Skip to content

Commit 3ea2bcf

Browse files
committed
feat: Add filter count next to filterable header h2oai#1689
1 parent b77c10e commit 3ea2bcf

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

ui/src/table.tsx

+32-25
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,15 @@ const
398398
? +c.max_width.substring(0, c.max_width.length - 2)
399399
: +c.max_width
400400
: undefined
401+
let label = c.label
402+
if (c.filterable) {
403+
const dataKey = c.name // Assuming the column name represents the data key
404+
const appliedFilters = selectedFilters?.[dataKey]?.length || 0
405+
label += appliedFilters > 0 ? ` (${appliedFilters} filters)` : ''
406+
}
401407
return {
402408
key: c.name,
403-
name: c.label,
409+
name: label,
404410
fieldName: c.name,
405411
minWidth,
406412
maxWidth,
@@ -418,37 +424,38 @@ const
418424
isMultiline: c.cell_overflow === 'wrap',
419425
filters: c.filterable ? c.filters : undefined,
420426
}
421-
}, [onColumnClick]),
427+
}, [onColumnClick, selectedFilters]),
422428
[columns, setColumns] = React.useState(m.columns.map(tableToWaveColumn)),
423429
primaryColumnKey = m.columns.find(c => c.link)?.name || (m.columns[0].link === false ? undefined : m.columns[0].name),
424430
onRenderDetailsHeader = React.useCallback((props?: Fluent.IDetailsHeaderProps) => {
425431
if (!props) return <span />
426-
427432
return (
428433
<Fluent.Sticky stickyPosition={Fluent.StickyPositionType.Header} isScrollSynced>
429-
<Fluent.DetailsHeader
430-
{...props}
431-
isAllCollapsed={groups?.every(group => group.isCollapsed)}
432-
styles={{
433-
...props.styles,
434-
root: {
435-
padding: 0,
436-
height: 48,
437-
lineHeight: '48px',
438-
background: cssVar('$neutralLight'),
439-
borderBottom: 'none',
440-
},
441-
cellSizerEnd: {
442-
marginLeft: -8,
443-
},
444-
cellIsGroupExpander: {
445-
// HACK: fixed size of expand/collapse button in column header
446-
height: 48
447-
}
448-
}}
449-
/>
434+
<div style={{ display: 'flex', alignItems: 'center' }}>
435+
<Fluent.DetailsHeader
436+
{...props}
437+
isAllCollapsed={groups?.every(group => group.isCollapsed)}
438+
styles={{
439+
...props.styles,
440+
root: {
441+
padding: 0,
442+
height: 48,
443+
lineHeight: '48px',
444+
background: cssVar('$neutralLight'),
445+
borderBottom: 'none',
446+
},
447+
cellSizerEnd: {
448+
marginLeft: -8,
449+
},
450+
cellIsGroupExpander: {
451+
// HACK: fixed size of expand/collapse button in column header
452+
height: 48,
453+
},
454+
}}
455+
/>
456+
</div>
450457
</Fluent.Sticky>
451-
)
458+
)
452459
}, [groups]),
453460
onRenderGroupHeader = React.useCallback((props?: Fluent.IDetailsGroupDividerProps) => {
454461
if (!props) return <span />

0 commit comments

Comments
 (0)