@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,66 @@
|
|
|
1
|
+
import { GridChildrenFromPathLookup, GridGroupNode, GridRowId, GridRowTreeConfig, GridTreeNode } from '@mui/x-data-grid';
|
|
2
|
+
import { GridTreeDepths, GridRowTreeUpdatedGroupsManager } from '@mui/x-data-grid/internals';
|
|
3
|
+
import { RowTreeBuilderGroupingCriterion } from './models';
|
|
4
|
+
import { DataGridProProps } from '../../models/dataGridProProps';
|
|
5
|
+
export declare const getGroupRowIdFromPath: (path: RowTreeBuilderGroupingCriterion[]) => string;
|
|
6
|
+
export declare const getNodePathInTree: ({ id, tree, }: {
|
|
7
|
+
id: GridRowId;
|
|
8
|
+
tree: GridRowTreeConfig;
|
|
9
|
+
}) => RowTreeBuilderGroupingCriterion[];
|
|
10
|
+
export declare const addGroupDefaultExpansion: ({ node, isGroupExpandedByDefault, defaultGroupingExpansionDepth, }: {
|
|
11
|
+
node: GridGroupNode;
|
|
12
|
+
isGroupExpandedByDefault?: DataGridProProps['isGroupExpandedByDefault'];
|
|
13
|
+
defaultGroupingExpansionDepth: number;
|
|
14
|
+
}) => {
|
|
15
|
+
childrenExpanded: boolean;
|
|
16
|
+
isAutoGenerated: true;
|
|
17
|
+
type: "group";
|
|
18
|
+
groupingKey: import("@mui/x-data-grid").GridKeyValue | null;
|
|
19
|
+
groupingField: string | null;
|
|
20
|
+
children: GridRowId[];
|
|
21
|
+
footerId?: GridRowId | null | undefined;
|
|
22
|
+
childrenFromPath: GridChildrenFromPathLookup;
|
|
23
|
+
parent: GridRowId | null;
|
|
24
|
+
isPinned?: boolean | undefined;
|
|
25
|
+
id: GridRowId;
|
|
26
|
+
depth: number;
|
|
27
|
+
} | {
|
|
28
|
+
childrenExpanded: boolean;
|
|
29
|
+
isAutoGenerated: false;
|
|
30
|
+
type: "group";
|
|
31
|
+
groupingKey: import("@mui/x-data-grid").GridKeyValue | null;
|
|
32
|
+
groupingField: string | null;
|
|
33
|
+
children: GridRowId[];
|
|
34
|
+
footerId?: GridRowId | null | undefined;
|
|
35
|
+
childrenFromPath: GridChildrenFromPathLookup;
|
|
36
|
+
parent: GridRowId | null;
|
|
37
|
+
isPinned?: boolean | undefined;
|
|
38
|
+
id: GridRowId;
|
|
39
|
+
depth: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Insert a node in the tree
|
|
43
|
+
*/
|
|
44
|
+
export declare const insertNodeInTree: ({ node, tree, treeDepths, }: {
|
|
45
|
+
node: GridTreeNode;
|
|
46
|
+
tree: GridRowTreeConfig;
|
|
47
|
+
treeDepths: GridTreeDepths;
|
|
48
|
+
}) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Removes a node from the tree
|
|
51
|
+
*/
|
|
52
|
+
export declare const removeNodeFromTree: ({ node, tree, treeDepths, }: {
|
|
53
|
+
node: GridTreeNode;
|
|
54
|
+
tree: GridRowTreeConfig;
|
|
55
|
+
treeDepths: GridTreeDepths;
|
|
56
|
+
}) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Updates the `id` and `isAutoGenerated` properties of a group node.
|
|
59
|
+
*/
|
|
60
|
+
export declare const updateGroupNodeIdAndAutoGenerated: ({ node, updatedNode, tree, treeDepths, }: {
|
|
61
|
+
node: GridGroupNode;
|
|
62
|
+
updatedNode: Pick<GridGroupNode, 'id' | 'isAutoGenerated'>;
|
|
63
|
+
tree: GridRowTreeConfig;
|
|
64
|
+
treeDepths: GridTreeDepths;
|
|
65
|
+
}) => void;
|
|
66
|
+
export declare const createUpdatedGroupsManager: () => GridRowTreeUpdatedGroupsManager;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
|
|
5
|
+
export const getGroupRowIdFromPath = path => {
|
|
6
|
+
const pathStr = path.map(groupingCriteria => `${groupingCriteria.field}/${groupingCriteria.key}`).join('-');
|
|
7
|
+
return `auto-generated-row-${pathStr}`;
|
|
8
|
+
};
|
|
9
|
+
export const getNodePathInTree = ({
|
|
10
|
+
id,
|
|
11
|
+
tree
|
|
12
|
+
}) => {
|
|
13
|
+
const path = [];
|
|
14
|
+
let node = tree[id];
|
|
15
|
+
|
|
16
|
+
while (node.id !== GRID_ROOT_GROUP_ID) {
|
|
17
|
+
path.push({
|
|
18
|
+
field: node.groupingField,
|
|
19
|
+
key: node.groupingKey
|
|
20
|
+
});
|
|
21
|
+
node = tree[node.parent];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return path;
|
|
25
|
+
};
|
|
26
|
+
export const addGroupDefaultExpansion = ({
|
|
27
|
+
node,
|
|
28
|
+
isGroupExpandedByDefault,
|
|
29
|
+
defaultGroupingExpansionDepth
|
|
30
|
+
}) => {
|
|
31
|
+
let childrenExpanded;
|
|
32
|
+
|
|
33
|
+
if (node.id === GRID_ROOT_GROUP_ID) {
|
|
34
|
+
childrenExpanded = true;
|
|
35
|
+
} else if (isGroupExpandedByDefault) {
|
|
36
|
+
childrenExpanded = isGroupExpandedByDefault(node);
|
|
37
|
+
} else {
|
|
38
|
+
childrenExpanded = defaultGroupingExpansionDepth === -1 || defaultGroupingExpansionDepth > node.depth;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return _extends({}, node, {
|
|
42
|
+
childrenExpanded
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Insert a node in the tree
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
export const insertNodeInTree = ({
|
|
50
|
+
node,
|
|
51
|
+
tree,
|
|
52
|
+
treeDepths
|
|
53
|
+
}) => {
|
|
54
|
+
var _treeDepths$node$dept;
|
|
55
|
+
|
|
56
|
+
// 1. Insert node in the tree.
|
|
57
|
+
tree[node.id] = node; // 2. Increment the `treeDepths` object for the node's depth.
|
|
58
|
+
|
|
59
|
+
treeDepths[node.depth] = ((_treeDepths$node$dept = treeDepths[node.depth]) != null ? _treeDepths$node$dept : 0) + 1; // 3. Register the new node in its parent.
|
|
60
|
+
|
|
61
|
+
const parentNode = tree[node.parent];
|
|
62
|
+
|
|
63
|
+
if (node.type === 'footer') {
|
|
64
|
+
// For footers,
|
|
65
|
+
// Register the node from its parent `footerId` property.
|
|
66
|
+
tree[node.parent] = _extends({}, parentNode, {
|
|
67
|
+
footerId: node.id
|
|
68
|
+
});
|
|
69
|
+
} else if (node.type === 'group' || node.type === 'leaf') {
|
|
70
|
+
var _groupingField, _groupingKey, _parentNode$childrenF;
|
|
71
|
+
|
|
72
|
+
// For groups and leaves,
|
|
73
|
+
// Register the node from its parents `children` and `childrenFromPath` properties.
|
|
74
|
+
const groupingField = (_groupingField = node.groupingField) != null ? _groupingField : '__no_field__';
|
|
75
|
+
const groupingKey = (_groupingKey = node.groupingKey) != null ? _groupingKey : '__no_key__';
|
|
76
|
+
tree[node.parent] = _extends({}, parentNode, {
|
|
77
|
+
childrenFromPath: _extends({}, parentNode.childrenFromPath, {
|
|
78
|
+
[groupingField]: _extends({}, (_parentNode$childrenF = parentNode.childrenFromPath) == null ? void 0 : _parentNode$childrenF[groupingField], {
|
|
79
|
+
[groupingKey.toString()]: node.id
|
|
80
|
+
})
|
|
81
|
+
}),
|
|
82
|
+
children: [...parentNode.children, node.id]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Removes a node from the tree
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
export const removeNodeFromTree = ({
|
|
91
|
+
node,
|
|
92
|
+
tree,
|
|
93
|
+
treeDepths
|
|
94
|
+
}) => {
|
|
95
|
+
// 1. Remove node from the tree.
|
|
96
|
+
delete tree[node.id]; // 2. Decrement the `treeDepths` object for the node's depth.
|
|
97
|
+
|
|
98
|
+
const nodeDepth = node.depth;
|
|
99
|
+
const currentNodeCount = treeDepths[nodeDepth];
|
|
100
|
+
|
|
101
|
+
if (currentNodeCount === 1) {
|
|
102
|
+
delete treeDepths[nodeDepth];
|
|
103
|
+
} else {
|
|
104
|
+
treeDepths[nodeDepth] = currentNodeCount - 1;
|
|
105
|
+
} // 3. Unregister the new node in its parent.
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
const parentNode = tree[node.parent]; // For footers,
|
|
109
|
+
// Unregister the node from its parent `footerId` property.
|
|
110
|
+
|
|
111
|
+
if (node.type === 'footer') {
|
|
112
|
+
tree[parentNode.id] = _extends({}, parentNode, {
|
|
113
|
+
footerId: null
|
|
114
|
+
});
|
|
115
|
+
} // For groups and leaves,
|
|
116
|
+
// Unregister the node from its parents `children` and `childrenFromPath` properties.
|
|
117
|
+
else {
|
|
118
|
+
var _groupingField2, _groupingKey2, _parentNode$childrenF2, _parentNode$childrenF3;
|
|
119
|
+
|
|
120
|
+
const groupingField = (_groupingField2 = node.groupingField) != null ? _groupingField2 : '__no_field__';
|
|
121
|
+
const groupingKey = (_groupingKey2 = node.groupingKey) != null ? _groupingKey2 : '__no_key__';
|
|
122
|
+
|
|
123
|
+
const _ref = (_parentNode$childrenF2 = (_parentNode$childrenF3 = parentNode.childrenFromPath) == null ? void 0 : _parentNode$childrenF3[groupingField]) != null ? _parentNode$childrenF2 : {},
|
|
124
|
+
_groupingKey$toString = groupingKey.toString(),
|
|
125
|
+
newChildrenFromPathWithField = _objectWithoutPropertiesLoose(_ref, [_groupingKey$toString].map(_toPropertyKey)); // TODO rows v6: Can we avoid this linear complexity ?
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
const children = parentNode.children.filter(childId => childId !== node.id);
|
|
129
|
+
|
|
130
|
+
const childrenFromPath = _extends({}, parentNode.childrenFromPath);
|
|
131
|
+
|
|
132
|
+
if (Object.keys(newChildrenFromPathWithField).length === 0) {
|
|
133
|
+
delete childrenFromPath[groupingField];
|
|
134
|
+
} else {
|
|
135
|
+
childrenFromPath[groupingField] = newChildrenFromPathWithField;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
tree[parentNode.id] = _extends({}, parentNode, {
|
|
139
|
+
children,
|
|
140
|
+
childrenFromPath
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Updates the `id` and `isAutoGenerated` properties of a group node.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
export const updateGroupNodeIdAndAutoGenerated = ({
|
|
149
|
+
node,
|
|
150
|
+
updatedNode,
|
|
151
|
+
tree,
|
|
152
|
+
treeDepths
|
|
153
|
+
}) => {
|
|
154
|
+
// 1. Set the new parent for all children from the old group
|
|
155
|
+
node.children.forEach(childId => {
|
|
156
|
+
tree[childId] = _extends({}, tree[childId], {
|
|
157
|
+
parent: updatedNode.id
|
|
158
|
+
});
|
|
159
|
+
}); // 2. Remove the old group from the tree
|
|
160
|
+
|
|
161
|
+
removeNodeFromTree({
|
|
162
|
+
node,
|
|
163
|
+
tree,
|
|
164
|
+
treeDepths
|
|
165
|
+
}); // 3. Add the new group in the tree
|
|
166
|
+
|
|
167
|
+
const groupNode = _extends({}, node, updatedNode);
|
|
168
|
+
|
|
169
|
+
insertNodeInTree({
|
|
170
|
+
node: groupNode,
|
|
171
|
+
tree,
|
|
172
|
+
treeDepths
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
export const createUpdatedGroupsManager = () => ({
|
|
176
|
+
value: {},
|
|
177
|
+
|
|
178
|
+
addAction(groupId, action) {
|
|
179
|
+
if (!this.value[groupId]) {
|
|
180
|
+
this.value[groupId] = {};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
this.value[groupId][action] = true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
});
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
-
export var getGroupRowIdFromPath = function getGroupRowIdFromPath(path) {
|
|
4
|
-
var pathStr = path.map(function (groupingCriteria) {
|
|
5
|
-
return "".concat(groupingCriteria.field, "/").concat(groupingCriteria.key);
|
|
6
|
-
}).join('-');
|
|
7
|
-
return "auto-generated-row-".concat(pathStr);
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Transform a list of rows into a tree structure where each row references its parent and children.
|
|
11
|
-
* If a row have a parent which does not exist in the input rows, creates an auto generated row
|
|
12
|
-
*
|
|
13
|
-
```
|
|
14
|
-
params = {
|
|
15
|
-
ids: [0, 1, 2],
|
|
16
|
-
idRowsLookup: { 0: {...}, 1: {...}, 2: {...} },
|
|
17
|
-
rows: [
|
|
18
|
-
{ id: 0, path: ['A'] },
|
|
19
|
-
{ id: 1, path: ['B', 'A'] },
|
|
20
|
-
{ id: 2, path: ['B', 'A', 'A'] }
|
|
21
|
-
],
|
|
22
|
-
defaultGroupingExpansionDepth: 0,
|
|
23
|
-
}
|
|
24
|
-
Returns:
|
|
25
|
-
{
|
|
26
|
-
ids: [0, 1, 2, 'auto-generated-row-B'],
|
|
27
|
-
idRowsLookup: { 0: {...}, 1: {...}, 2: {...}, 'auto-generated-row-B': {} },
|
|
28
|
-
tree: {
|
|
29
|
-
'0': { id: 0, parent: null, childrenExpanded: false, depth: 0, groupingKey: 'A' },
|
|
30
|
-
'auto-generated-row-B': { id: 'auto-generated-row-B', parent: null, childrenExpanded: false, depth: 0, groupingKey: 'B' },
|
|
31
|
-
'1': { id: 1, parent: 'auto-generated-row-B', childrenExpanded: false, depth: 1, groupingKey: 'A' },
|
|
32
|
-
'2': { id: 2, parent: 1, childrenExpanded: false, depth: 2, groupingKey: 'A' },
|
|
33
|
-
},
|
|
34
|
-
treeDepth: 3,
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
export var buildRowTree = function buildRowTree(params) {
|
|
40
|
-
// During the build, we store the children as a Record to avoid linear complexity when checking if a children is already defined.
|
|
41
|
-
var tempTree = {};
|
|
42
|
-
var treeDepth = 1;
|
|
43
|
-
|
|
44
|
-
var ids = _toConsumableArray(params.ids);
|
|
45
|
-
|
|
46
|
-
var idRowsLookup = _extends({}, params.idRowsLookup);
|
|
47
|
-
|
|
48
|
-
var idToIdLookup = _extends({}, params.idToIdLookup);
|
|
49
|
-
|
|
50
|
-
var groupingCriteriaToIdTree = {};
|
|
51
|
-
|
|
52
|
-
var isGroupExpandedByDefault = function isGroupExpandedByDefault(node) {
|
|
53
|
-
var _params$previousTree, _params$previousTree$;
|
|
54
|
-
|
|
55
|
-
var previousExpansion = (_params$previousTree = params.previousTree) == null ? void 0 : (_params$previousTree$ = _params$previousTree[node.id]) == null ? void 0 : _params$previousTree$.childrenExpanded;
|
|
56
|
-
|
|
57
|
-
if (previousExpansion != null) {
|
|
58
|
-
return previousExpansion;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!node.children || !node.children.length) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (params.isGroupExpandedByDefault) {
|
|
66
|
-
return params.isGroupExpandedByDefault(node);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return params.defaultGroupingExpansionDepth === -1 || params.defaultGroupingExpansionDepth > node.depth;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
for (var i = 0; i < params.rows.length; i += 1) {
|
|
73
|
-
var row = params.rows[i];
|
|
74
|
-
var keyToIdSubTree = groupingCriteriaToIdTree;
|
|
75
|
-
var parentNode = null;
|
|
76
|
-
|
|
77
|
-
for (var depth = 0; depth < row.path.length; depth += 1) {
|
|
78
|
-
var _row$path$depth = row.path[depth],
|
|
79
|
-
_key = _row$path$depth.key,
|
|
80
|
-
rawField = _row$path$depth.field;
|
|
81
|
-
|
|
82
|
-
var _field = rawField != null ? rawField : '__no_field__';
|
|
83
|
-
|
|
84
|
-
var nodeId = void 0;
|
|
85
|
-
var fieldSubTree = keyToIdSubTree[_field];
|
|
86
|
-
|
|
87
|
-
if (!fieldSubTree) {
|
|
88
|
-
fieldSubTree = {};
|
|
89
|
-
keyToIdSubTree[_field] = fieldSubTree;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
var keyConfig = fieldSubTree[_key.toString()];
|
|
93
|
-
|
|
94
|
-
if (keyConfig) {
|
|
95
|
-
if (depth === row.path.length - 1) {
|
|
96
|
-
var _params$onDuplicatePa;
|
|
97
|
-
|
|
98
|
-
(_params$onDuplicatePa = params.onDuplicatePath) == null ? void 0 : _params$onDuplicatePa.call(params, keyConfig.id, row.id, row.path);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
nodeId = keyConfig.id;
|
|
102
|
-
} else {
|
|
103
|
-
if (depth === row.path.length - 1) {
|
|
104
|
-
nodeId = row.id;
|
|
105
|
-
} else {
|
|
106
|
-
nodeId = getGroupRowIdFromPath(row.path.slice(0, depth + 1));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
keyConfig = {
|
|
110
|
-
id: nodeId,
|
|
111
|
-
children: {}
|
|
112
|
-
};
|
|
113
|
-
fieldSubTree[_key.toString()] = keyConfig;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
keyToIdSubTree = keyConfig.children;
|
|
117
|
-
|
|
118
|
-
if (!tempTree[nodeId]) {
|
|
119
|
-
var _parentNode$id, _parentNode;
|
|
120
|
-
|
|
121
|
-
var isAutoGenerated = depth < row.path.length - 1;
|
|
122
|
-
var _node = {
|
|
123
|
-
id: nodeId,
|
|
124
|
-
isAutoGenerated: isAutoGenerated,
|
|
125
|
-
parent: (_parentNode$id = (_parentNode = parentNode) == null ? void 0 : _parentNode.id) != null ? _parentNode$id : null,
|
|
126
|
-
groupingKey: _key,
|
|
127
|
-
groupingField: rawField,
|
|
128
|
-
depth: depth
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
if (isAutoGenerated) {
|
|
132
|
-
idRowsLookup[nodeId] = {};
|
|
133
|
-
ids.push(nodeId);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
tempTree[nodeId] = _node;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (parentNode != null) {
|
|
140
|
-
if (!parentNode.children) {
|
|
141
|
-
parentNode.children = {};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
parentNode.children[nodeId] = nodeId;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
parentNode = tempTree[nodeId];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
treeDepth = Math.max(treeDepth, row.path.length);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
var tree = {};
|
|
154
|
-
|
|
155
|
-
var _loop = function _loop(_i) {
|
|
156
|
-
var _params$previousTree2, _previousNode$childre, _node$children, _previousNode$childre2;
|
|
157
|
-
|
|
158
|
-
var rowId = ids[_i];
|
|
159
|
-
var tempNode = tempTree[rowId];
|
|
160
|
-
|
|
161
|
-
var nodeWithoutChildrenExpansion = _extends({}, tempNode, {
|
|
162
|
-
children: tempNode.children ? Object.values(tempNode.children) : undefined
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
var node = _extends({}, nodeWithoutChildrenExpansion, {
|
|
166
|
-
childrenExpanded: isGroupExpandedByDefault(nodeWithoutChildrenExpansion)
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
var previousNode = (_params$previousTree2 = params.previousTree) == null ? void 0 : _params$previousTree2[node.id];
|
|
170
|
-
var shouldReUsePreviousNode = previousNode && previousNode.isAutoGenerated === node.isAutoGenerated && previousNode.parent === node.parent && previousNode.groupingKey === node.groupingKey && previousNode.groupingField === node.groupingField && previousNode.depth === node.depth && previousNode.childrenExpanded === node.childrenExpanded && ((_previousNode$childre = previousNode.children) == null ? void 0 : _previousNode$childre.length) === ((_node$children = node.children) == null ? void 0 : _node$children.length) && ((_previousNode$childre2 = previousNode.children) == null ? void 0 : _previousNode$childre2.every(function (childId, index) {
|
|
171
|
-
var _node$children2;
|
|
172
|
-
|
|
173
|
-
return ((_node$children2 = node.children) == null ? void 0 : _node$children2[index]) === childId;
|
|
174
|
-
}));
|
|
175
|
-
|
|
176
|
-
if (shouldReUsePreviousNode) {
|
|
177
|
-
tree[rowId] = previousNode;
|
|
178
|
-
} else {
|
|
179
|
-
tree[rowId] = node;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
for (var _i = 0; _i < ids.length; _i += 1) {
|
|
184
|
-
_loop(_i);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
tree: tree,
|
|
189
|
-
treeDepth: treeDepth,
|
|
190
|
-
ids: ids,
|
|
191
|
-
idRowsLookup: idRowsLookup,
|
|
192
|
-
idToIdLookup: idToIdLookup,
|
|
193
|
-
groupingName: params.groupingName
|
|
194
|
-
};
|
|
195
|
-
};
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
export const getGroupRowIdFromPath = path => {
|
|
3
|
-
const pathStr = path.map(groupingCriteria => `${groupingCriteria.field}/${groupingCriteria.key}`).join('-');
|
|
4
|
-
return `auto-generated-row-${pathStr}`;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Transform a list of rows into a tree structure where each row references its parent and children.
|
|
8
|
-
* If a row have a parent which does not exist in the input rows, creates an auto generated row
|
|
9
|
-
*
|
|
10
|
-
```
|
|
11
|
-
params = {
|
|
12
|
-
ids: [0, 1, 2],
|
|
13
|
-
idRowsLookup: { 0: {...}, 1: {...}, 2: {...} },
|
|
14
|
-
rows: [
|
|
15
|
-
{ id: 0, path: ['A'] },
|
|
16
|
-
{ id: 1, path: ['B', 'A'] },
|
|
17
|
-
{ id: 2, path: ['B', 'A', 'A'] }
|
|
18
|
-
],
|
|
19
|
-
defaultGroupingExpansionDepth: 0,
|
|
20
|
-
}
|
|
21
|
-
Returns:
|
|
22
|
-
{
|
|
23
|
-
ids: [0, 1, 2, 'auto-generated-row-B'],
|
|
24
|
-
idRowsLookup: { 0: {...}, 1: {...}, 2: {...}, 'auto-generated-row-B': {} },
|
|
25
|
-
tree: {
|
|
26
|
-
'0': { id: 0, parent: null, childrenExpanded: false, depth: 0, groupingKey: 'A' },
|
|
27
|
-
'auto-generated-row-B': { id: 'auto-generated-row-B', parent: null, childrenExpanded: false, depth: 0, groupingKey: 'B' },
|
|
28
|
-
'1': { id: 1, parent: 'auto-generated-row-B', childrenExpanded: false, depth: 1, groupingKey: 'A' },
|
|
29
|
-
'2': { id: 2, parent: 1, childrenExpanded: false, depth: 2, groupingKey: 'A' },
|
|
30
|
-
},
|
|
31
|
-
treeDepth: 3,
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
export const buildRowTree = params => {
|
|
37
|
-
// During the build, we store the children as a Record to avoid linear complexity when checking if a children is already defined.
|
|
38
|
-
const tempTree = {};
|
|
39
|
-
let treeDepth = 1;
|
|
40
|
-
const ids = [...params.ids];
|
|
41
|
-
|
|
42
|
-
const idRowsLookup = _extends({}, params.idRowsLookup);
|
|
43
|
-
|
|
44
|
-
const idToIdLookup = _extends({}, params.idToIdLookup);
|
|
45
|
-
|
|
46
|
-
const groupingCriteriaToIdTree = {};
|
|
47
|
-
|
|
48
|
-
const isGroupExpandedByDefault = node => {
|
|
49
|
-
const previousExpansion = params.previousTree?.[node.id]?.childrenExpanded;
|
|
50
|
-
|
|
51
|
-
if (previousExpansion != null) {
|
|
52
|
-
return previousExpansion;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!node.children || !node.children.length) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (params.isGroupExpandedByDefault) {
|
|
60
|
-
return params.isGroupExpandedByDefault(node);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return params.defaultGroupingExpansionDepth === -1 || params.defaultGroupingExpansionDepth > node.depth;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
for (let i = 0; i < params.rows.length; i += 1) {
|
|
67
|
-
const row = params.rows[i];
|
|
68
|
-
let keyToIdSubTree = groupingCriteriaToIdTree;
|
|
69
|
-
let parentNode = null;
|
|
70
|
-
|
|
71
|
-
for (let depth = 0; depth < row.path.length; depth += 1) {
|
|
72
|
-
const {
|
|
73
|
-
key,
|
|
74
|
-
field: rawField
|
|
75
|
-
} = row.path[depth];
|
|
76
|
-
const field = rawField ?? '__no_field__';
|
|
77
|
-
let nodeId;
|
|
78
|
-
let fieldSubTree = keyToIdSubTree[field];
|
|
79
|
-
|
|
80
|
-
if (!fieldSubTree) {
|
|
81
|
-
fieldSubTree = {};
|
|
82
|
-
keyToIdSubTree[field] = fieldSubTree;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let keyConfig = fieldSubTree[key.toString()];
|
|
86
|
-
|
|
87
|
-
if (keyConfig) {
|
|
88
|
-
if (depth === row.path.length - 1) {
|
|
89
|
-
params.onDuplicatePath?.(keyConfig.id, row.id, row.path);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
nodeId = keyConfig.id;
|
|
93
|
-
} else {
|
|
94
|
-
if (depth === row.path.length - 1) {
|
|
95
|
-
nodeId = row.id;
|
|
96
|
-
} else {
|
|
97
|
-
nodeId = getGroupRowIdFromPath(row.path.slice(0, depth + 1));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
keyConfig = {
|
|
101
|
-
id: nodeId,
|
|
102
|
-
children: {}
|
|
103
|
-
};
|
|
104
|
-
fieldSubTree[key.toString()] = keyConfig;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
keyToIdSubTree = keyConfig.children;
|
|
108
|
-
|
|
109
|
-
if (!tempTree[nodeId]) {
|
|
110
|
-
const isAutoGenerated = depth < row.path.length - 1;
|
|
111
|
-
const node = {
|
|
112
|
-
id: nodeId,
|
|
113
|
-
isAutoGenerated,
|
|
114
|
-
parent: parentNode?.id ?? null,
|
|
115
|
-
groupingKey: key,
|
|
116
|
-
groupingField: rawField,
|
|
117
|
-
depth
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (isAutoGenerated) {
|
|
121
|
-
idRowsLookup[nodeId] = {};
|
|
122
|
-
ids.push(nodeId);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
tempTree[nodeId] = node;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (parentNode != null) {
|
|
129
|
-
if (!parentNode.children) {
|
|
130
|
-
parentNode.children = {};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
parentNode.children[nodeId] = nodeId;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
parentNode = tempTree[nodeId];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
treeDepth = Math.max(treeDepth, row.path.length);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const tree = {};
|
|
143
|
-
|
|
144
|
-
for (let i = 0; i < ids.length; i += 1) {
|
|
145
|
-
const rowId = ids[i];
|
|
146
|
-
const tempNode = tempTree[rowId];
|
|
147
|
-
|
|
148
|
-
const nodeWithoutChildrenExpansion = _extends({}, tempNode, {
|
|
149
|
-
children: tempNode.children ? Object.values(tempNode.children) : undefined
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const node = _extends({}, nodeWithoutChildrenExpansion, {
|
|
153
|
-
childrenExpanded: isGroupExpandedByDefault(nodeWithoutChildrenExpansion)
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const previousNode = params.previousTree?.[node.id];
|
|
157
|
-
const shouldReUsePreviousNode = previousNode && previousNode.isAutoGenerated === node.isAutoGenerated && previousNode.parent === node.parent && previousNode.groupingKey === node.groupingKey && previousNode.groupingField === node.groupingField && previousNode.depth === node.depth && previousNode.childrenExpanded === node.childrenExpanded && previousNode.children?.length === node.children?.length && previousNode.children?.every((childId, index) => node.children?.[index] === childId);
|
|
158
|
-
|
|
159
|
-
if (shouldReUsePreviousNode) {
|
|
160
|
-
tree[rowId] = previousNode;
|
|
161
|
-
} else {
|
|
162
|
-
tree[rowId] = node;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
tree,
|
|
168
|
-
treeDepth,
|
|
169
|
-
ids,
|
|
170
|
-
idRowsLookup,
|
|
171
|
-
idToIdLookup,
|
|
172
|
-
groupingName: params.groupingName
|
|
173
|
-
};
|
|
174
|
-
};
|