Skip to content

Commit

Permalink
fix: Do not merge groups when grouping by multiple times in a row #2103
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok authored and mturoci committed Sep 19, 2023
1 parent a5e56d4 commit 0b55319
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ui/src/table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,30 @@ describe('Table.tsx', () => {
expect(emitMock).toHaveBeenCalledTimes(1)
})

it('Checks if groups are correct when grouping by multiple times', () => {
const
{ container, getAllByText, getByTestId, getAllByRole } = render(<XTable model={tableProps} />),
groupBy = (col: string) => {
fireEvent.click(getByTestId('groupby'))
fireEvent.click(getAllByText(col)[1]!)
fireEvent.click(container.querySelector('.ms-DetailsHeader-collapseButton')!)
}

groupBy('Col1')

expect(getAllByRole('row')).toHaveLength(headerRow + 2 * tableProps.rows!.length)
const groupHeaders = container.querySelectorAll('.ms-GroupHeader-title')
expect(groupHeaders[0]).toHaveTextContent(`${cell21}(1)`)
expect(groupHeaders[1]).toHaveTextContent(`${cell11}(1)`)
expect(groupHeaders[2]).toHaveTextContent(`${cell31}(1)`)

groupBy('Col2')

expect(getAllByRole('row')).toHaveLength(headerRow + groupHeaderRowsCount + tableProps.rows!.length)
expect(container.querySelectorAll('.ms-GroupHeader-title')[0]).toHaveTextContent(`${'Group1'}(2)`)
expect(container.querySelectorAll('.ms-GroupHeader-title')[1]).toHaveTextContent(`${'Group2'}(1)`)
})

it('Renders alphabetically sorted group by list - strings', () => {
const { container, getAllByText, getByTestId } = render(<XTable model={tableProps} />)

Expand Down
2 changes: 2 additions & 0 deletions ui/src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ export const
if (!m.pagination) reset()
}, [items])

useUpdateOnlyEffect(() => { initGroups() }, [groupNames, initGroups])

React.useEffect(() => {
if (m.groups) {
expandedRefs.current = m.groups?.reduce((acc, { label, collapsed = true }) => {
Expand Down

0 comments on commit 0b55319

Please sign in to comment.