-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolves Issue #1689: Adding filter count to column headers #1760
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ import { border, cssVar, important, margin, rem } from './theme' | |
import useUpdateOnlyEffect from './parts/useUpdateOnlyEffectHook' | ||
import { wave } from './ui' | ||
|
||
/** Create a mapping between the column names and the number of filters selected for that count. */ | ||
const columnFilterCount: { [key: string]: number; } = {} | ||
|
||
/** Configure table pagination. Use as `pagination` parameter to `ui.table()` */ | ||
interface TablePagination { | ||
/** Total count of all the rows in your dataset. */ | ||
|
@@ -376,11 +379,26 @@ const | |
filters: c.filterable && m.pagination ? c.filters : undefined, | ||
} | ||
})), | ||
updateColumns = (filterKey: S, filterVal: S, checked?: B) => { | ||
onFilterChange(filterKey, filterVal, checked) | ||
setColumns(columns.map(c => { | ||
if (columnFilterCount[c.key] || columnFilterCount[c.key] == 0) { | ||
let filterCount = "" | ||
filterCount = columnFilterCount[c.key] | ||
? columnFilterCount[c.key] > 9 | ||
? " (9+) " | ||
: " (" + columnFilterCount[c.key] + ") " | ||
: "" | ||
c.name = c.name.substring(0, c.key.length) + filterCount | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding the filter count to the col name, we would like to have it as a separate square in the top right corner relative to the filter chevron so that it's clear that the number belongs to the filters. |
||
} | ||
return c | ||
})) | ||
}, | ||
primaryColumnKey = m.columns.find(c => c.link)?.name || (m.columns[0].link === false ? undefined : m.columns[0].name), | ||
onRenderMenuList = React.useCallback((col: WaveColumn) => (listProps?: Fluent.IContextualMenuListProps) => { | ||
return listProps ? | ||
<ContextualMenu | ||
onFilterChange={onFilterChange} | ||
onFilterChange={updateColumns} | ||
col={col} | ||
listProps={listProps} | ||
selectedFiltersRef={selectedFiltersRef} | ||
|
@@ -853,6 +871,7 @@ export const | |
return groups | ||
}) | ||
} | ||
columnFilterCount[filterKey] = filters[filterKey].length | ||
return filters | ||
}) | ||
}, [filter, initGroups, m.events, m.name, m.pagination, search]), | ||
|
@@ -953,7 +972,7 @@ export const | |
} | ||
}, [initGroups, m.groups]) | ||
|
||
const dataTableProps: DataTable = React.useMemo(() => ({ | ||
const dataTableProps: DataTable = { | ||
model: m, | ||
onFilterChange, | ||
items, | ||
|
@@ -965,7 +984,7 @@ export const | |
sort, | ||
isMultiple, | ||
setFiltersInBulk | ||
}), [filteredItems, groups, expandedRefs, isMultiple, items, m, onFilterChange, selectedFilters, selection, sort, setFiltersInBulk]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this removed? |
||
} | ||
|
||
return ( | ||
<div data-test={m.name} style={{ position: 'relative', height: computeHeight() }}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work correctly if there are multiple tables with same filter names on a page. Let's use the existing filters if possible instead.