Relocate columns and row logic, fix columns and useGroupBy to be more pure

Since useColumns was relying on groupBy logic, this was code smell. I wanted useGroupBy to be able to add that logic all by itself and not have to have dependencies in the core of the table.

To fix that, I've moved the core column and row logic to the useTable hook and added a new hook 'columnsBeforeHeaderGroups' to allow useGroupBy to do what i needs in a more pure way.
This commit is contained in:
tannerlinsley
2019-07-29 11:00:07 -06:00
parent cadd8bf62a
commit dc73347003
9 changed files with 587 additions and 451 deletions
+6 -10
View File
@@ -14,14 +14,11 @@ const propTypes = {
// General
columns: PropTypes.arrayOf(
PropTypes.shape({
filterFn: PropTypes.func,
filterAll: PropTypes.bool,
canFilter: PropTypes.bool,
disableFilters: PropTypes.bool,
Filter: PropTypes.any,
})
),
filterFn: PropTypes.func,
manualFilters: PropTypes.bool,
}
@@ -99,12 +96,12 @@ export const useFilters = props => {
hooks.columns.push(columns => {
columns.forEach(column => {
const { id, accessor, canFilter } = column
const { id, accessor, disableFilters: columnDisableFilters } = column
// Determine if a column is filterable
column.canFilter = accessor
? getFirstDefined(
canFilter,
columnDisableFilters,
disableFilters === true ? false : undefined,
true
)
@@ -143,13 +140,12 @@ export const useFilters = props => {
// Find the filters column
const column = columns.find(d => d.id === columnID)
column.preFilteredRows = filteredSoFar
// Don't filter hidden columns or columns that have had their filters disabled
if (!column || column.filterable === false) {
if (!column) {
return filteredSoFar
}
column.preFilteredRows = filteredSoFar
const filterMethod = getFilterMethod(
column.filter,
userFilterTypes || {},