@mui/x-data-grid-pro 5.17.5 → 6.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +297 -19
- package/DataGridPro/DataGridPro.js +4 -14
- package/DataGridPro/useDataGridProProps.js +2 -2
- package/components/DataGridProVirtualScroller.js +2 -2
- package/components/GridDetailPanelToggleCell.js +1 -1
- package/components/GridRowReorderCell.js +4 -6
- package/components/GridTreeDataGroupingCell.d.ts +2 -2
- package/components/GridTreeDataGroupingCell.js +1 -1
- package/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
- package/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
- package/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
- package/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
- package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.d.ts +1 -1
- package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
- package/hooks/features/rowPinning/gridRowPinningInterface.d.ts +2 -2
- package/hooks/features/rowPinning/useGridRowPinningPreProcessors.d.ts +16 -16
- package/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
- package/hooks/features/rowReorder/useGridRowReorder.js +5 -5
- package/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
- package/hooks/features/treeData/gridTreeDataUtils.js +14 -12
- package/hooks/features/treeData/useGridTreeData.js +2 -6
- package/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
- package/index.js +1 -1
- package/internals/index.d.ts +4 -2
- package/internals/index.js +4 -2
- package/legacy/DataGridPro/DataGridPro.js +4 -14
- package/legacy/DataGridPro/useDataGridProProps.js +2 -2
- package/legacy/components/DataGridProVirtualScroller.js +2 -2
- package/legacy/components/GridDetailPanelToggleCell.js +1 -1
- package/legacy/components/GridRowReorderCell.js +4 -6
- package/legacy/components/GridTreeDataGroupingCell.js +1 -1
- package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
- package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
- package/legacy/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
- package/legacy/hooks/features/lazyLoader/useGridLazyLoader.js +25 -15
- package/legacy/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +21 -7
- package/legacy/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
- package/legacy/hooks/features/rowReorder/useGridRowReorder.js +5 -5
- package/legacy/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
- package/legacy/hooks/features/treeData/gridTreeDataUtils.js +14 -12
- package/legacy/hooks/features/treeData/useGridTreeData.js +2 -6
- package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +37 -22
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +4 -2
- package/legacy/utils/tree/createRowTree.js +36 -0
- package/legacy/utils/tree/index.js +1 -1
- package/legacy/utils/tree/insertDataRowInTree.js +127 -0
- package/legacy/utils/tree/models.js +1 -0
- package/legacy/utils/tree/removeDataRowFromTree.js +97 -0
- package/legacy/utils/tree/sortRowTree.js +49 -43
- package/legacy/utils/tree/updateRowTree.js +81 -0
- package/legacy/utils/tree/utils.js +184 -0
- package/models/dataGridProProps.d.ts +3 -3
- package/modern/DataGridPro/DataGridPro.js +4 -14
- package/modern/DataGridPro/useDataGridProProps.js +2 -2
- package/modern/components/DataGridProVirtualScroller.js +2 -2
- package/modern/components/GridDetailPanelToggleCell.js +1 -1
- package/modern/components/GridRowReorderCell.js +4 -4
- package/modern/components/GridTreeDataGroupingCell.js +1 -1
- package/modern/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
- package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
- package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
- package/modern/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
- package/modern/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
- package/modern/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +60 -23
- package/modern/hooks/features/rowReorder/useGridRowReorder.js +5 -3
- package/modern/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
- package/modern/hooks/features/treeData/gridTreeDataUtils.js +13 -9
- package/modern/hooks/features/treeData/useGridTreeData.js +2 -4
- package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
- package/modern/index.js +1 -1
- package/modern/internals/index.js +4 -2
- package/modern/utils/tree/createRowTree.js +35 -0
- package/modern/utils/tree/index.js +1 -1
- package/modern/utils/tree/insertDataRowInTree.js +127 -0
- package/modern/utils/tree/models.js +1 -0
- package/modern/utils/tree/removeDataRowFromTree.js +100 -0
- package/modern/utils/tree/sortRowTree.js +46 -40
- package/modern/utils/tree/updateRowTree.js +83 -0
- package/modern/utils/tree/utils.js +180 -0
- package/node/DataGridPro/DataGridPro.js +4 -14
- package/node/DataGridPro/useDataGridProProps.js +1 -1
- package/node/components/DataGridProVirtualScroller.js +1 -1
- package/node/components/GridDetailPanelToggleCell.js +1 -1
- package/node/components/GridRowReorderCell.js +3 -5
- package/node/components/GridTreeDataGroupingCell.js +1 -1
- package/node/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
- package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
- package/node/hooks/features/infiniteLoader/useGridInfiniteLoader.js +1 -1
- package/node/hooks/features/lazyLoader/useGridLazyLoader.js +19 -8
- package/node/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +18 -5
- package/node/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +63 -26
- package/node/hooks/features/rowReorder/useGridRowReorder.js +4 -4
- package/node/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
- package/node/hooks/features/treeData/gridTreeDataUtils.js +14 -12
- package/node/hooks/features/treeData/useGridTreeData.js +1 -5
- package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -17
- package/node/index.js +1 -1
- package/node/internals/index.js +35 -10
- package/node/utils/tree/createRowTree.js +46 -0
- package/node/utils/tree/index.js +2 -2
- package/node/utils/tree/insertDataRowInTree.js +139 -0
- package/node/utils/tree/models.js +5 -0
- package/node/utils/tree/removeDataRowFromTree.js +110 -0
- package/node/utils/tree/sortRowTree.js +50 -43
- package/node/utils/tree/updateRowTree.js +98 -0
- package/node/utils/tree/utils.js +217 -0
- package/package.json +5 -5
- package/utils/tree/createRowTree.d.ts +15 -0
- package/utils/tree/createRowTree.js +35 -0
- package/utils/tree/index.d.ts +1 -1
- package/utils/tree/index.js +1 -1
- package/utils/tree/insertDataRowInTree.d.ts +51 -0
- package/utils/tree/insertDataRowInTree.js +129 -0
- package/utils/tree/models.d.ts +13 -0
- package/utils/tree/models.js +1 -0
- package/utils/tree/removeDataRowFromTree.d.ts +40 -0
- package/utils/tree/removeDataRowFromTree.js +100 -0
- package/utils/tree/sortRowTree.d.ts +6 -1
- package/utils/tree/sortRowTree.js +46 -40
- package/utils/tree/updateRowTree.d.ts +19 -0
- package/utils/tree/updateRowTree.js +83 -0
- package/utils/tree/utils.d.ts +66 -0
- package/utils/tree/utils.js +186 -0
- package/legacy/utils/tree/buildRowTree.js +0 -195
- package/modern/utils/tree/buildRowTree.js +0 -174
- package/node/utils/tree/buildRowTree.js +0 -195
- package/utils/tree/buildRowTree.d.ts +0 -48
- package/utils/tree/buildRowTree.js +0 -186
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
|
|
2
|
+
import { addGroupDefaultExpansion, getGroupRowIdFromPath, insertNodeInTree, updateGroupNodeIdAndAutoGenerated } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Inserts a data row in a tree.
|
|
6
|
+
* For each steps of its path:
|
|
7
|
+
* - if a node exists with the same partial path, it will register this node as the ancestor of the data row.
|
|
8
|
+
* - if not, it will create an auto-generated node and register it as ancestor of the data row.
|
|
9
|
+
*/
|
|
10
|
+
export var insertDataRowInTree = function insertDataRowInTree(_ref) {
|
|
11
|
+
var id = _ref.id,
|
|
12
|
+
path = _ref.path,
|
|
13
|
+
updatedGroupsManager = _ref.updatedGroupsManager,
|
|
14
|
+
tree = _ref.tree,
|
|
15
|
+
treeDepths = _ref.treeDepths,
|
|
16
|
+
onDuplicatePath = _ref.onDuplicatePath,
|
|
17
|
+
isGroupExpandedByDefault = _ref.isGroupExpandedByDefault,
|
|
18
|
+
defaultGroupingExpansionDepth = _ref.defaultGroupingExpansionDepth;
|
|
19
|
+
var parentNodeId = GRID_ROOT_GROUP_ID;
|
|
20
|
+
|
|
21
|
+
for (var depth = 0; depth < path.length; depth += 1) {
|
|
22
|
+
var _childrenFromPath, _childrenFromPath$fie;
|
|
23
|
+
|
|
24
|
+
var _path$depth = path[depth],
|
|
25
|
+
key = _path$depth.key,
|
|
26
|
+
field = _path$depth.field;
|
|
27
|
+
var fieldWithDefaultValue = field != null ? field : '__no_field__';
|
|
28
|
+
var keyWithDefaultValue = key != null ? key : '__no_key__';
|
|
29
|
+
var existingNodeIdWithPartialPath = (_childrenFromPath = tree[parentNodeId].childrenFromPath) == null ? void 0 : (_childrenFromPath$fie = _childrenFromPath[fieldWithDefaultValue]) == null ? void 0 : _childrenFromPath$fie[keyWithDefaultValue.toString()]; // When we reach the last step of the path,
|
|
30
|
+
// We need to create a node for the row passed to `insertNodeInTree`
|
|
31
|
+
|
|
32
|
+
if (depth === path.length - 1) {
|
|
33
|
+
// If no node matches the full path,
|
|
34
|
+
// We create a leaf node for the data row.
|
|
35
|
+
if (existingNodeIdWithPartialPath == null) {
|
|
36
|
+
var leafNode = {
|
|
37
|
+
type: 'leaf',
|
|
38
|
+
id: id,
|
|
39
|
+
depth: depth,
|
|
40
|
+
parent: parentNodeId,
|
|
41
|
+
groupingKey: key
|
|
42
|
+
};
|
|
43
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'insertChildren');
|
|
44
|
+
insertNodeInTree({
|
|
45
|
+
node: leafNode,
|
|
46
|
+
tree: tree,
|
|
47
|
+
treeDepths: treeDepths
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
var existingNodeWithPartialPath = tree[existingNodeIdWithPartialPath]; // If we already have an auto-generated group matching the partial path,
|
|
51
|
+
// We replace it with the node from of data row passed to `insertNodeInTree`
|
|
52
|
+
|
|
53
|
+
if (existingNodeWithPartialPath.type === 'group' && existingNodeWithPartialPath.isAutoGenerated) {
|
|
54
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'removeChildren');
|
|
55
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'insertChildren');
|
|
56
|
+
updateGroupNodeIdAndAutoGenerated({
|
|
57
|
+
tree: tree,
|
|
58
|
+
treeDepths: treeDepths,
|
|
59
|
+
node: existingNodeWithPartialPath,
|
|
60
|
+
updatedNode: {
|
|
61
|
+
id: id,
|
|
62
|
+
isAutoGenerated: false
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
// If we have another row matching the partial path, then there is a duplicate in the dataset.
|
|
67
|
+
// We warn the user and skip the current row.
|
|
68
|
+
onDuplicatePath == null ? void 0 : onDuplicatePath(existingNodeIdWithPartialPath, id, path);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} // For the intermediary steps of the path,
|
|
72
|
+
// We need to make sure that there is a node matching the partial path.
|
|
73
|
+
//
|
|
74
|
+
// If no node matches the partial path,
|
|
75
|
+
// We create an auto-generated group node.
|
|
76
|
+
else if (existingNodeIdWithPartialPath == null) {
|
|
77
|
+
var nodeId = getGroupRowIdFromPath(path.slice(0, depth + 1));
|
|
78
|
+
var autoGeneratedGroupNode = {
|
|
79
|
+
type: 'group',
|
|
80
|
+
id: nodeId,
|
|
81
|
+
parent: parentNodeId,
|
|
82
|
+
depth: depth,
|
|
83
|
+
isAutoGenerated: true,
|
|
84
|
+
groupingKey: key,
|
|
85
|
+
groupingField: field,
|
|
86
|
+
children: [],
|
|
87
|
+
childrenFromPath: {}
|
|
88
|
+
};
|
|
89
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'insertChildren');
|
|
90
|
+
insertNodeInTree({
|
|
91
|
+
node: addGroupDefaultExpansion({
|
|
92
|
+
node: autoGeneratedGroupNode,
|
|
93
|
+
defaultGroupingExpansionDepth: defaultGroupingExpansionDepth,
|
|
94
|
+
isGroupExpandedByDefault: isGroupExpandedByDefault
|
|
95
|
+
}),
|
|
96
|
+
tree: tree,
|
|
97
|
+
treeDepths: treeDepths
|
|
98
|
+
});
|
|
99
|
+
parentNodeId = nodeId;
|
|
100
|
+
} // For the intermediary steps of the path
|
|
101
|
+
// If a node matches the partial path, we use it as parent for the next step
|
|
102
|
+
else {
|
|
103
|
+
var currentGroupNode = tree[existingNodeIdWithPartialPath]; // If the node matching the partial path is not a group, we turn it into a group
|
|
104
|
+
|
|
105
|
+
if (currentGroupNode.type !== 'group') {
|
|
106
|
+
var groupNode = {
|
|
107
|
+
type: 'group',
|
|
108
|
+
id: currentGroupNode.id,
|
|
109
|
+
parent: currentGroupNode.parent,
|
|
110
|
+
depth: currentGroupNode.depth,
|
|
111
|
+
isAutoGenerated: false,
|
|
112
|
+
groupingKey: key,
|
|
113
|
+
groupingField: field,
|
|
114
|
+
children: [],
|
|
115
|
+
childrenFromPath: {}
|
|
116
|
+
};
|
|
117
|
+
tree[existingNodeIdWithPartialPath] = addGroupDefaultExpansion({
|
|
118
|
+
node: groupNode,
|
|
119
|
+
defaultGroupingExpansionDepth: defaultGroupingExpansionDepth,
|
|
120
|
+
isGroupExpandedByDefault: isGroupExpandedByDefault
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
parentNodeId = currentGroupNode.id;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
|
|
2
|
+
import { getNodePathInTree, getGroupRowIdFromPath, removeNodeFromTree, updateGroupNodeIdAndAutoGenerated } from './utils';
|
|
3
|
+
|
|
4
|
+
var removeNodeAndCleanParent = function removeNodeAndCleanParent(_ref) {
|
|
5
|
+
var node = _ref.node,
|
|
6
|
+
tree = _ref.tree,
|
|
7
|
+
treeDepths = _ref.treeDepths,
|
|
8
|
+
updatedGroupsManager = _ref.updatedGroupsManager;
|
|
9
|
+
removeNodeFromTree({
|
|
10
|
+
node: node,
|
|
11
|
+
tree: tree,
|
|
12
|
+
treeDepths: treeDepths
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (node.type === 'group' && node.footerId != null) {
|
|
16
|
+
removeNodeFromTree({
|
|
17
|
+
node: tree[node.footerId],
|
|
18
|
+
tree: tree,
|
|
19
|
+
treeDepths: treeDepths
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var parentNode = tree[node.parent];
|
|
24
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNode.id, 'removeChildren');
|
|
25
|
+
var shouldDeleteGroup = parentNode.id !== GRID_ROOT_GROUP_ID && parentNode.children.length === 0;
|
|
26
|
+
|
|
27
|
+
if (shouldDeleteGroup) {
|
|
28
|
+
if (parentNode.isAutoGenerated) {
|
|
29
|
+
removeNodeAndCleanParent({
|
|
30
|
+
node: node,
|
|
31
|
+
tree: tree,
|
|
32
|
+
treeDepths: treeDepths
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
tree[parentNode.id] = {
|
|
36
|
+
type: 'leaf',
|
|
37
|
+
id: parentNode.id,
|
|
38
|
+
depth: parentNode.depth,
|
|
39
|
+
parent: parentNode.parent,
|
|
40
|
+
groupingKey: parentNode.groupingKey
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var replaceDataGroupWithAutoGeneratedGroup = function replaceDataGroupWithAutoGeneratedGroup(_ref2) {
|
|
47
|
+
var node = _ref2.node,
|
|
48
|
+
tree = _ref2.tree,
|
|
49
|
+
treeDepths = _ref2.treeDepths,
|
|
50
|
+
updatedGroupsManager = _ref2.updatedGroupsManager;
|
|
51
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(node.parent, 'removeChildren');
|
|
52
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(node.parent, 'insertChildren');
|
|
53
|
+
updateGroupNodeIdAndAutoGenerated({
|
|
54
|
+
tree: tree,
|
|
55
|
+
treeDepths: treeDepths,
|
|
56
|
+
node: node,
|
|
57
|
+
updatedNode: {
|
|
58
|
+
id: getGroupRowIdFromPath(getNodePathInTree({
|
|
59
|
+
id: node.id,
|
|
60
|
+
tree: tree
|
|
61
|
+
})),
|
|
62
|
+
isAutoGenerated: true
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Removed a data row from the tree.
|
|
68
|
+
* If the node is a non-empty group, replace it with an auto-generated group to be able to keep displaying its children.
|
|
69
|
+
* If not, remove it and recursively clean its parent with the following rules:
|
|
70
|
+
* - An empty auto-generated should be removed from the tree
|
|
71
|
+
* - An empty non-auto-generated should be turned into a leaf
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export var removeDataRowFromTree = function removeDataRowFromTree(_ref3) {
|
|
76
|
+
var id = _ref3.id,
|
|
77
|
+
tree = _ref3.tree,
|
|
78
|
+
treeDepths = _ref3.treeDepths,
|
|
79
|
+
updatedGroupsManager = _ref3.updatedGroupsManager;
|
|
80
|
+
var node = tree[id];
|
|
81
|
+
|
|
82
|
+
if (node.type === 'group' && node.children.length > 0) {
|
|
83
|
+
replaceDataGroupWithAutoGeneratedGroup({
|
|
84
|
+
node: node,
|
|
85
|
+
tree: tree,
|
|
86
|
+
treeDepths: treeDepths,
|
|
87
|
+
updatedGroupsManager: updatedGroupsManager
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
removeNodeAndCleanParent({
|
|
91
|
+
node: node,
|
|
92
|
+
tree: tree,
|
|
93
|
+
treeDepths: treeDepths,
|
|
94
|
+
updatedGroupsManager: updatedGroupsManager
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
@@ -1,60 +1,66 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
|
|
2
3
|
export var sortRowTree = function sortRowTree(params) {
|
|
3
|
-
var
|
|
4
|
-
rowTree = params.rowTree,
|
|
4
|
+
var rowTree = params.rowTree,
|
|
5
5
|
disableChildrenSorting = params.disableChildrenSorting,
|
|
6
|
-
sortRowList = params.sortRowList
|
|
7
|
-
|
|
6
|
+
sortRowList = params.sortRowList,
|
|
7
|
+
shouldRenderGroupBelowLeaves = params.shouldRenderGroupBelowLeaves;
|
|
8
|
+
var sortedRows = [];
|
|
9
|
+
var sortedGroupedByParentRows = new Map();
|
|
8
10
|
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}]]);
|
|
11
|
+
var sortGroup = function sortGroup(node) {
|
|
12
|
+
var shouldSortGroup = !!sortRowList && (!disableChildrenSorting || node.depth === -1);
|
|
13
|
+
var sortedRowIds;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var group = groupedByParentRows.get(node.parent);
|
|
15
|
+
if (shouldSortGroup) {
|
|
16
|
+
for (var i = 0; i < node.children.length; i += 1) {
|
|
17
|
+
var childNode = rowTree[node.children[i]];
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
groupedByParentRows.set(node.parent, group);
|
|
25
|
-
}
|
|
19
|
+
if (childNode.type === 'group') {
|
|
20
|
+
sortGroup(childNode);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
sortedRowIds = sortRowList(node.children.map(function (childId) {
|
|
25
|
+
return rowTree[childId];
|
|
26
|
+
}));
|
|
27
|
+
} else if (shouldRenderGroupBelowLeaves) {
|
|
28
|
+
var childrenLeaves = [];
|
|
29
|
+
var childrenGroups = [];
|
|
33
30
|
|
|
31
|
+
for (var _i = 0; _i < node.children.length; _i += 1) {
|
|
32
|
+
var childId = node.children[_i];
|
|
33
|
+
var _childNode = rowTree[childId];
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
if (_childNode.type === 'group') {
|
|
36
|
+
sortGroup(_childNode);
|
|
37
|
+
childrenGroups.push(childId);
|
|
38
|
+
} else if (_childNode.type === 'leaf') {
|
|
39
|
+
childrenLeaves.push(childId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
sortedRowIds = [].concat(childrenLeaves, childrenGroups);
|
|
39
44
|
} else {
|
|
40
|
-
var
|
|
41
|
-
|
|
45
|
+
for (var _i2 = 0; _i2 < node.children.length; _i2 += 1) {
|
|
46
|
+
var _childNode2 = rowTree[node.children[_i2]];
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
groupSortedRows = sortRowList(group.body);
|
|
48
|
+
if (_childNode2.type === 'group') {
|
|
49
|
+
sortGroup(_childNode2);
|
|
50
|
+
}
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
53
|
+
sortedRowIds = _toConsumableArray(node.children);
|
|
54
|
+
}
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
if (node.footerId != null) {
|
|
57
|
+
sortedRowIds.push(node.footerId);
|
|
56
58
|
}
|
|
57
|
-
|
|
59
|
+
|
|
60
|
+
sortedGroupedByParentRows.set(node.id, sortedRowIds);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
sortGroup(rowTree[GRID_ROOT_GROUP_ID]); // Flatten the sorted lists to have children just after their parent
|
|
58
64
|
|
|
59
65
|
var insertRowListIntoSortedRows = function insertRowListIntoSortedRows(startIndex, rowList) {
|
|
60
66
|
sortedRows = [].concat(_toConsumableArray(sortedRows.slice(0, startIndex)), _toConsumableArray(rowList), _toConsumableArray(sortedRows.slice(startIndex)));
|
|
@@ -71,6 +77,6 @@ export var sortRowTree = function sortRowTree(params) {
|
|
|
71
77
|
return treeSize;
|
|
72
78
|
};
|
|
73
79
|
|
|
74
|
-
insertRowListIntoSortedRows(0, sortedGroupedByParentRows.get(
|
|
80
|
+
insertRowListIntoSortedRows(0, sortedGroupedByParentRows.get(GRID_ROOT_GROUP_ID));
|
|
75
81
|
return sortedRows;
|
|
76
82
|
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
|
|
3
|
+
import { isDeepEqual, getTreeNodeDescendants } from '@mui/x-data-grid/internals';
|
|
4
|
+
import { insertDataRowInTree } from './insertDataRowInTree';
|
|
5
|
+
import { removeDataRowFromTree } from './removeDataRowFromTree';
|
|
6
|
+
import { createUpdatedGroupsManager, getNodePathInTree } from './utils';
|
|
7
|
+
export var updateRowTree = function updateRowTree(params) {
|
|
8
|
+
var tree = _extends({}, params.previousTree);
|
|
9
|
+
|
|
10
|
+
var treeDepths = _extends({}, params.previousTreeDepth);
|
|
11
|
+
|
|
12
|
+
var updatedGroupsManager = createUpdatedGroupsManager();
|
|
13
|
+
|
|
14
|
+
for (var i = 0; i < params.nodes.inserted.length; i += 1) {
|
|
15
|
+
var _params$nodes$inserte = params.nodes.inserted[i],
|
|
16
|
+
id = _params$nodes$inserte.id,
|
|
17
|
+
path = _params$nodes$inserte.path;
|
|
18
|
+
insertDataRowInTree({
|
|
19
|
+
tree: tree,
|
|
20
|
+
treeDepths: treeDepths,
|
|
21
|
+
updatedGroupsManager: updatedGroupsManager,
|
|
22
|
+
id: id,
|
|
23
|
+
path: path,
|
|
24
|
+
onDuplicatePath: params.onDuplicatePath,
|
|
25
|
+
isGroupExpandedByDefault: params.isGroupExpandedByDefault,
|
|
26
|
+
defaultGroupingExpansionDepth: params.defaultGroupingExpansionDepth
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (var _i = 0; _i < params.nodes.removed.length; _i += 1) {
|
|
31
|
+
var nodeId = params.nodes.removed[_i];
|
|
32
|
+
removeDataRowFromTree({
|
|
33
|
+
tree: tree,
|
|
34
|
+
treeDepths: treeDepths,
|
|
35
|
+
updatedGroupsManager: updatedGroupsManager,
|
|
36
|
+
id: nodeId
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (var _i2 = 0; _i2 < params.nodes.modified.length; _i2 += 1) {
|
|
41
|
+
var _params$nodes$modifie = params.nodes.modified[_i2],
|
|
42
|
+
_id = _params$nodes$modifie.id,
|
|
43
|
+
_path = _params$nodes$modifie.path;
|
|
44
|
+
var pathInPreviousTree = getNodePathInTree({
|
|
45
|
+
tree: tree,
|
|
46
|
+
id: _id
|
|
47
|
+
});
|
|
48
|
+
var isInSameGroup = isDeepEqual(pathInPreviousTree, _path);
|
|
49
|
+
|
|
50
|
+
if (!isInSameGroup) {
|
|
51
|
+
removeDataRowFromTree({
|
|
52
|
+
tree: tree,
|
|
53
|
+
treeDepths: treeDepths,
|
|
54
|
+
updatedGroupsManager: updatedGroupsManager,
|
|
55
|
+
id: _id
|
|
56
|
+
});
|
|
57
|
+
insertDataRowInTree({
|
|
58
|
+
tree: tree,
|
|
59
|
+
treeDepths: treeDepths,
|
|
60
|
+
updatedGroupsManager: updatedGroupsManager,
|
|
61
|
+
id: _id,
|
|
62
|
+
path: _path,
|
|
63
|
+
onDuplicatePath: params.onDuplicatePath,
|
|
64
|
+
isGroupExpandedByDefault: params.isGroupExpandedByDefault,
|
|
65
|
+
defaultGroupingExpansionDepth: params.defaultGroupingExpansionDepth
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(tree[_id].parent, 'modifyChildren');
|
|
69
|
+
}
|
|
70
|
+
} // TODO rows v6: Avoid walking the whole tree, we should be able to generate the new list only using slices.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
var dataRowIds = getTreeNodeDescendants(tree, GRID_ROOT_GROUP_ID, true);
|
|
74
|
+
return {
|
|
75
|
+
tree: tree,
|
|
76
|
+
treeDepths: treeDepths,
|
|
77
|
+
groupingName: params.groupingName,
|
|
78
|
+
dataRowIds: dataRowIds,
|
|
79
|
+
updatedGroupsManager: updatedGroupsManager
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
6
|
+
import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
|
|
7
|
+
export var getGroupRowIdFromPath = function getGroupRowIdFromPath(path) {
|
|
8
|
+
var pathStr = path.map(function (groupingCriteria) {
|
|
9
|
+
return "".concat(groupingCriteria.field, "/").concat(groupingCriteria.key);
|
|
10
|
+
}).join('-');
|
|
11
|
+
return "auto-generated-row-".concat(pathStr);
|
|
12
|
+
};
|
|
13
|
+
export var getNodePathInTree = function getNodePathInTree(_ref) {
|
|
14
|
+
var id = _ref.id,
|
|
15
|
+
tree = _ref.tree;
|
|
16
|
+
var path = [];
|
|
17
|
+
var node = tree[id];
|
|
18
|
+
|
|
19
|
+
while (node.id !== GRID_ROOT_GROUP_ID) {
|
|
20
|
+
path.push({
|
|
21
|
+
field: node.groupingField,
|
|
22
|
+
key: node.groupingKey
|
|
23
|
+
});
|
|
24
|
+
node = tree[node.parent];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return path;
|
|
28
|
+
};
|
|
29
|
+
export var addGroupDefaultExpansion = function addGroupDefaultExpansion(_ref2) {
|
|
30
|
+
var node = _ref2.node,
|
|
31
|
+
isGroupExpandedByDefault = _ref2.isGroupExpandedByDefault,
|
|
32
|
+
defaultGroupingExpansionDepth = _ref2.defaultGroupingExpansionDepth;
|
|
33
|
+
var childrenExpanded;
|
|
34
|
+
|
|
35
|
+
if (node.id === GRID_ROOT_GROUP_ID) {
|
|
36
|
+
childrenExpanded = true;
|
|
37
|
+
} else if (isGroupExpandedByDefault) {
|
|
38
|
+
childrenExpanded = isGroupExpandedByDefault(node);
|
|
39
|
+
} else {
|
|
40
|
+
childrenExpanded = defaultGroupingExpansionDepth === -1 || defaultGroupingExpansionDepth > node.depth;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return _extends({}, node, {
|
|
44
|
+
childrenExpanded: childrenExpanded
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Insert a node in the tree
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export var insertNodeInTree = function insertNodeInTree(_ref3) {
|
|
52
|
+
var _treeDepths$node$dept;
|
|
53
|
+
|
|
54
|
+
var node = _ref3.node,
|
|
55
|
+
tree = _ref3.tree,
|
|
56
|
+
treeDepths = _ref3.treeDepths;
|
|
57
|
+
// 1. Insert node in the tree.
|
|
58
|
+
tree[node.id] = node; // 2. Increment the `treeDepths` object for the node's depth.
|
|
59
|
+
|
|
60
|
+
treeDepths[node.depth] = ((_treeDepths$node$dept = treeDepths[node.depth]) != null ? _treeDepths$node$dept : 0) + 1; // 3. Register the new node in its parent.
|
|
61
|
+
|
|
62
|
+
var parentNode = tree[node.parent];
|
|
63
|
+
|
|
64
|
+
if (node.type === 'footer') {
|
|
65
|
+
// For footers,
|
|
66
|
+
// Register the node from its parent `footerId` property.
|
|
67
|
+
tree[node.parent] = _extends({}, parentNode, {
|
|
68
|
+
footerId: node.id
|
|
69
|
+
});
|
|
70
|
+
} else if (node.type === 'group' || node.type === 'leaf') {
|
|
71
|
+
var _groupingField, _groupingKey, _parentNode$childrenF;
|
|
72
|
+
|
|
73
|
+
// For groups and leaves,
|
|
74
|
+
// Register the node from its parents `children` and `childrenFromPath` properties.
|
|
75
|
+
var groupingField = (_groupingField = node.groupingField) != null ? _groupingField : '__no_field__';
|
|
76
|
+
var groupingKey = (_groupingKey = node.groupingKey) != null ? _groupingKey : '__no_key__';
|
|
77
|
+
tree[node.parent] = _extends({}, parentNode, {
|
|
78
|
+
childrenFromPath: _extends({}, parentNode.childrenFromPath, _defineProperty({}, groupingField, _extends({}, (_parentNode$childrenF = parentNode.childrenFromPath) == null ? void 0 : _parentNode$childrenF[groupingField], _defineProperty({}, groupingKey.toString(), node.id)))),
|
|
79
|
+
children: [].concat(_toConsumableArray(parentNode.children), [node.id])
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Removes a node from the tree
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
export var removeNodeFromTree = function removeNodeFromTree(_ref4) {
|
|
88
|
+
var node = _ref4.node,
|
|
89
|
+
tree = _ref4.tree,
|
|
90
|
+
treeDepths = _ref4.treeDepths;
|
|
91
|
+
// 1. Remove node from the tree.
|
|
92
|
+
delete tree[node.id]; // 2. Decrement the `treeDepths` object for the node's depth.
|
|
93
|
+
|
|
94
|
+
var nodeDepth = node.depth;
|
|
95
|
+
var currentNodeCount = treeDepths[nodeDepth];
|
|
96
|
+
|
|
97
|
+
if (currentNodeCount === 1) {
|
|
98
|
+
delete treeDepths[nodeDepth];
|
|
99
|
+
} else {
|
|
100
|
+
treeDepths[nodeDepth] = currentNodeCount - 1;
|
|
101
|
+
} // 3. Unregister the new node in its parent.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
var parentNode = tree[node.parent]; // For footers,
|
|
105
|
+
// Unregister the node from its parent `footerId` property.
|
|
106
|
+
|
|
107
|
+
if (node.type === 'footer') {
|
|
108
|
+
tree[parentNode.id] = _extends({}, parentNode, {
|
|
109
|
+
footerId: null
|
|
110
|
+
});
|
|
111
|
+
} // For groups and leaves,
|
|
112
|
+
// Unregister the node from its parents `children` and `childrenFromPath` properties.
|
|
113
|
+
else {
|
|
114
|
+
var _groupingField2, _groupingKey2, _parentNode$childrenF2, _parentNode$childrenF3;
|
|
115
|
+
|
|
116
|
+
var groupingField = (_groupingField2 = node.groupingField) != null ? _groupingField2 : '__no_field__';
|
|
117
|
+
var groupingKey = (_groupingKey2 = node.groupingKey) != null ? _groupingKey2 : '__no_key__';
|
|
118
|
+
|
|
119
|
+
var _ref5 = (_parentNode$childrenF2 = (_parentNode$childrenF3 = parentNode.childrenFromPath) == null ? void 0 : _parentNode$childrenF3[groupingField]) != null ? _parentNode$childrenF2 : {},
|
|
120
|
+
_groupingKey$toString = groupingKey.toString(),
|
|
121
|
+
childrenToRemove = _ref5[_groupingKey$toString],
|
|
122
|
+
newChildrenFromPathWithField = _objectWithoutProperties(_ref5, [_groupingKey$toString].map(_toPropertyKey)); // TODO rows v6: Can we avoid this linear complexity ?
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
var children = parentNode.children.filter(function (childId) {
|
|
126
|
+
return childId !== node.id;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
var childrenFromPath = _extends({}, parentNode.childrenFromPath);
|
|
130
|
+
|
|
131
|
+
if (Object.keys(newChildrenFromPathWithField).length === 0) {
|
|
132
|
+
delete childrenFromPath[groupingField];
|
|
133
|
+
} else {
|
|
134
|
+
childrenFromPath[groupingField] = newChildrenFromPathWithField;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
tree[parentNode.id] = _extends({}, parentNode, {
|
|
138
|
+
children: children,
|
|
139
|
+
childrenFromPath: childrenFromPath
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Updates the `id` and `isAutoGenerated` properties of a group node.
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
export var updateGroupNodeIdAndAutoGenerated = function updateGroupNodeIdAndAutoGenerated(_ref6) {
|
|
148
|
+
var node = _ref6.node,
|
|
149
|
+
updatedNode = _ref6.updatedNode,
|
|
150
|
+
tree = _ref6.tree,
|
|
151
|
+
treeDepths = _ref6.treeDepths;
|
|
152
|
+
// 1. Set the new parent for all children from the old group
|
|
153
|
+
node.children.forEach(function (childId) {
|
|
154
|
+
tree[childId] = _extends({}, tree[childId], {
|
|
155
|
+
parent: updatedNode.id
|
|
156
|
+
});
|
|
157
|
+
}); // 2. Remove the old group from the tree
|
|
158
|
+
|
|
159
|
+
removeNodeFromTree({
|
|
160
|
+
node: node,
|
|
161
|
+
tree: tree,
|
|
162
|
+
treeDepths: treeDepths
|
|
163
|
+
}); // 3. Add the new group in the tree
|
|
164
|
+
|
|
165
|
+
var groupNode = _extends({}, node, updatedNode);
|
|
166
|
+
|
|
167
|
+
insertNodeInTree({
|
|
168
|
+
node: groupNode,
|
|
169
|
+
tree: tree,
|
|
170
|
+
treeDepths: treeDepths
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
export var createUpdatedGroupsManager = function createUpdatedGroupsManager() {
|
|
174
|
+
return {
|
|
175
|
+
value: {},
|
|
176
|
+
addAction: function addAction(groupId, action) {
|
|
177
|
+
if (!this.value[groupId]) {
|
|
178
|
+
this.value[groupId] = {};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.value[groupId][action] = true;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { GridEventListener, GridCallbackDetails, GridRowParams, GridRowId, GridValidRowModel, GridGroupNode, GridFeatureMode } from '@mui/x-data-grid';
|
|
3
3
|
import { GridExperimentalFeatures, DataGridPropsWithoutDefaultValue, DataGridPropsWithDefaultValues, DataGridPropsWithComplexDefaultValueAfterProcessing, DataGridPropsWithComplexDefaultValueBeforeProcessing } from '@mui/x-data-grid/internals';
|
|
4
4
|
import type { GridPinnedColumns } from '../hooks/features/columnPinning';
|
|
5
5
|
import type { GridPinnedRowsProp } from '../hooks/features/rowPinning';
|
|
@@ -52,10 +52,10 @@ export interface DataGridProPropsWithDefaultValue extends DataGridPropsWithDefau
|
|
|
52
52
|
/**
|
|
53
53
|
* Determines if a group should be expanded after its creation.
|
|
54
54
|
* This prop takes priority over the `defaultGroupingExpansionDepth` prop.
|
|
55
|
-
* @param {
|
|
55
|
+
* @param {GridGroupNode} node The node of the group to test.
|
|
56
56
|
* @returns {boolean} A boolean indicating if the group is expanded.
|
|
57
57
|
*/
|
|
58
|
-
isGroupExpandedByDefault?: (node:
|
|
58
|
+
isGroupExpandedByDefault?: (node: GridGroupNode) => boolean;
|
|
59
59
|
/**
|
|
60
60
|
* If `true`, the column pinning is disabled.
|
|
61
61
|
* @default false
|
|
@@ -437,7 +437,7 @@ DataGridProRaw.propTypes = {
|
|
|
437
437
|
/**
|
|
438
438
|
* Determines if a group should be expanded after its creation.
|
|
439
439
|
* This prop takes priority over the `defaultGroupingExpansionDepth` prop.
|
|
440
|
-
* @param {
|
|
440
|
+
* @param {GridGroupNode} node The node of the group to test.
|
|
441
441
|
* @returns {boolean} A boolean indicating if the group is expanded.
|
|
442
442
|
*/
|
|
443
443
|
isGroupExpandedByDefault: PropTypes.func,
|
|
@@ -615,16 +615,6 @@ DataGridProRaw.propTypes = {
|
|
|
615
615
|
*/
|
|
616
616
|
onColumnResize: PropTypes.func,
|
|
617
617
|
|
|
618
|
-
/**
|
|
619
|
-
* Callback fired when a column visibility changes.
|
|
620
|
-
* Only works when no `columnVisibilityModel` is provided and if we change the visibility of a single column at a time.
|
|
621
|
-
* @param {GridColumnVisibilityChangeParams} params With all properties from [[GridColumnVisibilityChangeParams]].
|
|
622
|
-
* @param {MuiEvent<{}>} event The event object.
|
|
623
|
-
* @param {GridCallbackDetails} details Additional details for this callback.
|
|
624
|
-
* @deprecated Use `onColumnVisibilityModelChange` instead.
|
|
625
|
-
*/
|
|
626
|
-
onColumnVisibilityChange: PropTypes.func,
|
|
627
|
-
|
|
628
618
|
/**
|
|
629
619
|
* Callback fired when the column visibility model changes.
|
|
630
620
|
* @param {GridColumnVisibilityModel} model The new model.
|
|
@@ -876,8 +866,8 @@ DataGridProRaw.propTypes = {
|
|
|
876
866
|
* Rows data to pin on top or bottom.
|
|
877
867
|
*/
|
|
878
868
|
pinnedRows: PropTypes.shape({
|
|
879
|
-
bottom: PropTypes.
|
|
880
|
-
top: PropTypes.
|
|
869
|
+
bottom: PropTypes.arrayOf(PropTypes.object),
|
|
870
|
+
top: PropTypes.arrayOf(PropTypes.object)
|
|
881
871
|
}),
|
|
882
872
|
|
|
883
873
|
/**
|
|
@@ -922,7 +912,7 @@ DataGridProRaw.propTypes = {
|
|
|
922
912
|
/**
|
|
923
913
|
* Set of rows of type [[GridRowsProp]].
|
|
924
914
|
*/
|
|
925
|
-
rows: PropTypes.
|
|
915
|
+
rows: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
926
916
|
|
|
927
917
|
/**
|
|
928
918
|
* Loading rows can be processed on the server or client-side.
|