Created
December 5, 2018 09:01
-
-
Save milooy/53ee9f265ff537efea78ecfaf4272ac7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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