Skip to content

Instantly share code, notes, and snippets.

@milooy
Created December 5, 2018 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milooy/53ee9f265ff537efea78ecfaf4272ac7 to your computer and use it in GitHub Desktop.
Save milooy/53ee9f265ff537efea78ecfaf4272ac7 to your computer and use it in GitHub Desktop.
export const filterBy = (dataSource, props) => {
// TODO: Yurim - refactor with flow
const {
sortIndex, sortDirection, query, filterFunction, searchKeyList, additionalSortFunction,
} = props;
const filteredList = dataSource;
const direction = sortDirection ? "asc" : "desc";
const curryiedIdentity = curry(identity);
const sortByColumn = sortIndex ? orderBy([listItem => flow(get(sortIndex), toLower)(listItem)], [direction], filteredList) : curryiedIdentity;
const filterByFunction = filterFunction ? filter(filterFunction, filteredList) : curryiedIdentity;
const filterByQuery = query ? filter(
notebook => some(key => keyIsInQueryString(key, query)(notebook), searchKeyList),
filteredList,
) : curryiedIdentity;
const sortByAdditionalFunction = additionalSortFunction ? additionalSortFunction(filteredList) : curryiedIdentity;
return flow(
sortByColumn,
filterByFunction,
filterByQuery,
sortByAdditionalFunction
)(filteredList);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment