@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.
Files changed (129) hide show
  1. package/CHANGELOG.md +297 -19
  2. package/DataGridPro/DataGridPro.js +4 -14
  3. package/DataGridPro/useDataGridProProps.js +2 -2
  4. package/components/DataGridProVirtualScroller.js +2 -2
  5. package/components/GridDetailPanelToggleCell.js +1 -1
  6. package/components/GridRowReorderCell.js +4 -6
  7. package/components/GridTreeDataGroupingCell.d.ts +2 -2
  8. package/components/GridTreeDataGroupingCell.js +1 -1
  9. package/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  10. package/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  11. package/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  12. package/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
  13. package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.d.ts +1 -1
  14. package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
  15. package/hooks/features/rowPinning/gridRowPinningInterface.d.ts +2 -2
  16. package/hooks/features/rowPinning/useGridRowPinningPreProcessors.d.ts +16 -16
  17. package/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
  18. package/hooks/features/rowReorder/useGridRowReorder.js +5 -5
  19. package/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  20. package/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  21. package/hooks/features/treeData/useGridTreeData.js +2 -6
  22. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
  23. package/index.js +1 -1
  24. package/internals/index.d.ts +4 -2
  25. package/internals/index.js +4 -2
  26. package/legacy/DataGridPro/DataGridPro.js +4 -14
  27. package/legacy/DataGridPro/useDataGridProProps.js +2 -2
  28. package/legacy/components/DataGridProVirtualScroller.js +2 -2
  29. package/legacy/components/GridDetailPanelToggleCell.js +1 -1
  30. package/legacy/components/GridRowReorderCell.js +4 -6
  31. package/legacy/components/GridTreeDataGroupingCell.js +1 -1
  32. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  33. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  34. package/legacy/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  35. package/legacy/hooks/features/lazyLoader/useGridLazyLoader.js +25 -15
  36. package/legacy/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +21 -7
  37. package/legacy/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
  38. package/legacy/hooks/features/rowReorder/useGridRowReorder.js +5 -5
  39. package/legacy/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  40. package/legacy/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  41. package/legacy/hooks/features/treeData/useGridTreeData.js +2 -6
  42. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +37 -22
  43. package/legacy/index.js +1 -1
  44. package/legacy/internals/index.js +4 -2
  45. package/legacy/utils/tree/createRowTree.js +36 -0
  46. package/legacy/utils/tree/index.js +1 -1
  47. package/legacy/utils/tree/insertDataRowInTree.js +127 -0
  48. package/legacy/utils/tree/models.js +1 -0
  49. package/legacy/utils/tree/removeDataRowFromTree.js +97 -0
  50. package/legacy/utils/tree/sortRowTree.js +49 -43
  51. package/legacy/utils/tree/updateRowTree.js +81 -0
  52. package/legacy/utils/tree/utils.js +184 -0
  53. package/models/dataGridProProps.d.ts +3 -3
  54. package/modern/DataGridPro/DataGridPro.js +4 -14
  55. package/modern/DataGridPro/useDataGridProProps.js +2 -2
  56. package/modern/components/DataGridProVirtualScroller.js +2 -2
  57. package/modern/components/GridDetailPanelToggleCell.js +1 -1
  58. package/modern/components/GridRowReorderCell.js +4 -4
  59. package/modern/components/GridTreeDataGroupingCell.js +1 -1
  60. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  61. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  62. package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  63. package/modern/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
  64. package/modern/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
  65. package/modern/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +60 -23
  66. package/modern/hooks/features/rowReorder/useGridRowReorder.js +5 -3
  67. package/modern/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  68. package/modern/hooks/features/treeData/gridTreeDataUtils.js +13 -9
  69. package/modern/hooks/features/treeData/useGridTreeData.js +2 -4
  70. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
  71. package/modern/index.js +1 -1
  72. package/modern/internals/index.js +4 -2
  73. package/modern/utils/tree/createRowTree.js +35 -0
  74. package/modern/utils/tree/index.js +1 -1
  75. package/modern/utils/tree/insertDataRowInTree.js +127 -0
  76. package/modern/utils/tree/models.js +1 -0
  77. package/modern/utils/tree/removeDataRowFromTree.js +100 -0
  78. package/modern/utils/tree/sortRowTree.js +46 -40
  79. package/modern/utils/tree/updateRowTree.js +83 -0
  80. package/modern/utils/tree/utils.js +180 -0
  81. package/node/DataGridPro/DataGridPro.js +4 -14
  82. package/node/DataGridPro/useDataGridProProps.js +1 -1
  83. package/node/components/DataGridProVirtualScroller.js +1 -1
  84. package/node/components/GridDetailPanelToggleCell.js +1 -1
  85. package/node/components/GridRowReorderCell.js +3 -5
  86. package/node/components/GridTreeDataGroupingCell.js +1 -1
  87. package/node/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
  88. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  89. package/node/hooks/features/infiniteLoader/useGridInfiniteLoader.js +1 -1
  90. package/node/hooks/features/lazyLoader/useGridLazyLoader.js +19 -8
  91. package/node/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +18 -5
  92. package/node/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +63 -26
  93. package/node/hooks/features/rowReorder/useGridRowReorder.js +4 -4
  94. package/node/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  95. package/node/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  96. package/node/hooks/features/treeData/useGridTreeData.js +1 -5
  97. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -17
  98. package/node/index.js +1 -1
  99. package/node/internals/index.js +35 -10
  100. package/node/utils/tree/createRowTree.js +46 -0
  101. package/node/utils/tree/index.js +2 -2
  102. package/node/utils/tree/insertDataRowInTree.js +139 -0
  103. package/node/utils/tree/models.js +5 -0
  104. package/node/utils/tree/removeDataRowFromTree.js +110 -0
  105. package/node/utils/tree/sortRowTree.js +50 -43
  106. package/node/utils/tree/updateRowTree.js +98 -0
  107. package/node/utils/tree/utils.js +217 -0
  108. package/package.json +5 -5
  109. package/utils/tree/createRowTree.d.ts +15 -0
  110. package/utils/tree/createRowTree.js +35 -0
  111. package/utils/tree/index.d.ts +1 -1
  112. package/utils/tree/index.js +1 -1
  113. package/utils/tree/insertDataRowInTree.d.ts +51 -0
  114. package/utils/tree/insertDataRowInTree.js +129 -0
  115. package/utils/tree/models.d.ts +13 -0
  116. package/utils/tree/models.js +1 -0
  117. package/utils/tree/removeDataRowFromTree.d.ts +40 -0
  118. package/utils/tree/removeDataRowFromTree.js +100 -0
  119. package/utils/tree/sortRowTree.d.ts +6 -1
  120. package/utils/tree/sortRowTree.js +46 -40
  121. package/utils/tree/updateRowTree.d.ts +19 -0
  122. package/utils/tree/updateRowTree.js +83 -0
  123. package/utils/tree/utils.d.ts +66 -0
  124. package/utils/tree/utils.js +186 -0
  125. package/legacy/utils/tree/buildRowTree.js +0 -195
  126. package/modern/utils/tree/buildRowTree.js +0 -174
  127. package/node/utils/tree/buildRowTree.js +0 -195
  128. package/utils/tree/buildRowTree.d.ts +0 -48
  129. package/utils/tree/buildRowTree.js +0 -186
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "getGroupRowIdFromPath", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _buildRowTree.getGroupRowIdFromPath;
9
+ return _utils.getGroupRowIdFromPath;
10
10
  }
