-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable sorting question list via Companies (#21)
The `Difficulty` filter is now hard-coded, as to avoid running into edge cases using preFilteredRows/filteredRows (see https://github.com/tannerlinsley/react-table/blob/master/docs/api/useFilters.md#column-properties). All filters have been refactored out to a seperate file (filters.js), to reduce code clutter in the Table component. The question list is now sorted by difficulty by default when being exported from src/data/index.js. Fixes #13
- Loading branch information
Sean
committed
Jun 5, 2020
1 parent
c39d65c
commit 5423f06
Showing
4 changed files
with
93 additions
and
72 deletions.
There are no files selected for viewing
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,63 @@ | ||
import React from 'react'; | ||
|
||
function CreateDropDownListHelper(options, filterValue, setFilter) { | ||
return ( | ||
<select | ||
value={filterValue} | ||
onChange={e => { | ||
setFilter(e.target.value || ''); | ||
}} | ||
> | ||
<option value="">All</option> | ||
{options.map((option, idx) => ( | ||
<option key={idx} value={option}> | ||
{option} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
} | ||
|
||
export function DefaultColumnFilter({ | ||
column: { filterValue, preFilteredRows, setFilter, id }, | ||
}) { | ||
const count = preFilteredRows.length; | ||
|
||
return ( | ||
<input | ||
value={filterValue || ''} | ||
onChange={e => { | ||
setFilter(e.target.value || ''); | ||
}} | ||
placeholder={`Search ${count} questions`} | ||
/> | ||
); | ||
} | ||
|
||
export function SelectDifficultyColumnFilter({ | ||
column: { filterValue, setFilter }, | ||
}) { | ||
const options = ['Easy', 'Medium', 'Hard']; | ||
|
||
return CreateDropDownListHelper(options, filterValue, setFilter); | ||
} | ||
|
||
export function SelectColumnFilter({ | ||
column: { filterValue, setFilter, preFilteredRows, id }, | ||
}) { | ||
const options = React.useMemo(() => { | ||
const set = new Set(); | ||
|
||
preFilteredRows.forEach(row => { | ||
const values = String(row.values[id]).split(','); | ||
|
||
values.forEach(value => { | ||
set.add(value); | ||
}); | ||
}); | ||
|
||
return [...set.values()].sort(); | ||
}, [id, preFilteredRows]); | ||
|
||
return CreateDropDownListHelper(options, filterValue, setFilter); | ||
} |
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