refactor: flow typing (#1012)

* fix: padding

* fix: Minor button alignment issues

* feat: Add icon to invite people button

* WIP
This commit is contained in:
Tom Moor
2019-08-08 23:09:09 -07:00
committed by GitHub
parent 7b2eea0009
commit d024d31f66
64 changed files with 207 additions and 144 deletions

View File

@ -1,11 +1,36 @@
// @flow
import { sortBy } from 'lodash';
import { deburr } from 'lodash';
import naturalSort from 'natural-sort';
export default (sortableArray: *, key: string): * => {
if (!sortableArray) return [];
let keys = sortableArray.map(object => object[key]);
keys.sort(naturalSort());
return sortBy(sortableArray, object => keys.indexOf(object[key]));
type NaturalSortOptions = {
caseSensitive?: boolean,
direction?: 'asc' | 'desc',
};
const sorter = naturalSort();
function getSortByField<T: Object>(
item: T,
keyOrCallback: string | (T => string)
) {
if (typeof keyOrCallback === 'string') {
return deburr(item[keyOrCallback]);
}
return keyOrCallback(item);
}
function naturalSortBy<T>(
items: T[],
key: string | (T => string),
sortOptions?: NaturalSortOptions
): T[] {
if (!items) return [];
const sort = sortOptions ? naturalSort(sortOptions) : sorter;
return items.sort((a: any, b: any): -1 | 0 | 1 =>
sort(getSortByField(a, key), getSortByField(b, key))
);
}
export default naturalSortBy;