-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[DataGridPro] Fix duplicate nested rows for dynamically updated row IDs #18526
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
ad3a7eb
382bbc7
770ddb8
fab847a
5e7502b
1063c36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,7 +200,7 @@ export const useGridRows = ( | |
return; | ||
} | ||
|
||
const nonPinnedRowsUpdates = computeRowsUpdates(apiRef, updates, props.getRowId); | ||
const { nonPinnedRowsUpdates } = computeRowsUpdates(apiRef, updates, props.getRowId); | ||
|
||
const cache = updateCacheWithNewRows({ | ||
updates: nonPinnedRowsUpdates, | ||
|
@@ -215,10 +215,55 @@ export const useGridRows = ( | |
|
||
const updateNestedRows = React.useCallback<GridRowProPrivateApi['updateNestedRows']>( | ||
(updates, groupKeys) => { | ||
const nonPinnedRowsUpdates = computeRowsUpdates(apiRef, updates, props.getRowId); | ||
const { nonPinnedRowsUpdates, insertedNodes } = computeRowsUpdates( | ||
apiRef, | ||
updates, | ||
props.getRowId, | ||
); | ||
|
||
const tree = gridRowTreeSelector(apiRef); | ||
const removedNodes = new Set<GridRowId>(); | ||
|
||
if (groupKeys && groupKeys.length > 0) { | ||
const rootNode = tree[GRID_ROOT_GROUP_ID]; | ||
let parentNode = rootNode; | ||
for (let i = 0; i < groupKeys.length; i += 1) { | ||
const childrenFromPath = (parentNode as GridGroupNode).childrenFromPath; | ||
const nodeId = childrenFromPath[Object.keys(childrenFromPath)[0]]?.[groupKeys[i]]; | ||
if (nodeId) { | ||
parentNode = tree[nodeId]; | ||
} | ||
} | ||
|
||
const traverse = (node: GridGroupNode) => { | ||
Comment on lines
+229
to
+240
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this whole traverse necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is to check if the children of the row being fetched are outdated and need to be removed before adding new ones. Regarding the part where parent group's ID is derived from |
||
if (!node) { | ||
return; | ||
} | ||
for (const childId of node.children) { | ||
if (!insertedNodes.has(childId)) { | ||
removedNodes.add(childId); | ||
if (tree[childId].type === 'group') { | ||
traverse(tree[childId] as GridGroupNode); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
if (parentNode !== rootNode) { | ||
traverse(parentNode as GridGroupNode); | ||
} | ||
} | ||
|
||
const cacheUpdates = [ | ||
...nonPinnedRowsUpdates, | ||
...Array.from(removedNodes).map((rowId) => ({ | ||
id: rowId, | ||
_action: 'delete' as const, | ||
})), | ||
]; | ||
MBilalShafi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const cache = updateCacheWithNewRows({ | ||
updates: nonPinnedRowsUpdates, | ||
updates: cacheUpdates, | ||
getRowId: props.getRowId, | ||
previousCache: apiRef.current.caches.rows, | ||
groupKeys: groupKeys ?? [], | ||
|
Uh oh!
There was an error while loading. Please reload this page.