11
11
  });
12
12
 
13
- var _buildRowTree = require("./buildRowTree");
13
+ var _utils = require("./utils");
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.insertDataRowInTree = void 0;
7
+
8
+ var _xDataGrid = require("@mui/x-data-grid");
9
+
10
+ var _utils = require("./utils");
11
+
12
+ /**
13
+ * Inserts a data row in a tree.
14
+ * For each steps of its path:
15
+ * - if a node exists with the same partial path, it will register this node as the ancestor of the data row.
16
+ * - if not, it will create an auto-generated node and register it as ancestor of the data row.
17
+ */
18
+ const insertDataRowInTree = ({
19
+ id,
20
+ path,
21
+ updatedGroupsManager,
22
+ tree,
23
+ treeDepths,
24
+ onDuplicatePath,
25
+ isGroupExpandedByDefault,
26
+ defaultGroupingExpansionDepth
27
+ }) => {
28
+ let parentNodeId = _xDataGrid.GRID_ROOT_GROUP_ID;
29
+
30
+ for (let depth = 0; depth < path.length; depth += 1) {
31
+ var _childrenFromPath, _childrenFromPath$fie;
32
+
33
+ const {
34
+ key,
35
+ field
36
+ } = path[depth];
37
+ const fieldWithDefaultValue = field != null ? field : '__no_field__';
38
+ const keyWithDefaultValue = key != null ? key : '__no_key__';
39
+ const 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,
40
+ // We need to create a node for the row passed to `insertNodeInTree`
41
+
42
+ if (depth === path.length - 1) {
43
+ // If no node matches the full path,
44
+ // We create a leaf node for the data row.
45
+ if (existingNodeIdWithPartialPath == null) {
46
+ const leafNode = {
47
+ type: 'leaf',
48
+ id,
49
+ depth,
50
+ parent: parentNodeId,
51
+ groupingKey: key
52
+ };
53
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'insertChildren');
54
+ (0, _utils.insertNodeInTree)({
55
+ node: leafNode,
56
+ tree,
57
+ treeDepths
58
+ });
59
+ } else {
60
+ const existingNodeWithPartialPath = tree[existingNodeIdWithPartialPath]; // If we already have an auto-generated group matching the partial path,
61
+ // We replace it with the node from of data row passed to `insertNodeInTree`
62
+
63
+ if (existingNodeWithPartialPath.type === 'group' && existingNodeWithPartialPath.isAutoGenerated) {
64
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'removeChildren');
65
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'insertChildren');
66
+ (0, _utils.updateGroupNodeIdAndAutoGenerated)({
67
+ tree,
68
+ treeDepths,
69
+ node: existingNodeWithPartialPath,
70
+ updatedNode: {
71
+ id,
72
+ isAutoGenerated: false
73
+ }
74
+ });
75
+ } else {
76
+ // If we have another row matching the partial path, then there is a duplicate in the dataset.
77
+ // We warn the user and skip the current row.
78
+ onDuplicatePath == null ? void 0 : onDuplicatePath(existingNodeIdWithPartialPath, id, path);
79
+ }
80
+ }
81
+ } // For the intermediary steps of the path,
82
+ // We need to make sure that there is a node matching the partial path.
83
+ //
84
+ // If no node matches the partial path,
85
+ // We create an auto-generated group node.
86
+ else if (existingNodeIdWithPartialPath == null) {
87
+ const nodeId = (0, _utils.getGroupRowIdFromPath)(path.slice(0, depth + 1));
88
+ const autoGeneratedGroupNode = {
89
+ type: 'group',
90
+ id: nodeId,
91
+ parent: parentNodeId,
92
+ depth,
93
+ isAutoGenerated: true,
94
+ groupingKey: key,
95
+ groupingField: field,
96
+ children: [],
97
+ childrenFromPath: {}
98
+ };
99
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNodeId, 'insertChildren');
100
+ (0, _utils.insertNodeInTree)({
101
+ node: (0, _utils.addGroupDefaultExpansion)({
102
+ node: autoGeneratedGroupNode,
103
+ defaultGroupingExpansionDepth,
104
+ isGroupExpandedByDefault
105
+ }),
106
+ tree,
107
+ treeDepths
108
+ });
109
+ parentNodeId = nodeId;
110
+ } // For the intermediary steps of the path
111
+ // If a node matches the partial path, we use it as parent for the next step
112
+ else {
113
+ const currentGroupNode = tree[existingNodeIdWithPartialPath]; // If the node matching the partial path is not a group, we turn it into a group
114
+
115
+ if (currentGroupNode.type !== 'group') {
116
+ const groupNode = {
117
+ type: 'group',
118
+ id: currentGroupNode.id,
119
+ parent: currentGroupNode.parent,
120
+ depth: currentGroupNode.depth,
121
+ isAutoGenerated: false,
122
+ groupingKey: key,
123
+ groupingField: field,
124
+ children: [],
125
+ childrenFromPath: {}
126
+ };
127
+ tree[existingNodeIdWithPartialPath] = (0, _utils.addGroupDefaultExpansion)({
128
+ node: groupNode,
129
+ defaultGroupingExpansionDepth,
130
+ isGroupExpandedByDefault
131
+ });
132
+ }
133
+
134
+ parentNodeId = currentGroupNode.id;
135
+ }
136
+ }
137
+ };
138
+
139
+ exports.insertDataRowInTree = insertDataRowInTree;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeDataRowFromTree = void 0;
7
+
8
+ var _xDataGrid = require("@mui/x-data-grid");
9
+
10
+ var _utils = require("./utils");
11
+
12
+ const removeNodeAndCleanParent = ({
13
+ node,
14
+ tree,
15
+ treeDepths,
16
+ updatedGroupsManager
17
+ }) => {
18
+ (0, _utils.removeNodeFromTree)({
19
+ node,
20
+ tree,
21
+ treeDepths
22
+ });
23
+
24
+ if (node.type === 'group' && node.footerId != null) {
25
+ (0, _utils.removeNodeFromTree)({
26
+ node: tree[node.footerId],
27
+ tree,
28
+ treeDepths
29
+ });
30
+ }
31
+
32
+ const parentNode = tree[node.parent];
33
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(parentNode.id, 'removeChildren');
34
+ const shouldDeleteGroup = parentNode.id !== _xDataGrid.GRID_ROOT_GROUP_ID && parentNode.children.length === 0;
35
+
36
+ if (shouldDeleteGroup) {
37
+ if (parentNode.isAutoGenerated) {
38
+ removeNodeAndCleanParent({
39
+ node,
40
+ tree,
41
+ treeDepths
42
+ });
43
+ } else {
44
+ tree[parentNode.id] = {
45
+ type: 'leaf',
46
+ id: parentNode.id,
47
+ depth: parentNode.depth,
48
+ parent: parentNode.parent,
49
+ groupingKey: parentNode.groupingKey
50
+ };
51
+ }
52
+ }
53
+ };
54
+
55
+ const replaceDataGroupWithAutoGeneratedGroup = ({
56
+ node,
57
+ tree,
58
+ treeDepths,
59
+ updatedGroupsManager
60
+ }) => {
61
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(node.parent, 'removeChildren');
62
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(node.parent, 'insertChildren');
63
+ (0, _utils.updateGroupNodeIdAndAutoGenerated)({
64
+ tree,
65
+ treeDepths,
66
+ node,
67
+ updatedNode: {
68
+ id: (0, _utils.getGroupRowIdFromPath)((0, _utils.getNodePathInTree)({
69
+ id: node.id,
70
+ tree
71
+ })),
72
+ isAutoGenerated: true
73
+ }
74
+ });
75
+ };
76
+ /**
77
+ * Removed a data row from the tree.
78
+ * If the node is a non-empty group, replace it with an auto-generated group to be able to keep displaying its children.
79
+ * If not, remove it and recursively clean its parent with the following rules:
80
+ * - An empty auto-generated should be removed from the tree
81
+ * - An empty non-auto-generated should be turned into a leaf
82
+ */
83
+
84
+
85
+ const removeDataRowFromTree = ({
86
+ id,
87
+ tree,
88
+ treeDepths,
89
+ updatedGroupsManager
90
+ }) => {
91
+ const node = tree[id];
92
+
93
+ if (node.type === 'group' && node.children.length > 0) {
94
+ replaceDataGroupWithAutoGeneratedGroup({
95
+ node,
96
+ tree,
97
+ treeDepths,
98
+ updatedGroupsManager
99
+ });
100
+ } else {
101
+ removeNodeAndCleanParent({
102
+ node,
103
+ tree,
104
+ treeDepths,
105
+ updatedGroupsManager
106
+ });
107
+ }
108
+ };
109
+
110
+ exports.removeDataRowFromTree = removeDataRowFromTree;
@@ -5,62 +5,69 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.sortRowTree = void 0;
7
7
 
