-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGridPremium] Fix expanded groups being collapsed after calling updateRows
#8823
[DataGridPremium] Fix expanded groups being collapsed after calling updateRows
#8823
Conversation
Netlify deploy previewNetlify deploy preview: https://deploy-preview-8823--material-ui-x.netlify.app/ Updated pagesNo updates. These are the results for the performance tests:
|
@@ -34,8 +34,8 @@ export const getNodePathInTree = ({ | |||
let node = tree[id] as GridGroupNode | GridLeafNode; | |||
|
|||
while (node.id !== GRID_ROOT_GROUP_ID) { | |||
path.push({ | |||
field: (node as GridGroupNode).groupingField, | |||
path.unshift({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I'm going to keep .push
and just reverse the array later, because it looks like unshift
is ~70% slower even for short arrays: https://jsperf.app/wisoqe
It also fixes #8853 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it is a nice stability improvement. 🙏
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional Nice to have (possibly in a follow-up): It'd be nice to have a small test case covering #8853 too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I'll add a regression test in a follow-up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in #8870
Fixes #8580
Before: https://codesandbox.io/s/kind-lamarr-ofjvim
After: https://codesandbox.io/s/wild-http-h2gfjq
Fixes #8853
Before: https://codesandbox.io/s/cocky-sunset-f7qkjg
After: https://codesandbox.io/s/frosty-bassi-1hwexf
The issue comes down to this part where we update the row tree:
mui-x/packages/grid/x-data-grid-pro/src/utils/tree/updateRowTree.ts
Lines 61 to 63 in 1099111
Here we compare
path
andpathInPreviousTree
. ButisInSameGroup
always equalsfalse
, even if the groups have not been changed. Here are example values that are being compared:There are two differences between
pathInPreviousTree
andpath
:path
, thenull
value is used when the field is missing, but inpathInPreviousTree
,undefined
is used instead.This issue comes from a bug in
getNodePathInTree
mui-x/packages/grid/x-data-grid-pro/src/utils/tree/utils.ts
Line 38 in 4d4fcb4
Leaf nodes do not have
groupingField
property, thereforefield
should be set tonull
here. TS didn't warn about this because of theas GridGroupNode
assertion.deepEqual
returnsfalse
.The order comes from
getNodePathInTree
as well, whereArray.push
is being used:mui-x/packages/grid/x-data-grid-pro/src/utils/tree/utils.ts
Line 37 in 4d4fcb4
The fix is to use
Array.unshift
to reverse the order of items.TODO: