Skip to content

Commit db3eb2d

Browse files
committed
feat: Changes from review comments, updated filter count to a badge design, applied refactor suggestions, split select-deselect test cases and added reset test h2oai#1689
1 parent d39fe8f commit db3eb2d

File tree

2 files changed

+77
-40
lines changed

2 files changed

+77
-40
lines changed

ui/src/table.test.tsx

+47-3
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,21 @@ describe('Table.tsx', () => {
10421042
expect(emitMock).toHaveBeenCalledTimes(1)
10431043
})
10441044

1045-
it('Filter counts - manual select, deselect', () => {
1045+
it('Filter counts - manual select', () => {
1046+
const { container, getAllByRole, getByLabelText, queryByTestId } = render(<XTable model={tableProps} />)
1047+
1048+
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
1049+
fireEvent.click(container.querySelector(filterSelectorName)!)
1050+
//select 2 options
1051+
fireEvent.click(getByLabelText('1'))
1052+
expect(getAllByRole('row')).toHaveLength(1 + headerRow)
1053+
expect(queryByTestId('filter-count')).toHaveTextContent('1')
1054+
fireEvent.click(getByLabelText('2'))
1055+
expect(getAllByRole('row')).toHaveLength(2 + headerRow)
1056+
expect(queryByTestId('filter-count')).toHaveTextContent('2')
1057+
})
1058+
1059+
it('Filter counts - manual deselect', () => {
10461060
const { container, getAllByRole, getByLabelText, queryByTestId } = render(<XTable model={tableProps} />)
10471061

10481062
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
@@ -1064,7 +1078,18 @@ describe('Table.tsx', () => {
10641078
expect(queryByTestId('filter-count')).toBeNull
10651079
})
10661080

1067-
it('Filter counts - select all, deselect all', () => {
1081+
it('Filter counts - select all', () => {
1082+
const { container, getAllByRole, queryByTestId, getByText } = render(<XTable model={tableProps} />)
1083+
1084+
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
1085+
fireEvent.click(container.querySelector(filterSelectorName)!)
1086+
1087+
fireEvent.click(getByText('Select All'))
1088+
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
1089+
expect(queryByTestId('filter-count')).toHaveTextContent(tableProps.rows!.length.toString())
1090+
})
1091+
1092+
it('Filter counts - deselect all', () => {
10681093
const { container, getAllByRole, queryByTestId, getByText } = render(<XTable model={tableProps} />)
10691094

10701095
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
@@ -1077,7 +1102,7 @@ describe('Table.tsx', () => {
10771102
fireEvent.click(getByText('Deselect All'))
10781103
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
10791104
expect(queryByTestId('filter-count')).toBeNull
1080-
})
1105+
})
10811106

10821107
it('Filter counts - more than 9 selections', () => {
10831108

@@ -1110,6 +1135,25 @@ describe('Table.tsx', () => {
11101135
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
11111136
expect(queryByTestId('filter-count')).toBeNull
11121137
})
1138+
1139+
it('Filter counts - clear selection with reset', () => {
1140+
const { container, getAllByRole, getByLabelText, queryByTestId, getByText } = render(<XTable model={{ ...tableProps, resettable: true }} />)
1141+
1142+
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
1143+
fireEvent.click(container.querySelector(filterSelectorName)!)
1144+
//select 2 options
1145+
fireEvent.click(getByLabelText('1'))
1146+
expect(getAllByRole('row')).toHaveLength(1 + headerRow)
1147+
expect(queryByTestId('filter-count')).toHaveTextContent('1')
1148+
fireEvent.click(getByLabelText('2'))
1149+
expect(getAllByRole('row')).toHaveLength(2 + headerRow)
1150+
expect(queryByTestId('filter-count')).toHaveTextContent('2')
1151+
1152+
//hit reset to clear the 2 options
1153+
fireEvent.click(getByText('Reset table'))
1154+
expect(getAllByRole('row')).toHaveLength(tableProps.rows!.length + headerRow)
1155+
expect(queryByTestId('filter-count')).toBeNull
1156+
})
11131157
})
11141158

11151159

ui/src/table.tsx

+30-37
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,13 @@ const
223223
verticalAlign: 'middle',
224224
},
225225
filterCount: {
226-
position: 'relative',
227-
top: -5,
228-
padding: '0 2px',
229-
color: cssVar('$red'),
230-
border: '0.5px solid',
231-
borderColor: cssVar('$red'),
232-
marginLeft: 5,
233-
lineHeight: 'normal',
226+
position: 'relative',
227+
top: -5,
228+
padding: 5,
229+
marginLeft: 5,
230+
lineHeight: 'normal',
231+
borderRadius: 8,
232+
backgroundColor: cssVar('$neutralQuaternary'),
234233
}
235234
}),
236235
styles: Partial<Fluent.IDetailsListStyles> = {
@@ -391,39 +390,37 @@ const
391390
minWidth,
392391
maxWidth,
393392
onRenderHeader: (props?: Fluent.IDetailsColumnProps) => {
394-
if (props) {
395-
let sortIcon = undefined
396-
if (c.sortable) {
397-
const sortIconName = sortCols && sortCols[props.column.key] ? 'Sort'+sortCols[props.column.key] : 'Sort'
398-
sortIcon = <Fluent.Icon iconName={sortIconName}
399-
className={css.sortingIcon}
400-
style={{ visibility: `${sortIconName === 'Sort' ? 'hidden' : 'visible'}`}}
401-
/>
402-
}
403-
let filterCountField = undefined
404-
const filterCount = selectedFilters?.[props.column.key]?.length || 0
405-
if (filterCount > 0){
406-
filterCountField =
407-
<span data-test='filter-count' className={css.filterCount}>
408-
{`${filterCount > 9 ? '9+' : filterCount}`}
409-
</span>
410-
}
411-
return <div style={{ display: 'flex', alignItems: 'center'}}>{props.column.name}
412-
{sortIcon ? sortIcon : null}
393+
if (!props) return null
394+
395+
const filterCount = selectedFilters?.[props.column.key]?.length || 0
396+
const sortIconName = sortCols && sortCols[props.column.key] ? 'Sort'+sortCols[props.column.key] : 'Sort'
413397

414-
{c.filterable ? (
398+
return (
399+
<div style={{ display: 'flex', alignItems: 'center'}}>{props.column.name}
400+
{c.sortable && (
401+
<Fluent.Icon iconName={sortIconName}
402+
className={css.sortingIcon}
403+
style={{ visibility: `${sortIconName === 'Sort' ? 'hidden' : 'visible'}`}}
404+
/>
405+
)}
406+
407+
{c.filterable && (
415408
<Fluent.Icon iconName='ChevronDown'
416409
onClick={(ev: React.MouseEvent<HTMLElement>) => {
417410
ev.stopPropagation()
418411
onColumnContextMenu(props.column, ev)
419412
}}
420413
className={css.filterIcon}
421414
/>
422-
) : null
423-
}
424-
{filterCountField ? filterCountField : null}
425-
</div>
426-
} else return null
415+
)}
416+
417+
{filterCount > 0 && (
418+
<span data-test='filter-count' className={css.filterCount}>
419+
{`${filterCount > 9 ? '9+' : filterCount}`}
420+
</span>
421+
)}
422+
</div>
423+
)
427424
},
428425
onColumnClick,
429426
columnActionsMode: Fluent.ColumnActionsMode.clickable,
@@ -577,10 +574,6 @@ const
577574
}, [m.columns, tableToWaveColumn])
578575
React.useImperativeHandle(ref, () => ({
579576
resetSortIcons: () => {
580-
setColumns(columns => columns.map(col => {
581-
if (col.iconName) col.iconName = undefined
582-
return col
583-
}))
584577
setSortCols(null)
585578
}
586579
}))

0 commit comments

Comments
 (0)