8
+ var _xDataGrid = require("@mui/x-data-grid");
9
+
8
10
  const sortRowTree = params => {
9
11
  const {
10
- rowIds,
11
12
  rowTree,
12
13
  disableChildrenSorting,
13
- sortRowList
14
+ sortRowList,
15
+ shouldRenderGroupBelowLeaves
14
16
  } = params;
15
- let sortedRows = []; // Group the rows by parent
16
-
17
- const groupedByParentRows = new Map([[null, {
18
- body: [],
19
- footer: null
20
- }]]);
21
-
22
- for (let i = 0; i < rowIds.length; i += 1) {
23
- const rowId = rowIds[i];
24
- const node = rowTree[rowId];
25
- let group = groupedByParentRows.get(node.parent);
26
-
27
- if (!group) {
28
- group = {
29
- body: [],
30
- footer: null
31
- };
32
- groupedByParentRows.set(node.parent, group);
33
- }
17
+ let sortedRows = [];
18
+ const sortedGroupedByParentRows = new Map();
34
19
 
35
- if (node.position === 'footer') {
36
- group.footer = node;
37
- } else {
38
- group.body.push(node);
39
- }
40
- } // Apply the sorting to each list of children
20
+ const sortGroup = node => {
21
+ const shouldSortGroup = !!sortRowList && (!disableChildrenSorting || node.depth === -1);
22
+ let sortedRowIds;
41
23
 
24
+ if (shouldSortGroup) {
25
+ for (let i = 0; i < node.children.length; i += 1) {
26
+ const childNode = rowTree[node.children[i]];
42
27
 
43
- const sortedGroupedByParentRows = new Map();
44
- groupedByParentRows.forEach((group, parent) => {
45
- if (group.body.length === 0) {
46
- sortedGroupedByParentRows.set(parent, []);
47
- } else {
48
- let groupSortedRows;
49
- const depth = group.body[0].depth;
28
+ if (childNode.type === 'group') {
29
+ sortGroup(childNode);
30
+ }
31
+ }
32
+
33
+ sortedRowIds = sortRowList(node.children.map(childId => rowTree[childId]));
34
+ } else if (shouldRenderGroupBelowLeaves) {
35
+ const childrenLeaves = [];
36
+ const childrenGroups = [];
50
37
 
51
- if (depth > 0 && disableChildrenSorting || !sortRowList) {
52
- groupSortedRows = group.body.map(row => row.id);
53
- } else {
54
- groupSortedRows = sortRowList(group.body);
38
+ for (let i = 0; i < node.children.length; i += 1) {
39
+ const childId = node.children[i];
40
+ const childNode = rowTree[childId];
41
+
42
+ if (childNode.type === 'group') {
43
+ sortGroup(childNode);
44
+ childrenGroups.push(childId);
45
+ } else if (childNode.type === 'leaf') {
46
+ childrenLeaves.push(childId);
47
+ }
55
48
  }
56
49
 
57
- if (group.footer != null) {
58
- groupSortedRows.push(group.footer.id);
50
+ sortedRowIds = [...childrenLeaves, ...childrenGroups];
51
+ } else {
52
+ for (let i = 0; i < node.children.length; i += 1) {
53
+ const childNode = rowTree[node.children[i]];
54
+
55
+ if (childNode.type === 'group') {
56
+ sortGroup(childNode);
57
+ }
59
58
  }
60
59
 
61
- sortedGroupedByParentRows.set(parent, groupSortedRows);
60
+ sortedRowIds = [...node.children];
61
+ }
62
+
63
+ if (node.footerId != null) {
64
+ sortedRowIds.push(node.footerId);
62
65
  }
63
- }); // Flatten the sorted lists to have children just after their parent
66
+
67
+ sortedGroupedByParentRows.set(node.id, sortedRowIds);
68
+ };
69
+
70
+ sortGroup(rowTree[_xDataGrid.GRID_ROOT_GROUP_ID]); // Flatten the sorted lists to have children just after their parent
64
71
 
65
72
  const insertRowListIntoSortedRows = (startIndex, rowList) => {
66
73
  sortedRows = [...sortedRows.slice(0, startIndex), ...rowList, ...sortedRows.slice(startIndex)];
@@ -77,7 +84,7 @@ const sortRowTree = params => {
77
84
  return treeSize;
78
85
  };
79
86
 
80
- insertRowListIntoSortedRows(0, sortedGroupedByParentRows.get(null));
87
+ insertRowListIntoSortedRows(0, sortedGroupedByParentRows.get(_xDataGrid.GRID_ROOT_GROUP_ID));
81
88
  return sortedRows;
82
89
  };
83
90
 
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.updateRowTree = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _xDataGrid = require("@mui/x-data-grid");
13
+
14
+ var _internals = require("@mui/x-data-grid/internals");
15
+
16
+ var _insertDataRowInTree = require("./insertDataRowInTree");
17
+
18
+ var _removeDataRowFromTree = require("./removeDataRowFromTree");
19
+
20
+ var _utils = require("./utils");
21
+
22
+ const updateRowTree = params => {
23
+ const tree = (0, _extends2.default)({}, params.previousTree);
24
+ const treeDepths = (0, _extends2.default)({}, params.previousTreeDepth);
25
+ const updatedGroupsManager = (0, _utils.createUpdatedGroupsManager)();
26
+
27
+ for (let i = 0; i < params.nodes.inserted.length; i += 1) {
28
+ const {
29
+ id,
30
+ path
31
+ } = params.nodes.inserted[i];
32
+ (0, _insertDataRowInTree.insertDataRowInTree)({
33
+ tree,
34
+ treeDepths,
35
+ updatedGroupsManager,
36
+ id,
37
+ path,
38
+ onDuplicatePath: params.onDuplicatePath,
39
+ isGroupExpandedByDefault: params.isGroupExpandedByDefault,
40
+ defaultGroupingExpansionDepth: params.defaultGroupingExpansionDepth
41
+ });
42
+ }
43
+
44
+ for (let i = 0; i < params.nodes.removed.length; i += 1) {
45
+ const nodeId = params.nodes.removed[i];
46
+ (0, _removeDataRowFromTree.removeDataRowFromTree)({
47
+ tree,
48
+ treeDepths,
49
+ updatedGroupsManager,
50
+ id: nodeId
51
+ });
52
+ }
53
+
54
+ for (let i = 0; i < params.nodes.modified.length; i += 1) {
55
+ const {
56
+ id,
57
+ path
58
+ } = params.nodes.modified[i];
59
+ const pathInPreviousTree = (0, _utils.getNodePathInTree)({
60
+ tree,
61
+ id
62
+ });
63
+ const isInSameGroup = (0, _internals.isDeepEqual)(pathInPreviousTree, path);
64
+
65
+ if (!isInSameGroup) {
66
+ (0, _removeDataRowFromTree.removeDataRowFromTree)({
67
+ tree,
68
+ treeDepths,
69
+ updatedGroupsManager,
70
+ id
71
+ });
72
+ (0, _insertDataRowInTree.insertDataRowInTree)({
73
+ tree,
74
+ treeDepths,
75
+ updatedGroupsManager,
76
+ id,
77
+ path,
78
+ onDuplicatePath: params.onDuplicatePath,
79
+ isGroupExpandedByDefault: params.isGroupExpandedByDefault,
80
+ defaultGroupingExpansionDepth: params.defaultGroupingExpansionDepth
81
+ });
82
+ } else {
83
+ updatedGroupsManager == null ? void 0 : updatedGroupsManager.addAction(tree[id].parent, 'modifyChildren');
84
+ }
85
+ } // TODO rows v6: Avoid walking the whole tree, we should be able to generate the new list only using slices.
86
+
87
+
88
+ const dataRowIds = (0, _internals.getTreeNodeDescendants)(tree, _xDataGrid.GRID_ROOT_GROUP_ID, true);
89
+ return {
90
+ tree,
91
+ treeDepths,
92
+ groupingName: params.groupingName,
93
+ dataRowIds,
94
+ updatedGroupsManager
95
+ };
96
+ };
97
+
98
+ exports.updateRowTree = updateRowTree;
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.updateGroupNodeIdAndAutoGenerated = exports.removeNodeFromTree = exports.insertNodeInTree = exports.getNodePathInTree = exports.getGroupRowIdFromPath = exports.createUpdatedGroupsManager = exports.addGroupDefaultExpansion = void 0;
9
+
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
+
12
+ var _toPropertyKey2 = _interopRequireDefault(require("@babel/runtime/helpers/toPropertyKey"));
13
+
14
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
+
16
+ var _xDataGrid = require("@mui/x-data-grid");
17
+
18
+ const getGroupRowIdFromPath = path => {
19
+ const pathStr = path.map(groupingCriteria => `${groupingCriteria.field}/${groupingCriteria.key}`).join('-');
20
+ return `auto-generated-row-${pathStr}`;
21
+ };
22
+
23
+ exports.getGroupRowIdFromPath = getGroupRowIdFromPath;
24
+
25
+ const getNodePathInTree = ({
26
+ id,
27
+ tree
28
+ }) => {
29
+ const path = [];
30
+ let node = tree[id];
31
+
32
+ while (node.id !== _xDataGrid.GRID_ROOT_GROUP_ID) {
33
+ path.push({
34
+ field: node.groupingField,
35
+ key: node.groupingKey
36
+ });
37
+ node = tree[node.parent];
38
+ }
39
+
40
+ return path;
41
+ };
42
+
43
+ exports.getNodePathInTree = getNodePathInTree;
44
+
45
+ const addGroupDefaultExpansion = ({
46
+ node,
47
+ isGroupExpandedByDefault,
48
+ defaultGroupingExpansionDepth
49
+ }) => {
50
+ let childrenExpanded;
51
+
52
+ if (node.id === _xDataGrid.GRID_ROOT_GROUP_ID) {
53
+ childrenExpanded = true;
54
+ } else if (isGroupExpandedByDefault) {
55
+ childrenExpanded = isGroupExpandedByDefault(node);
56
+ } else {
57
+ childrenExpanded = defaultGroupingExpansionDepth === -1 || defaultGroupingExpansionDepth > node.depth;
58
+ }
59
+
60
+ return (0, _extends2.default)({}, node, {
61
+ childrenExpanded
62
+ });
63
+ };
64
+ /**
65
+ * Insert a node in the tree
66
+ */
67
+
68
+
69
+ exports.addGroupDefaultExpansion = addGroupDefaultExpansion;
70
+
71
+ const insertNodeInTree = ({
72
+ node,
73
+ tree,
74
+ treeDepths
75
+ }) => {
76
+ var _treeDepths$node$dept;
77
+
78
+ // 1. Insert node in the tree.
79
+ tree[node.id] = node; // 2. Increment the `treeDepths` object for the node's depth.
80
+
81
+ treeDepths[node.depth] = ((_treeDepths$node$dept = treeDepths[node.depth]) != null ? _treeDepths$node$dept : 0) + 1; // 3. Register the new node in its parent.
82
+
83
+ const parentNode = tree[node.parent];
84
+
85
+ if (node.type === 'footer') {
86
+ // For footers,
87
+ // Register the node from its parent `footerId` property.
88
+ tree[node.parent] = (0, _extends2.default)({}, parentNode, {
89
+ footerId: node.id
90
+ });
91
+ } else if (node.type === 'group' || node.type === 'leaf') {
92
+ var _groupingField, _groupingKey, _parentNode$childrenF;
93
+
94
+ // For groups and leaves,
95
+ // Register the node from its parents `children` and `childrenFromPath` properties.
96
+ const groupingField = (_groupingField = node.groupingField) != null ? _groupingField : '__no_field__';
97
+ const groupingKey = (_groupingKey = node.groupingKey) != null ? _groupingKey : '__no_key__';
98
+ tree[node.parent] = (0, _extends2.default)({}, parentNode, {
99
+ childrenFromPath: (0, _extends2.default)({}, parentNode.childrenFromPath, {
100
+ [groupingField]: (0, _extends2.default)({}, (_parentNode$childrenF = parentNode.childrenFromPath) == null ? void 0 : _parentNode$childrenF[groupingField], {
101
+ [groupingKey.toString()]: node.id
102
+ })
103
+ }),
104
+ children: [...parentNode.children, node.id]
105
+ });
106
+ }
107
+ };
108
+ /**
109
+ * Removes a node from the tree
110
+ */
111
+
112
+
113
+ exports.insertNodeInTree = insertNodeInTree;
114
+
115
+ const removeNodeFromTree = ({
116
+ node,
117
+ tree,
118
+ treeDepths
119
+ }) => {
120
+ // 1. Remove node from the tree.
121
+ delete tree[node.id]; // 2. Decrement the `treeDepths` object for the node's depth.
122
+
123
+ const nodeDepth = node.depth;
124
+ const currentNodeCount = treeDepths[nodeDepth];
125
+
126
+ if (currentNodeCount === 1) {
127
+ delete treeDepths[nodeDepth];
128
+ } else {
129
+ treeDepths[nodeDepth] = currentNodeCount - 1;
130
+ } // 3. Unregister the new node in its parent.
131
+
132
+
133
+ const parentNode = tree[node.parent]; // For footers,
134
+ // Unregister the node from its parent `footerId` property.
135
+
136
+ if (node.type === 'footer') {
137
+ tree[parentNode.id] = (0, _extends2.default)({}, parentNode, {
138
+ footerId: null
139
+ });
140
+ } // For groups and leaves,
141
+ // Unregister the node from its parents `children` and `childrenFromPath` properties.
142
+ else {
143
+ var _groupingField2, _groupingKey2, _parentNode$childrenF2, _parentNode$childrenF3;
144
+
145
+ const groupingField = (_groupingField2 = node.groupingField) != null ? _groupingField2 : '__no_field__';
146
+ const groupingKey = (_groupingKey2 = node.groupingKey) != null ? _groupingKey2 : '__no_key__';
147
+
148
+ const _ref = (_parentNode$childrenF2 = (_parentNode$childrenF3 = parentNode.childrenFromPath) == null ? void 0 : _parentNode$childrenF3[groupingField]) != null ? _parentNode$childrenF2 : {},
149
+ _groupingKey$toString = groupingKey.toString(),
150
+ newChildrenFromPathWithField = (0, _objectWithoutPropertiesLoose2.default)(_ref, [_groupingKey$toString].map(_toPropertyKey2.default)); // TODO rows v6: Can we avoid this linear complexity ?
151
+
152
+
153
+ const children = parentNode.children.filter(childId => childId !== node.id);
154
+ const childrenFromPath = (0, _extends2.default)({}, parentNode.childrenFromPath);
155
+
156
+ if (Object.keys(newChildrenFromPathWithField).length === 0) {
157
+ delete childrenFromPath[groupingField];
158
+ } else {
159
+ childrenFromPath[groupingField] = newChildrenFromPathWithField;
160
+ }
161
+
162
+ tree[parentNode.id] = (0, _extends2.default)({}, parentNode, {
163
+ children,
164
+ childrenFromPath
165
+ });
166
+ }
167
+ };
168
+ /**
169
+ * Updates the `id` and `isAutoGenerated` properties of a group node.
170
+ */
171
+
172
+
173
+ exports.removeNodeFromTree = removeNodeFromTree;
174
+
175
+ const updateGroupNodeIdAndAutoGenerated = ({
176
+ node,
177
+ updatedNode,
178
+ tree,
179
+ treeDepths
180
+ }) => {
181
+ // 1. Set the new parent for all children from the old group
182
+ node.children.forEach(childId => {
183
+ tree[childId] = (0, _extends2.default)({}, tree[childId], {
184
+ parent: updatedNode.id
185
+ });
186
+ }); // 2. Remove the old group from the tree
187
+
188
+ removeNodeFromTree({
189
+ node,
190
+ tree,
191
+ treeDepths
192
+ }); // 3. Add the new group in the tree
193
+
194
+ const groupNode = (0, _extends2.default)({}, node, updatedNode);
195
+ insertNodeInTree({
196
+ node: groupNode,
197
+ tree,
198
+ treeDepths
199
+ });
200
+ };
201
+
202
+ exports.updateGroupNodeIdAndAutoGenerated = updateGroupNodeIdAndAutoGenerated;
203
+
204
+ const createUpdatedGroupsManager = () => ({
205
+ value: {},
206
+
207
+ addAction(groupId, action) {
208
+ if (!this.value[groupId]) {
209
+ this.value[groupId] = {};
210
+ }
211
+
212
+ this.value[groupId][action] = true;
213
+ }
214
+
215
+ });
216
+
217
+ exports.createUpdatedGroupsManager = createUpdatedGroupsManager;