-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: sort via selectors * wip: selector sort * feat: store sort order locally * chore: remove empty test * fix: type error * fix(clockface): have resource body return empty state when children are false * chore: add type for list
- Loading branch information
Showing
7 changed files
with
150 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {createSelector} from 'reselect' | ||
import {orderBy, get} from 'lodash' | ||
|
||
const resourceList = state => state | ||
|
||
export const sortSelector = (_, props) => ({ | ||
key: props.sortKey, | ||
direction: props.sortDirection, | ||
type: props.sortType, | ||
}) | ||
|
||
function orderByType(data, type) { | ||
switch (type) { | ||
case 'date': | ||
return Date.parse(data) | ||
case 'float': | ||
return parseFloat(data) | ||
default: | ||
return data | ||
} | ||
} | ||
|
||
export const getSortedResource = createSelector( | ||
resourceList, | ||
sortSelector, | ||
(resourceList, sort) => { | ||
if (sort.key && sort.direction) { | ||
return orderBy<{id: string}>( | ||
resourceList, | ||
r => orderByType(get(r, sort.key), sort.type), | ||
[sort.direction] | ||
).map(r => r.id) | ||
} | ||
|
||
return resourceList | ||
} | ||
) |