Skip to content

Commit

Permalink
[DataGridPremium] Fix expanded groups being collapsed after calling `…
Browse files Browse the repository at this point in the history
…updateRows` (#8823)
  • Loading branch information
cherniavskii authored May 4, 2023
1 parent fc4392c commit 92641bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2634,4 +2634,24 @@ describe('<DataGridPremium /> - Row Grouping', () => {

await waitFor(() => expect(getCell(1, 3).textContent).to.equal('username 2'));
});

// See https://github.com/mui/mui-x/issues/8580
it('should not collapse expanded groups after `updateRows`', async () => {
render(
<Test
columns={[{ field: 'id' }, { field: 'group' }, { field: 'username', width: 150 }]}
rows={[{ id: 1, group: 'A', username: 'username' }]}
rowGroupingModel={['group']}
/>,
);

fireEvent.click(screen.getByRole('button', { name: 'see children' }));

act(() => apiRef.current.updateRows([{ id: 1, group: 'A', username: 'username 2' }]));

await waitFor(() => {
expect(screen.getByRole('button', { name: 'hide children' })).toBeVisible();
});
await waitFor(() => expect(getCell(1, 3).textContent).to.equal('username 2'));
});
});
4 changes: 3 additions & 1 deletion packages/grid/x-data-grid-pro/src/utils/tree/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ export const getNodePathInTree = ({

while (node.id !== GRID_ROOT_GROUP_ID) {
path.push({
field: (node as GridGroupNode).groupingField,
field: node.type === 'leaf' ? null : node.groupingField,
key: node.groupingKey,
});

node = tree[node.parent!] as GridGroupNode | GridLeafNode;
}

path.reverse();

return path;
};

Expand Down

0 comments on commit 92641bd

Please sign in to comment.