Skip to content

Commit ab3979d

Browse files
authored
chore: Prevent internal table groups regression. #2103 (#2150)
1 parent d5b73cd commit ab3979d

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

py/examples/table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def serve(q: Q):
6969
rows=[ui.table_row(
7070
name=issue.id,
7171
cells=[issue.text, issue.status, issue.icon, str(issue.views), str(issue.progress),
72-
issue.state, issue.created]
72+
issue.state, issue.created]
7373
) for issue in issues],
7474
groupable=True,
7575
downloadable=True,

ui/src/table.test.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,20 @@ describe('Table.tsx', () => {
10691069
expect(container.querySelectorAll('.ms-GroupedList-group')).toHaveLength(tableProps.rows!.length)
10701070
})
10711071

1072+
it('Renders grouped list after selection, removes grouping when "No Grouping" chosen', () => {
1073+
const { container, getAllByText, getByTestId, getByText } = render(<XTable model={tableProps} />)
1074+
1075+
fireEvent.click(getByTestId('groupby'))
1076+
fireEvent.click(getAllByText('Col1')[1]!)
1077+
1078+
expect(container.querySelectorAll('.ms-GroupedList-group')).toHaveLength(tableProps.rows!.length)
1079+
1080+
fireEvent.click(getByTestId('groupby'))
1081+
fireEvent.click(getByText('(No Grouping)')!)
1082+
1083+
expect(container.querySelectorAll('.ms-GroupedList-group')).toHaveLength(0)
1084+
})
1085+
10721086
it('Checks if grouped list is collapsed after selection', () => {
10731087
const { getAllByRole, getAllByText, getByTestId } = render(<XTable model={tableProps} />)
10741088

@@ -1648,6 +1662,18 @@ describe('Table.tsx', () => {
16481662
expect(getAllByRole('gridcell')[2].textContent).toBe('Jumps over a dog.')
16491663
expect(getAllByRole('gridcell')[4].textContent).toBe('Wooo hooo.')
16501664
})
1665+
1666+
it('Does not keep groups rendered after reset', () => {
1667+
const { container, getAllByText, getByTestId, getByText } = render(<XTable model={{ ...tableProps, groupable: true, resettable: true }} />)
1668+
1669+
fireEvent.click(getByTestId('groupby'))
1670+
fireEvent.click(getAllByText('Col1')[1]!)
1671+
1672+
expect(container.querySelectorAll('.ms-GroupedList-group')).toHaveLength(3)
1673+
fireEvent.click(getByText('Reset table'))
1674+
expect(container.querySelectorAll('.ms-GroupedList-group')).toHaveLength(0)
1675+
})
1676+
16511677
})
16521678

16531679
describe('Download', () => {

ui/src/table.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ export const
988988
if (!m.pagination) reset()
989989
}, [items])
990990

991-
useUpdateOnlyEffect(() => { initGroups() }, [groupNames, initGroups])
991+
useUpdateOnlyEffect(() => { if (groupNames.size) initGroups() }, [groupNames, initGroups])
992992

993993
React.useEffect(() => {
994994
if (m.groups) {

0 commit comments

Comments
 (0)