@mui/x-data-grid 6.0.0-alpha.0 → 6.0.0-alpha.2
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 +209 -0
- package/DataGrid/useDataGridProps.js +4 -4
- package/components/DataGridVirtualScroller.js +5 -3
- package/components/GridPagination.d.ts +43 -1
- package/components/GridPagination.js +1 -2
- package/components/GridRow.d.ts +1 -4
- package/components/GridRow.js +9 -8
- package/components/base/GridBody.js +1 -2
- package/components/base/GridOverlays.js +52 -12
- package/components/cell/GridBooleanCell.js +2 -1
- package/components/columnSelection/GridCellCheckboxRenderer.d.ts +2 -2
- package/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
- package/components/containers/GridOverlay.js +0 -5
- package/components/panel/filterPanel/GridFilterForm.js +2 -1
- package/components/toolbar/GridToolbarFilterButton.js +8 -4
- package/constants/gridClasses.d.ts +8 -0
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +1 -1
- package/hooks/core/strategyProcessing/gridStrategyProcessingApi.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/hooks/features/editRows/useGridCellEditing.new.js +18 -9
- package/hooks/features/editRows/useGridEditing.new.js +3 -2
- package/hooks/features/editRows/useGridEditing.old.js +2 -1
- package/hooks/features/editRows/useGridRowEditing.new.js +18 -9
- package/hooks/features/export/useGridPrintExport.js +31 -17
- package/hooks/features/export/utils.js +1 -5
- package/hooks/features/filter/gridFilterSelector.js +2 -2
- package/hooks/features/filter/useGridFilter.js +6 -6
- package/hooks/features/pagination/gridPaginationSelector.js +2 -2
- package/hooks/features/rows/gridRowsInterfaces.d.ts +106 -0
- package/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
- package/hooks/features/rows/gridRowsSelector.d.ts +17 -7
- package/hooks/features/rows/gridRowsSelector.js +38 -6
- package/hooks/features/rows/gridRowsUtils.d.ts +16 -4
- package/hooks/features/rows/gridRowsUtils.js +222 -39
- package/hooks/features/rows/index.d.ts +3 -3
- package/hooks/features/rows/index.js +2 -2
- package/hooks/features/rows/useGridRows.js +161 -124
- package/hooks/features/rows/useGridRowsPreProcessors.js +78 -26
- package/hooks/features/selection/useGridSelection.js +2 -2
- package/hooks/features/sorting/gridSortingSelector.js +9 -4
- package/hooks/features/sorting/gridSortingState.d.ts +2 -2
- package/hooks/features/sorting/useGridSorting.js +9 -33
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +4 -7
- package/hooks/features/virtualization/useGridVirtualScroller.js +11 -17
- package/index.js +1 -1
- package/internals/index.d.ts +2 -1
- package/internals/index.js +1 -0
- package/legacy/DataGrid/useDataGridProps.js +4 -4
- package/legacy/components/DataGridVirtualScroller.js +5 -3
- package/legacy/components/GridPagination.js +1 -2
- package/legacy/components/GridRow.js +9 -8
- package/legacy/components/base/GridBody.js +1 -2
- package/legacy/components/base/GridOverlays.js +54 -12
- package/legacy/components/cell/GridBooleanCell.js +2 -1
- package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
- package/legacy/components/containers/GridOverlay.js +0 -5
- package/legacy/components/panel/filterPanel/GridFilterForm.js +2 -1
- package/legacy/components/toolbar/GridToolbarFilterButton.js +3 -1
- package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/legacy/hooks/features/editRows/useGridCellEditing.new.js +18 -9
- package/legacy/hooks/features/editRows/useGridEditing.new.js +3 -2
- package/legacy/hooks/features/editRows/useGridEditing.old.js +2 -1
- package/legacy/hooks/features/editRows/useGridRowEditing.new.js +18 -9
- package/legacy/hooks/features/export/useGridPrintExport.js +33 -20
- package/legacy/hooks/features/export/utils.js +1 -3
- package/legacy/hooks/features/filter/gridFilterSelector.js +2 -2
- package/legacy/hooks/features/filter/useGridFilter.js +6 -6
- package/legacy/hooks/features/pagination/gridPaginationSelector.js +2 -2
- package/legacy/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
- package/legacy/hooks/features/rows/gridRowsSelector.js +52 -9
- package/legacy/hooks/features/rows/gridRowsUtils.js +238 -46
- package/legacy/hooks/features/rows/index.js +2 -2
- package/legacy/hooks/features/rows/useGridRows.js +163 -134
- package/legacy/hooks/features/rows/useGridRowsPreProcessors.js +81 -26
- package/legacy/hooks/features/selection/useGridSelection.js +2 -2
- package/legacy/hooks/features/sorting/gridSortingSelector.js +5 -2
- package/legacy/hooks/features/sorting/useGridSorting.js +11 -33
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +11 -17
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +1 -0
- package/legacy/models/gridFeatureMode.js +1 -4
- package/models/api/gridParamsApi.d.ts +2 -2
- package/models/api/gridRowApi.d.ts +7 -5
- package/models/events/gridEventLookup.d.ts +3 -3
- package/models/gridApiCaches.d.ts +1 -1
- package/models/gridFeatureMode.d.ts +0 -4
- package/models/gridFeatureMode.js +1 -4
- package/models/gridRows.d.ts +100 -30
- package/models/gridSortModel.d.ts +2 -2
- package/models/params/gridCellParams.d.ts +7 -11
- package/modern/DataGrid/useDataGridProps.js +4 -4
- package/modern/components/DataGridVirtualScroller.js +5 -3
- package/modern/components/GridPagination.js +1 -2
- package/modern/components/GridRow.js +9 -8
- package/modern/components/base/GridBody.js +1 -2
- package/modern/components/base/GridOverlays.js +52 -12
- package/modern/components/cell/GridBooleanCell.js +2 -1
- package/modern/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
- package/modern/components/containers/GridOverlay.js +0 -5
- package/modern/components/panel/filterPanel/GridFilterForm.js +2 -1
- package/modern/components/toolbar/GridToolbarFilterButton.js +1 -1
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/modern/hooks/features/editRows/useGridCellEditing.new.js +18 -9
- package/modern/hooks/features/editRows/useGridEditing.new.js +3 -2
- package/modern/hooks/features/editRows/useGridEditing.old.js +2 -1
- package/modern/hooks/features/editRows/useGridRowEditing.new.js +18 -9
- package/modern/hooks/features/export/useGridPrintExport.js +30 -16
- package/modern/hooks/features/export/utils.js +1 -1
- package/modern/hooks/features/filter/gridFilterSelector.js +2 -2
- package/modern/hooks/features/filter/useGridFilter.js +6 -6
- package/modern/hooks/features/pagination/gridPaginationSelector.js +2 -2
- package/modern/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
- package/modern/hooks/features/rows/gridRowsSelector.js +28 -6
- package/modern/hooks/features/rows/gridRowsUtils.js +220 -37
- package/modern/hooks/features/rows/index.js +2 -2
- package/modern/hooks/features/rows/useGridRows.js +158 -121
- package/modern/hooks/features/rows/useGridRowsPreProcessors.js +78 -26
- package/modern/hooks/features/selection/useGridSelection.js +2 -2
- package/modern/hooks/features/sorting/gridSortingSelector.js +3 -2
- package/modern/hooks/features/sorting/useGridSorting.js +9 -33
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +10 -16
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -0
- package/modern/models/gridFeatureMode.js +1 -4
- package/node/DataGrid/useDataGridProps.js +3 -3
- package/node/components/DataGridVirtualScroller.js +5 -3
- package/node/components/GridPagination.js +1 -2
- package/node/components/GridRow.js +9 -7
- package/node/components/base/GridBody.js +1 -3
- package/node/components/base/GridOverlays.js +57 -12
- package/node/components/cell/GridBooleanCell.js +3 -1
- package/node/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
- package/node/components/containers/GridOverlay.js +0 -5
- package/node/components/panel/filterPanel/GridFilterForm.js +2 -1
- package/node/components/toolbar/GridToolbarFilterButton.js +8 -4
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/node/hooks/features/editRows/useGridCellEditing.new.js +20 -10
- package/node/hooks/features/editRows/useGridEditing.new.js +4 -2
- package/node/hooks/features/editRows/useGridEditing.old.js +3 -1
- package/node/hooks/features/editRows/useGridRowEditing.new.js +20 -10
- package/node/hooks/features/export/useGridPrintExport.js +31 -17
- package/node/hooks/features/export/utils.js +1 -5
- package/node/hooks/features/filter/gridFilterSelector.js +1 -1
- package/node/hooks/features/filter/useGridFilter.js +5 -6
- package/node/hooks/features/pagination/gridPaginationSelector.js +1 -1
- package/node/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
- package/node/hooks/features/rows/gridRowsSelector.js +43 -10
- package/node/hooks/features/rows/gridRowsUtils.js +239 -40
- package/node/hooks/features/rows/index.js +23 -9
- package/node/hooks/features/rows/useGridRows.js +161 -122
- package/node/hooks/features/rows/useGridRowsPreProcessors.js +81 -26
- package/node/hooks/features/selection/useGridSelection.js +2 -2
- package/node/hooks/features/sorting/gridSortingSelector.js +9 -4
- package/node/hooks/features/sorting/useGridSorting.js +9 -33
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +11 -17
- package/node/index.js +1 -1
- package/node/internals/index.js +14 -2
- package/node/models/gridFeatureMode.js +1 -7
- package/package.json +1 -1
- package/themeAugmentation/props.d.ts +2 -2
- package/hooks/features/rows/gridRowsState.d.ts +0 -60
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
4
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
7
7
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
8
|
-
import { gridRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector,
|
|
8
|
+
import { gridRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowGroupingNameSelector, gridRowTreeDepthsSelector, gridDataRowIdsSelector, gridRowsDataRowIdToIdLookupSelector, gridRowMaximumTreeDepthSelector } from './gridRowsSelector';
|
|
9
9
|
import { GridSignature, useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
10
10
|
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
11
11
|
import { gridSortedRowIdsSelector } from '../sorting/gridSortingSelector';
|
|
12
12
|
import { gridFilteredRowsLookupSelector } from '../filter/gridFilterSelector';
|
|
13
|
-
import { getTreeNodeDescendants, createRowsInternalCache, getRowsStateFromCache, getRowIdFromRowModel } from './gridRowsUtils';
|
|
13
|
+
import { getTreeNodeDescendants, createRowsInternalCache, getRowsStateFromCache, isAutoGeneratedRow, GRID_ROOT_GROUP_ID, updateCacheWithNewRows, getTopLevelRowCount, getRowIdFromRowModel } from './gridRowsUtils';
|
|
14
14
|
import { useGridRegisterPipeApplier } from '../../core/pipeProcessing';
|
|
15
15
|
export var rowsStateInitializer = function rowsStateInitializer(state, props, apiRef) {
|
|
16
16
|
apiRef.current.unstable_caches.rows = createRowsInternalCache({
|
|
@@ -21,9 +21,10 @@ export var rowsStateInitializer = function rowsStateInitializer(state, props, ap
|
|
|
21
21
|
return _extends({}, state, {
|
|
22
22
|
rows: getRowsStateFromCache({
|
|
23
23
|
apiRef: apiRef,
|
|
24
|
-
previousTree: null,
|
|
25
24
|
rowCountProp: props.rowCount,
|
|
26
|
-
loadingProp: props.loading
|
|
25
|
+
loadingProp: props.loading,
|
|
26
|
+
previousTree: null,
|
|
27
|
+
previousTreeDepths: null
|
|
27
28
|
})
|
|
28
29
|
});
|
|
29
30
|
};
|
|
@@ -41,18 +42,32 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
41
42
|
var lastUpdateMs = React.useRef(Date.now());
|
|
42
43
|
var timeout = React.useRef(null);
|
|
43
44
|
var getRow = React.useCallback(function (id) {
|
|
44
|
-
var
|
|
45
|
+
var model = gridRowsLookupSelector(apiRef)[id];
|
|
46
|
+
|
|
47
|
+
if (model) {
|
|
48
|
+
return model;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var node = apiRef.current.getRowNode(id);
|
|
52
|
+
|
|
53
|
+
if (node && isAutoGeneratedRow(node)) {
|
|
54
|
+
// TODO rows v6: Is it the best approach ?
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
45
57
|
|
|
46
|
-
return
|
|
58
|
+
return null;
|
|
47
59
|
}, [apiRef]);
|
|
48
60
|
var lookup = React.useMemo(function () {
|
|
49
|
-
return currentPage.rows.reduce(function (acc,
|
|
50
|
-
var id =
|
|
61
|
+
return currentPage.rows.reduce(function (acc, _ref, index) {
|
|
62
|
+
var id = _ref.id;
|
|
51
63
|
acc[id] = index;
|
|
52
64
|
return acc;
|
|
53
65
|
}, {});
|
|
54
66
|
}, [currentPage.rows]);
|
|
55
|
-
var throttledRowsChange = React.useCallback(function (
|
|
67
|
+
var throttledRowsChange = React.useCallback(function (_ref2) {
|
|
68
|
+
var cache = _ref2.cache,
|
|
69
|
+
throttle = _ref2.throttle;
|
|
70
|
+
|
|
56
71
|
var run = function run() {
|
|
57
72
|
timeout.current = null;
|
|
58
73
|
lastUpdateMs.current = Date.now();
|
|
@@ -60,9 +75,10 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
60
75
|
return _extends({}, state, {
|
|
61
76
|
rows: getRowsStateFromCache({
|
|
62
77
|
apiRef: apiRef,
|
|
63
|
-
previousTree: gridRowTreeSelector(apiRef),
|
|
64
78
|
rowCountProp: props.rowCount,
|
|
65
|
-
loadingProp: props.loading
|
|
79
|
+
loadingProp: props.loading,
|
|
80
|
+
previousTree: gridRowTreeSelector(apiRef),
|
|
81
|
+
previousTreeDepths: gridRowTreeDepthsSelector(apiRef)
|
|
66
82
|
})
|
|
67
83
|
});
|
|
68
84
|
});
|
|
@@ -75,7 +91,7 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
75
91
|
timeout.current = null;
|
|
76
92
|
}
|
|
77
93
|
|
|
78
|
-
apiRef.current.unstable_caches.rows =
|
|
94
|
+
apiRef.current.unstable_caches.rows = cache;
|
|
79
95
|
|
|
80
96
|
if (!throttle) {
|
|
81
97
|
run();
|
|
@@ -97,79 +113,45 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
97
113
|
|
|
98
114
|
var setRows = React.useCallback(function (rows) {
|
|
99
115
|
logger.debug("Updating all rows, new length ".concat(rows.length));
|
|
100
|
-
throttledRowsChange(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
throttledRowsChange({
|
|
117
|
+
cache: createRowsInternalCache({
|
|
118
|
+
rows: rows,
|
|
119
|
+
getRowId: props.getRowId,
|
|
120
|
+
loading: props.loading
|
|
121
|
+
}),
|
|
122
|
+
throttle: true
|
|
123
|
+
});
|
|
105
124
|
}, [logger, props.getRowId, props.loading, throttledRowsChange]);
|
|
106
125
|
var updateRows = React.useCallback(function (updates) {
|
|
107
126
|
if (props.signature === GridSignature.DataGrid && updates.length > 1) {
|
|
108
127
|
// TODO: Add test with direct call to `apiRef.current.updateRows` in DataGrid after enabling the `apiRef` on the free plan.
|
|
109
128
|
throw new Error(["MUI: You can't update several rows at once in `apiRef.current.updateRows` on the DataGrid.", 'You need to upgrade to DataGridPro or DataGridPremium component to unlock this feature.'].join('\n'));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
var uniqueUpdates = new Map();
|
|
114
|
-
updates.forEach(function (update) {
|
|
115
|
-
var id = getRowIdFromRowModel(update, props.getRowId, 'A row was provided without id when calling updateRows():');
|
|
129
|
+
}
|
|
116
130
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
131
|
+
var cache = updateCacheWithNewRows({
|
|
132
|
+
updates: updates,
|
|
133
|
+
getRowId: props.getRowId,
|
|
134
|
+
previousCache: apiRef.current.unstable_caches.rows
|
|
122
135
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
rowsBeforePartialUpdates: prevCache.rowsBeforePartialUpdates,
|
|
127
|
-
loadingPropBeforePartialUpdates: prevCache.loadingPropBeforePartialUpdates,
|
|
128
|
-
idRowsLookup: _extends({}, prevCache.idRowsLookup),
|
|
129
|
-
idToIdLookup: _extends({}, prevCache.idToIdLookup),
|
|
130
|
-
ids: _toConsumableArray(prevCache.ids)
|
|
131
|
-
};
|
|
132
|
-
uniqueUpdates.forEach(function (partialRow, id) {
|
|
133
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
134
|
-
if (partialRow._action === 'delete') {
|
|
135
|
-
delete newCache.idRowsLookup[id];
|
|
136
|
-
delete newCache.idToIdLookup[id];
|
|
137
|
-
deletedRowIds.push(id);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
var oldRow = apiRef.current.getRow(id);
|
|
142
|
-
|
|
143
|
-
if (!oldRow) {
|
|
144
|
-
newCache.idRowsLookup[id] = partialRow;
|
|
145
|
-
newCache.idToIdLookup[id] = id;
|
|
146
|
-
newCache.ids.push(id);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
newCache.idRowsLookup[id] = _extends({}, apiRef.current.getRow(id), partialRow);
|
|
136
|
+
throttledRowsChange({
|
|
137
|
+
cache: cache,
|
|
138
|
+
throttle: true
|
|
151
139
|
});
|
|
152
|
-
|
|
153
|
-
if (deletedRowIds.length > 0) {
|
|
154
|
-
newCache.ids = newCache.ids.filter(function (id) {
|
|
155
|
-
return !deletedRowIds.includes(id);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
throttledRowsChange(newCache, true);
|
|
160
140
|
}, [props.signature, props.getRowId, throttledRowsChange, apiRef]);
|
|
161
141
|
var getRowModels = React.useCallback(function () {
|
|
162
|
-
var
|
|
142
|
+
var dataRows = gridDataRowIdsSelector(apiRef);
|
|
163
143
|
var idRowsLookup = gridRowsLookupSelector(apiRef);
|
|
164
|
-
return new Map(
|
|
165
|
-
|
|
144
|
+
return new Map(dataRows.map(function (id) {
|
|
145
|
+
var _idRowsLookup$id;
|
|
146
|
+
|
|
147
|
+
return [id, (_idRowsLookup$id = idRowsLookup[id]) != null ? _idRowsLookup$id : {}];
|
|
166
148
|
}));
|
|
167
149
|
}, [apiRef]);
|
|
168
150
|
var getRowsCount = React.useCallback(function () {
|
|
169
151
|
return gridRowCountSelector(apiRef);
|
|
170
152
|
}, [apiRef]);
|
|
171
153
|
var getAllRowIds = React.useCallback(function () {
|
|
172
|
-
return
|
|
154
|
+
return gridDataRowIdsSelector(apiRef);
|
|
173
155
|
}, [apiRef]);
|
|
174
156
|
var getRowIndexRelativeToVisibleRows = React.useCallback(function (id) {
|
|
175
157
|
return lookup[id];
|
|
@@ -181,6 +163,10 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
181
163
|
throw new Error("MUI: No row with id #".concat(id, " found"));
|
|
182
164
|
}
|
|
183
165
|
|
|
166
|
+
if (currentNode.type !== 'group') {
|
|
167
|
+
throw new Error('MUI: Only group nodes can be expanded or collapsed');
|
|
168
|
+
}
|
|
169
|
+
|
|
184
170
|
var newNode = _extends({}, currentNode, {
|
|
185
171
|
childrenExpanded: isExpanded
|
|
186
172
|
});
|
|
@@ -196,16 +182,16 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
196
182
|
apiRef.current.publishEvent('rowExpansionChange', newNode);
|
|
197
183
|
}, [apiRef]);
|
|
198
184
|
var getRowNode = React.useCallback(function (id) {
|
|
199
|
-
var
|
|
185
|
+
var _ref3;
|
|
200
186
|
|
|
201
|
-
return (
|
|
187
|
+
return (_ref3 = gridRowTreeSelector(apiRef)[id]) != null ? _ref3 : null;
|
|
202
188
|
}, [apiRef]);
|
|
203
|
-
var getRowGroupChildren = React.useCallback(function (
|
|
204
|
-
var
|
|
205
|
-
skipAutoGeneratedRows =
|
|
206
|
-
groupId =
|
|
207
|
-
applySorting =
|
|
208
|
-
applyFiltering =
|
|
189
|
+
var getRowGroupChildren = React.useCallback(function (_ref4) {
|
|
190
|
+
var _ref4$skipAutoGenerat = _ref4.skipAutoGeneratedRows,
|
|
191
|
+
skipAutoGeneratedRows = _ref4$skipAutoGenerat === void 0 ? true : _ref4$skipAutoGenerat,
|
|
192
|
+
groupId = _ref4.groupId,
|
|
193
|
+
applySorting = _ref4.applySorting,
|
|
194
|
+
applyFiltering = _ref4.applyFiltering;
|
|
209
195
|
var tree = gridRowTreeSelector(apiRef);
|
|
210
196
|
var children;
|
|
211
197
|
|
|
@@ -224,9 +210,8 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
224
210
|
|
|
225
211
|
for (var index = startIndex; index < sortedRowIds.length && tree[sortedRowIds[index]].depth > groupNode.depth; index += 1) {
|
|
226
212
|
var id = sortedRowIds[index];
|
|
227
|
-
var node = tree[id];
|
|
228
213
|
|
|
229
|
-
if (!skipAutoGeneratedRows || !
|
|
214
|
+
if (!skipAutoGeneratedRows || !isAutoGeneratedRow(tree[id])) {
|
|
230
215
|
children.push(id);
|
|
231
216
|
}
|
|
232
217
|
}
|
|
@@ -244,24 +229,41 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
244
229
|
return children;
|
|
245
230
|
}, [apiRef]);
|
|
246
231
|
var setRowIndex = React.useCallback(function (rowId, targetIndex) {
|
|
247
|
-
var
|
|
248
|
-
var oldIndex = allRows.findIndex(function (row) {
|
|
249
|
-
return row === rowId;
|
|
250
|
-
});
|
|
232
|
+
var node = apiRef.current.getRowNode(rowId);
|
|
251
233
|
|
|
252
|
-
if (
|
|
253
|
-
|
|
234
|
+
if (!node) {
|
|
235
|
+
throw new Error("MUI: No row with id #".concat(rowId, " found"));
|
|
254
236
|
}
|
|
255
237
|
|
|
256
|
-
|
|
238
|
+
if (node.parent !== GRID_ROOT_GROUP_ID) {
|
|
239
|
+
throw new Error("MUI: The row reordering do not support reordering of grouped rows yet");
|
|
240
|
+
}
|
|
257
241
|
|
|
258
|
-
|
|
242
|
+
if (node.type !== 'leaf') {
|
|
243
|
+
throw new Error("MUI: The row reordering do not support reordering of footer or grouping rows");
|
|
244
|
+
}
|
|
259
245
|
|
|
260
|
-
updatedRows.splice(targetIndex, 0, updatedRows.splice(oldIndex, 1)[0]);
|
|
261
246
|
apiRef.current.setState(function (state) {
|
|
247
|
+
var group = gridRowTreeSelector(state, apiRef.current.instanceId)[GRID_ROOT_GROUP_ID];
|
|
248
|
+
var allRows = group.children;
|
|
249
|
+
var oldIndex = allRows.findIndex(function (row) {
|
|
250
|
+
return row === rowId;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
if (oldIndex === -1 || oldIndex === targetIndex) {
|
|
254
|
+
return state;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
logger.debug("Moving row ".concat(rowId, " to index ").concat(targetIndex));
|
|
258
|
+
|
|
259
|
+
var updatedRows = _toConsumableArray(allRows);
|
|
260
|
+
|
|
261
|
+
updatedRows.splice(targetIndex, 0, updatedRows.splice(oldIndex, 1)[0]);
|
|
262
262
|
return _extends({}, state, {
|
|
263
263
|
rows: _extends({}, state.rows, {
|
|
264
|
-
|
|
264
|
+
tree: _extends({}, state.rows.tree, _defineProperty({}, GRID_ROOT_GROUP_ID, _extends({}, group, {
|
|
265
|
+
children: updatedRows
|
|
266
|
+
})))
|
|
265
267
|
})
|
|
266
268
|
});
|
|
267
269
|
});
|
|
@@ -276,55 +278,59 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
276
278
|
return;
|
|
277
279
|
}
|
|
278
280
|
|
|
279
|
-
var
|
|
281
|
+
var treeDepth = gridRowMaximumTreeDepthSelector(apiRef);
|
|
280
282
|
|
|
281
|
-
|
|
283
|
+
if (treeDepth > 1) {
|
|
284
|
+
throw new Error('`apiRef.current.unstable_replaceRows` is not compatible with tree data and row grouping');
|
|
285
|
+
}
|
|
282
286
|
|
|
283
|
-
var
|
|
284
|
-
var idToIdLookup = gridRowsIdToIdLookupSelector(apiRef);
|
|
285
|
-
var tree = gridRowTreeSelector(apiRef);
|
|
287
|
+
var tree = _extends({}, gridRowTreeSelector(apiRef));
|
|
286
288
|
|
|
287
|
-
var
|
|
289
|
+
var dataRowIdToModelLookup = _extends({}, gridRowsLookupSelector(apiRef));
|
|
288
290
|
|
|
289
|
-
var
|
|
291
|
+
var dataRowIdToIdLookup = _extends({}, gridRowsDataRowIdToIdLookupSelector(apiRef));
|
|
290
292
|
|
|
291
|
-
var
|
|
293
|
+
var rootGroup = tree[GRID_ROOT_GROUP_ID];
|
|
292
294
|
|
|
293
|
-
var
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
delete
|
|
306
|
-
delete updatedIdToIdLookup[replacedRowId];
|
|
307
|
-
delete updatedTree[replacedRowId];
|
|
308
|
-
});
|
|
309
|
-
newRowEntries.forEach(function (row) {
|
|
295
|
+
var rootGroupChildren = _toConsumableArray(rootGroup.children);
|
|
296
|
+
|
|
297
|
+
for (var i = 0; i < newRows.length; i += 1) {
|
|
298
|
+
var rowModel = newRows[i];
|
|
299
|
+
var rowId = getRowIdFromRowModel(rowModel, props.getRowId, 'A row was provided without id when calling replaceRows().');
|
|
300
|
+
|
|
301
|
+
var _rootGroupChildren$sp = rootGroupChildren.splice(firstRowToRender + i, 1, rowId),
|
|
302
|
+
_rootGroupChildren$sp2 = _slicedToArray(_rootGroupChildren$sp, 1),
|
|
303
|
+
replacedRowId = _rootGroupChildren$sp2[0];
|
|
304
|
+
|
|
305
|
+
delete dataRowIdToModelLookup[replacedRowId];
|
|
306
|
+
delete dataRowIdToIdLookup[replacedRowId];
|
|
307
|
+
delete tree[replacedRowId];
|
|
310
308
|
var rowTreeNodeConfig = {
|
|
311
|
-
id:
|
|
312
|
-
parent: null,
|
|
309
|
+
id: rowId,
|
|
313
310
|
depth: 0,
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
parent: GRID_ROOT_GROUP_ID,
|
|
312
|
+
type: 'leaf',
|
|
313
|
+
groupingKey: null
|
|
316
314
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
315
|
+
dataRowIdToModelLookup[rowId] = rowModel;
|
|
316
|
+
dataRowIdToIdLookup[rowId] = rowId;
|
|
317
|
+
tree[rowId] = rowTreeNodeConfig;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
tree[GRID_ROOT_GROUP_ID] = _extends({}, rootGroup, {
|
|
321
|
+
children: rootGroupChildren
|
|
322
|
+
}); // Removes potential remaining skeleton rows from the dataRowIds.
|
|
323
|
+
|
|
324
|
+
var dataRowIds = rootGroupChildren.filter(function (childId) {
|
|
325
|
+
return tree[childId].type === 'leaf';
|
|
320
326
|
});
|
|
321
327
|
apiRef.current.setState(function (state) {
|
|
322
328
|
return _extends({}, state, {
|
|
323
329
|
rows: _extends({}, state.rows, {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
330
|
+
dataRowIdToModelLookup: dataRowIdToModelLookup,
|
|
331
|
+
dataRowIdToIdLookup: dataRowIdToIdLookup,
|
|
332
|
+
dataRowIds: dataRowIds,
|
|
333
|
+
tree: tree
|
|
328
334
|
})
|
|
329
335
|
});
|
|
330
336
|
});
|
|
@@ -355,7 +361,12 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
355
361
|
if (apiRef.current.unstable_caches.rows.rowsBeforePartialUpdates === props.rows) {
|
|
356
362
|
// The `props.rows` did not change since the last row grouping
|
|
357
363
|
// We can use the current rows cache which contains the partial updates done recently.
|
|
358
|
-
cache = apiRef.current.unstable_caches.rows
|
|
364
|
+
cache = _extends({}, apiRef.current.unstable_caches.rows, {
|
|
365
|
+
updates: {
|
|
366
|
+
type: 'full',
|
|
367
|
+
rows: gridDataRowIdsSelector(apiRef)
|
|
368
|
+
}
|
|
369
|
+
});
|
|
359
370
|
} else {
|
|
360
371
|
// The `props.rows` has changed since the last row grouping
|
|
361
372
|
// We must use the new `props.rows` on the new grouping
|
|
@@ -367,7 +378,10 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
367
378
|
});
|
|
368
379
|
}
|
|
369
380
|
|
|
370
|
-
throttledRowsChange(
|
|
381
|
+
throttledRowsChange({
|
|
382
|
+
cache: cache,
|
|
383
|
+
throttle: false
|
|
384
|
+
});
|
|
371
385
|
}, [logger, apiRef, props.rows, props.getRowId, props.loading, throttledRowsChange]);
|
|
372
386
|
var handleStrategyProcessorChange = React.useCallback(function (methodName) {
|
|
373
387
|
if (methodName === 'rowTreeCreation') {
|
|
@@ -389,13 +403,25 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
389
403
|
|
|
390
404
|
var applyHydrateRowsProcessor = React.useCallback(function () {
|
|
391
405
|
apiRef.current.setState(function (state) {
|
|
406
|
+
var response = apiRef.current.unstable_applyPipeProcessors('hydrateRows', {
|
|
407
|
+
tree: gridRowTreeSelector(state, apiRef.current.instanceId),
|
|
408
|
+
treeDepths: gridRowTreeDepthsSelector(state, apiRef.current.instanceId),
|
|
409
|
+
dataRowIds: gridDataRowIdsSelector(state, apiRef.current.instanceId),
|
|
410
|
+
dataRowIdToModelLookup: gridRowsLookupSelector(state, apiRef.current.instanceId),
|
|
411
|
+
dataRowIdToIdLookup: gridRowsDataRowIdToIdLookupSelector(state, apiRef.current.instanceId)
|
|
412
|
+
});
|
|
392
413
|
return _extends({}, state, {
|
|
393
|
-
rows: _extends({}, state.rows,
|
|
414
|
+
rows: _extends({}, state.rows, response, {
|
|
415
|
+
totalTopLevelRowCount: getTopLevelRowCount({
|
|
416
|
+
tree: response.tree,
|
|
417
|
+
rowCountProp: props.rowCount
|
|
418
|
+
})
|
|
419
|
+
})
|
|
394
420
|
});
|
|
395
421
|
});
|
|
396
422
|
apiRef.current.publishEvent('rowsSet');
|
|
397
423
|
apiRef.current.forceUpdate();
|
|
398
|
-
}, [apiRef]);
|
|
424
|
+
}, [apiRef, props.rowCount]);
|
|
399
425
|
useGridRegisterPipeApplier(apiRef, 'hydrateRows', applyHydrateRowsProcessor);
|
|
400
426
|
useGridApiMethod(apiRef, rowApi, 'GridRowApi');
|
|
401
427
|
/**
|
|
@@ -439,10 +465,13 @@ export var useGridRows = function useGridRows(apiRef, props) {
|
|
|
439
465
|
}
|
|
440
466
|
|
|
441
467
|
logger.debug("Updating all rows, new length ".concat(props.rows.length));
|
|
442
|
-
throttledRowsChange(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
468
|
+
throttledRowsChange({
|
|
469
|
+
cache: createRowsInternalCache({
|
|
470
|
+
rows: props.rows,
|
|
471
|
+
getRowId: props.getRowId,
|
|
472
|
+
loading: props.loading
|
|
473
|
+
}),
|
|
474
|
+
throttle: false
|
|
475
|
+
});
|
|
447
476
|
}, [props.rows, props.rowCount, props.getRowId, props.loading, logger, throttledRowsChange, apiRef]);
|
|
448
477
|
};
|
|
@@ -1,39 +1,94 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
4
|
import { GRID_DEFAULT_STRATEGY, useGridRegisterStrategyProcessor } from '../../core/strategyProcessing';
|
|
5
|
+
import { buildRootGroup, GRID_ROOT_GROUP_ID } from './gridRowsUtils';
|
|
2
6
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
tree[rowId] = {
|
|
18
|
-
id: rowId,
|
|
19
|
-
depth: 0,
|
|
20
|
-
parent: null,
|
|
21
|
-
groupingKey: '',
|
|
22
|
-
groupingField: null
|
|
23
|
-
};
|
|
24
|
-
}
|
|
7
|
+
var createFlatRowTree = function createFlatRowTree(rows) {
|
|
8
|
+
var tree = _defineProperty({}, GRID_ROOT_GROUP_ID, _extends({}, buildRootGroup(), {
|
|
9
|
+
children: rows
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
for (var i = 0; i < rows.length; i += 1) {
|
|
13
|
+
var rowId = rows[i];
|
|
14
|
+
tree[rowId] = {
|
|
15
|
+
id: rowId,
|
|
16
|
+
depth: 0,
|
|
17
|
+
parent: GRID_ROOT_GROUP_ID,
|
|
18
|
+
type: 'leaf',
|
|
19
|
+
groupingKey: null
|
|
20
|
+
};
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
return {
|
|
28
24
|
groupingName: GRID_DEFAULT_STRATEGY,
|
|
29
25
|
tree: tree,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
treeDepths: {
|
|
27
|
+
0: rows.length
|
|
28
|
+
},
|
|
29
|
+
dataRowIds: rows
|
|
34
30
|
};
|
|
35
31
|
};
|
|
36
32
|
|
|
33
|
+
var updateFlatRowTree = function updateFlatRowTree(_ref) {
|
|
34
|
+
var previousTree = _ref.previousTree,
|
|
35
|
+
actions = _ref.actions;
|
|
36
|
+
|
|
37
|
+
var tree = _extends({}, previousTree);
|
|
38
|
+
|
|
39
|
+
var idsToRemoveFromRootGroup = {};
|
|
40
|
+
|
|
41
|
+
for (var i = 0; i < actions.remove.length; i += 1) {
|
|
42
|
+
var idToDelete = actions.remove[i];
|
|
43
|
+
idsToRemoveFromRootGroup[idToDelete] = true;
|
|
44
|
+
delete tree[idToDelete];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (var _i = 0; _i < actions.insert.length; _i += 1) {
|
|
48
|
+
var idToInsert = actions.insert[_i];
|
|
49
|
+
tree[idToInsert] = {
|
|
50
|
+
id: idToInsert,
|
|
51
|
+
depth: 0,
|
|
52
|
+
parent: GRID_ROOT_GROUP_ID,
|
|
53
|
+
type: 'leaf',
|
|
54
|
+
groupingKey: null
|
|
55
|
+
};
|
|
56
|
+
} // TODO rows v6: Support row unpinning
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
var rootGroup = tree[GRID_ROOT_GROUP_ID];
|
|
60
|
+
var rootGroupChildren = [].concat(_toConsumableArray(rootGroup.children), _toConsumableArray(actions.insert));
|
|
61
|
+
|
|
62
|
+
if (Object.values(idsToRemoveFromRootGroup).length) {
|
|
63
|
+
rootGroupChildren = rootGroupChildren.filter(function (id) {
|
|
64
|
+
return !idsToRemoveFromRootGroup[id];
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
tree[GRID_ROOT_GROUP_ID] = _extends({}, rootGroup, {
|
|
69
|
+
children: rootGroupChildren
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
groupingName: GRID_DEFAULT_STRATEGY,
|
|
73
|
+
tree: tree,
|
|
74
|
+
treeDepths: {
|
|
75
|
+
0: rootGroupChildren.length
|
|
76
|
+
},
|
|
77
|
+
dataRowIds: rootGroupChildren
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var flatRowTreeCreationMethod = function flatRowTreeCreationMethod(params) {
|
|
82
|
+
if (params.updates.type === 'full') {
|
|
83
|
+
return createFlatRowTree(params.updates.rows);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return updateFlatRowTree({
|
|
87
|
+
previousTree: params.previousTree,
|
|
88
|
+
actions: params.updates.actions
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
37
92
|
export var useGridRowsPreProcessors = function useGridRowsPreProcessors(apiRef) {
|
|
38
93
|
useGridRegisterStrategyProcessor(apiRef, GRID_DEFAULT_STRATEGY, 'rowTreeCreation', flatRowTreeCreationMethod);
|
|
39
94
|
};
|
|
@@ -126,7 +126,7 @@ export var useGridSelection = function useGridSelection(apiRef, props) {
|
|
|
126
126
|
|
|
127
127
|
var rowNode = apiRef.current.getRowNode(id);
|
|
128
128
|
|
|
129
|
-
if ((rowNode == null ? void 0 : rowNode.
|
|
129
|
+
if ((rowNode == null ? void 0 : rowNode.type) === 'footer' || (rowNode == null ? void 0 : rowNode.type) === 'pinnedRow') {
|
|
130
130
|
return false;
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -296,7 +296,7 @@ export var useGridSelection = function useGridSelection(apiRef, props) {
|
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
if (params.rowNode.
|
|
299
|
+
if (params.rowNode.type === 'pinnedRow') {
|
|
300
300
|
return;
|
|
301
301
|
}
|
|
302
302
|
|
|
@@ -21,11 +21,14 @@ export var gridSortedRowIdsSelector = createSelector(gridSortingStateSelector, f
|
|
|
21
21
|
* @category Sorting
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
export var gridSortedRowEntriesSelector = createSelector(gridSortedRowIdsSelector, gridRowsLookupSelector,
|
|
24
|
+
export var gridSortedRowEntriesSelector = createSelector(gridSortedRowIdsSelector, gridRowsLookupSelector, // TODO rows v6: Is this the best approach ?
|
|
25
|
+
function (sortedIds, idRowsLookup) {
|
|
25
26
|
return sortedIds.map(function (id) {
|
|
27
|
+
var _idRowsLookup$id;
|
|
28
|
+
|
|
26
29
|
return {
|
|
27
30
|
id: id,
|
|
28
|
-
model: idRowsLookup[id]
|
|
31
|
+
model: (_idRowsLookup$id = idRowsLookup[id]) != null ? _idRowsLookup$id : {}
|
|
29
32
|
};
|
|
30
33
|
});
|
|
31
34
|
});
|