@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,6 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { GridFeatureModeConstant } from '../../../models/gridFeatureMode';
|
|
4
3
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
5
4
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
6
5
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
@@ -9,7 +8,7 @@ import { GridPreferencePanelsValue } from '../preferencesPanel/gridPreferencePan
|
|
|
9
8
|
import { getDefaultGridFilterModel } from './gridFilterState';
|
|
10
9
|
import { gridFilterModelSelector, gridVisibleSortedRowEntriesSelector } from './gridFilterSelector';
|
|
11
10
|
import { useFirstRender } from '../../utils/useFirstRender';
|
|
12
|
-
import {
|
|
11
|
+
import { GRID_ROOT_GROUP_ID, gridRowTreeSelector } from '../rows';
|
|
13
12
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
14
13
|
import { GRID_DEFAULT_STRATEGY, useGridRegisterStrategyProcessor } from '../../core/strategyProcessing';
|
|
15
14
|
import { buildAggregatedFilterApplier, sanitizeFilterModel, mergeStateWithFilterModel, cleanFilterItem, passFilterLogic } from './gridFilterUtils';
|
|
@@ -43,7 +42,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
43
42
|
const updateFilteredRows = React.useCallback(() => {
|
|
44
43
|
apiRef.current.setState(state => {
|
|
45
44
|
const filterModel = gridFilterModelSelector(state, apiRef.current.instanceId);
|
|
46
|
-
const isRowMatchingFilters = props.filterMode ===
|
|
45
|
+
const isRowMatchingFilters = props.filterMode === 'client' ? buildAggregatedFilterApplier(filterModel, apiRef) : null;
|
|
47
46
|
const filteringResult = apiRef.current.unstable_applyStrategyProcessor('filtering', {
|
|
48
47
|
isRowMatchingFilters,
|
|
49
48
|
filterModel: filterModel ?? getDefaultGridFilterModel()
|
|
@@ -244,8 +243,9 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
244
243
|
return initialValue;
|
|
245
244
|
}, [props.components.FilterPanel, props.componentsProps?.filterPanel]);
|
|
246
245
|
const flatFilteringMethod = React.useCallback(params => {
|
|
247
|
-
if (props.filterMode ===
|
|
248
|
-
const
|
|
246
|
+
if (props.filterMode === 'client' && params.isRowMatchingFilters) {
|
|
247
|
+
const tree = gridRowTreeSelector(apiRef);
|
|
248
|
+
const rowIds = tree[GRID_ROOT_GROUP_ID].children;
|
|
249
249
|
const filteredRowsLookup = {};
|
|
250
250
|
|
|
251
251
|
for (let i = 0; i < rowIds.length; i += 1) {
|
|
@@ -267,7 +267,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
267
267
|
|
|
268
268
|
return {
|
|
269
269
|
filteredRowsLookup,
|
|
270
|
-
// For flat tree, the `visibleRowsLookup` and the `filteredRowsLookup` since no row is collapsed.
|
|
270
|
+
// For flat tree, the `visibleRowsLookup` and the `filteredRowsLookup` are equals since no row is collapsed.
|
|
271
271
|
visibleRowsLookup: filteredRowsLookup,
|
|
272
272
|
filteredDescendantCountLookup: {}
|
|
273
273
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
2
|
import { gridVisibleSortedRowEntriesSelector, gridVisibleSortedRowIdsSelector, gridVisibleSortedTopLevelRowEntriesSelector } from '../filter/gridFilterSelector';
|
|
3
|
-
import {
|
|
3
|
+
import { gridRowMaximumTreeDepthSelector, gridRowTreeSelector } from '../rows/gridRowsSelector';
|
|
4
4
|
/**
|
|
5
5
|
* @category Pagination
|
|
6
6
|
* @ignore - do not document.
|
|
@@ -30,7 +30,7 @@ export const gridPageCountSelector = createSelector(gridPaginationSelector, pagi
|
|
|
30
30
|
* @category Pagination
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
export const gridPaginationRowRangeSelector = createSelector(gridPaginationSelector, gridRowTreeSelector,
|
|
33
|
+
export const gridPaginationRowRangeSelector = createSelector(gridPaginationSelector, gridRowTreeSelector, gridRowMaximumTreeDepthSelector, gridVisibleSortedRowEntriesSelector, gridVisibleSortedTopLevelRowEntriesSelector, (pagination, rowTree, rowTreeDepth, visibleSortedRowEntries, visibleSortedTopLevelRowEntries) => {
|
|
34
34
|
const visibleTopLevelRowCount = visibleSortedTopLevelRowEntries.length;
|
|
35
35
|
const topLevelFirstRowIndex = Math.min(pagination.pageSize * pagination.page, visibleTopLevelRowCount - 1);
|
|
36
36
|
const topLevelLastRowIndex = Math.min(topLevelFirstRowIndex + pagination.pageSize - 1, visibleTopLevelRowCount - 1); // The range contains no element
|
|
File without changes
|
|
@@ -2,13 +2,23 @@ import { createSelector } from '../../../utils/createSelector';
|
|
|
2
2
|
export const gridRowsStateSelector = state => state.rows;
|
|
3
3
|
export const gridRowCountSelector = createSelector(gridRowsStateSelector, rows => rows.totalRowCount);
|
|
4
4
|
export const gridRowsLoadingSelector = createSelector(gridRowsStateSelector, rows => rows.loading);
|
|
5
|
-
export const gridTopLevelRowCountSelector = createSelector(gridRowsStateSelector, rows => rows.totalTopLevelRowCount);
|
|
6
|
-
|
|
7
|
-
export const
|
|
5
|
+
export const gridTopLevelRowCountSelector = createSelector(gridRowsStateSelector, rows => rows.totalTopLevelRowCount); // TODO rows v6: Rename
|
|
6
|
+
|
|
7
|
+
export const gridRowsLookupSelector = createSelector(gridRowsStateSelector, rows => rows.dataRowIdToModelLookup);
|
|
8
|
+
export const gridRowsDataRowIdToIdLookupSelector = createSelector(gridRowsStateSelector, rows => rows.dataRowIdToIdLookup);
|
|
8
9
|
export const gridRowTreeSelector = createSelector(gridRowsStateSelector, rows => rows.tree);
|
|
9
10
|
export const gridRowGroupingNameSelector = createSelector(gridRowsStateSelector, rows => rows.groupingName);
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
11
|
+
export const gridRowTreeDepthsSelector = createSelector(gridRowsStateSelector, rows => rows.treeDepths);
|
|
12
|
+
export const gridRowMaximumTreeDepthSelector = createSelector(gridRowsStateSelector, rows => {
|
|
13
|
+
const entries = Object.entries(rows.treeDepths);
|
|
14
|
+
|
|
15
|
+
if (entries.length === 0) {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return entries.filter(([, nodeCount]) => nodeCount > 0).map(([depth]) => Number(depth)).sort((a, b) => b - a)[0] + 1;
|
|
20
|
+
});
|
|
21
|
+
export const gridDataRowIdsSelector = createSelector(gridRowsStateSelector, rows => rows.dataRowIds);
|
|
12
22
|
/**
|
|
13
23
|
* @ignore - do not document.
|
|
14
24
|
*/
|
|
@@ -18,7 +28,19 @@ export const gridAdditionalRowGroupsSelector = createSelector(gridRowsStateSelec
|
|
|
18
28
|
* @ignore - do not document.
|
|
19
29
|
*/
|
|
20
30
|
|
|
21
|
-
export const gridPinnedRowsSelector = createSelector(gridAdditionalRowGroupsSelector, additionalRowGroups =>
|
|
31
|
+
export const gridPinnedRowsSelector = createSelector(gridAdditionalRowGroupsSelector, additionalRowGroups => {
|
|
32
|
+
const rawPinnedRows = additionalRowGroups?.pinnedRows;
|
|
33
|
+
return {
|
|
34
|
+
bottom: rawPinnedRows?.bottom?.map(rowEntry => ({
|
|
35
|
+
id: rowEntry.id,
|
|
36
|
+
model: rowEntry.model ?? {}
|
|
37
|
+
})),
|
|
38
|
+
top: rawPinnedRows?.top?.map(rowEntry => ({
|
|
39
|
+
id: rowEntry.id,
|
|
40
|
+
model: rowEntry.model ?? {}
|
|
41
|
+
}))
|
|
42
|
+
};
|
|
43
|
+
});
|
|
22
44
|
/**
|
|
23
45
|
* @ignore - do not document.
|
|
24
46
|
*/
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["rowsBeforePartialUpdates"];
|
|
4
2
|
import { gridPinnedRowsSelector } from './gridRowsSelector';
|
|
3
|
+
import { gridDensityRowHeightSelector } from '../density/densitySelector';
|
|
4
|
+
export const GRID_ROOT_GROUP_ID = `auto-generated-group-node-root`;
|
|
5
|
+
export const buildRootGroup = () => ({
|
|
6
|
+
type: 'group',
|
|
7
|
+
id: GRID_ROOT_GROUP_ID,
|
|
8
|
+
depth: -1,
|
|
9
|
+
groupingField: null,
|
|
10
|
+
groupingKey: null,
|
|
11
|
+
isAutoGenerated: true,
|
|
12
|
+
children: [],
|
|
13
|
+
childrenFromPath: {},
|
|
14
|
+
childrenExpanded: true,
|
|
15
|
+
parent: null
|
|
16
|
+
});
|
|
5
17
|
/**
|
|
6
18
|
* A helper function to check if the id provided is valid.
|
|
7
19
|
* @param {GridRowId} id Id as [[GridRowId]].
|
|
@@ -24,68 +36,235 @@ export const createRowsInternalCache = ({
|
|
|
24
36
|
getRowId,
|
|
25
37
|
loading
|
|
26
38
|
}) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
idRowsLookup: {},
|
|
31
|
-
idToIdLookup: {},
|
|
32
|
-
ids: []
|
|
39
|
+
const updates = {
|
|
40
|
+
type: 'full',
|
|
41
|
+
rows: []
|
|
33
42
|
};
|
|
43
|
+
const dataRowIdToModelLookup = {};
|
|
44
|
+
const dataRowIdToIdLookup = {};
|
|
34
45
|
|
|
35
46
|
for (let i = 0; i < rows.length; i += 1) {
|
|
36
|
-
const
|
|
37
|
-
const id = getRowIdFromRowModel(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
const model = rows[i];
|
|
48
|
+
const id = getRowIdFromRowModel(model, getRowId);
|
|
49
|
+
dataRowIdToModelLookup[id] = model;
|
|
50
|
+
dataRowIdToIdLookup[id] = id;
|
|
51
|
+
updates.rows.push(id);
|
|
41
52
|
}
|
|
42
53
|
|
|
43
|
-
return
|
|
54
|
+
return {
|
|
55
|
+
rowsBeforePartialUpdates: rows,
|
|
56
|
+
loadingPropBeforePartialUpdates: loading,
|
|
57
|
+
updates,
|
|
58
|
+
dataRowIdToIdLookup,
|
|
59
|
+
dataRowIdToModelLookup
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export const getTopLevelRowCount = ({
|
|
63
|
+
tree,
|
|
64
|
+
rowCountProp = 0
|
|
65
|
+
}) => {
|
|
66
|
+
const rootGroupNode = tree[GRID_ROOT_GROUP_ID];
|
|
67
|
+
return Math.max(rowCountProp, rootGroupNode.children.length + (rootGroupNode.footerId == null ? 0 : 1));
|
|
44
68
|
};
|
|
45
69
|
export const getRowsStateFromCache = ({
|
|
46
70
|
apiRef,
|
|
71
|
+
rowCountProp = 0,
|
|
72
|
+
loadingProp,
|
|
47
73
|
previousTree,
|
|
48
|
-
|
|
49
|
-
loadingProp
|
|
74
|
+
previousTreeDepths
|
|
50
75
|
}) => {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
const cache = apiRef.current.unstable_caches.rows; // 1. Apply the "rowTreeCreation" family processing.
|
|
77
|
+
|
|
78
|
+
const {
|
|
79
|
+
tree: unProcessedTree,
|
|
80
|
+
treeDepths: unProcessedTreeDepths,
|
|
81
|
+
dataRowIds: unProcessedDataRowIds,
|
|
82
|
+
groupingName
|
|
83
|
+
} = apiRef.current.unstable_applyStrategyProcessor('rowTreeCreation', {
|
|
84
|
+
previousTree,
|
|
85
|
+
previousTreeDepths,
|
|
86
|
+
updates: cache.updates,
|
|
87
|
+
dataRowIdToIdLookup: cache.dataRowIdToIdLookup,
|
|
88
|
+
dataRowIdToModelLookup: cache.dataRowIdToModelLookup
|
|
89
|
+
}); // 2. Apply the "hydrateRows" pipe-processing.
|
|
90
|
+
|
|
91
|
+
const groupingParamsWithHydrateRows = apiRef.current.unstable_applyPipeProcessors('hydrateRows', {
|
|
92
|
+
tree: unProcessedTree,
|
|
93
|
+
treeDepths: unProcessedTreeDepths,
|
|
94
|
+
dataRowIdToIdLookup: cache.dataRowIdToIdLookup,
|
|
95
|
+
dataRowIds: unProcessedDataRowIds,
|
|
96
|
+
dataRowIdToModelLookup: cache.dataRowIdToModelLookup
|
|
97
|
+
}); // 3. Reset the cache updates
|
|
98
|
+
|
|
99
|
+
apiRef.current.unstable_caches.rows.updates = {
|
|
100
|
+
type: 'partial',
|
|
101
|
+
actions: {
|
|
102
|
+
insert: [],
|
|
103
|
+
modify: [],
|
|
104
|
+
remove: []
|
|
105
|
+
},
|
|
106
|
+
idToActionLookup: {}
|
|
107
|
+
};
|
|
108
|
+
return _extends({}, groupingParamsWithHydrateRows, {
|
|
109
|
+
totalRowCount: Math.max(rowCountProp, groupingParamsWithHydrateRows.dataRowIds.length),
|
|
110
|
+
totalTopLevelRowCount: getTopLevelRowCount({
|
|
111
|
+
tree: groupingParamsWithHydrateRows.tree,
|
|
112
|
+
rowCountProp
|
|
113
|
+
}),
|
|
114
|
+
groupingName,
|
|
115
|
+
loading: loadingProp
|
|
65
116
|
});
|
|
66
117
|
};
|
|
118
|
+
export const isAutoGeneratedRow = rowNode => rowNode.type === 'skeletonRow' || rowNode.type === 'footer' || rowNode.type === 'group' && rowNode.isAutoGenerated || rowNode.type === 'pinnedRow' && rowNode.isAutoGenerated;
|
|
67
119
|
export const getTreeNodeDescendants = (tree, parentId, skipAutoGeneratedRows) => {
|
|
68
|
-
const
|
|
120
|
+
const node = tree[parentId];
|
|
69
121
|
|
|
70
|
-
if (
|
|
122
|
+
if (node.type !== 'group') {
|
|
71
123
|
return [];
|
|
72
124
|
}
|
|
73
125
|
|
|
74
126
|
const validDescendants = [];
|
|
75
127
|
|
|
76
|
-
for (let i = 0; i < children.length; i += 1) {
|
|
77
|
-
const child = children[i];
|
|
78
|
-
const childNode = tree[child];
|
|
128
|
+
for (let i = 0; i < node.children.length; i += 1) {
|
|
129
|
+
const child = node.children[i];
|
|
79
130
|
|
|
80
|
-
if (!skipAutoGeneratedRows || !
|
|
131
|
+
if (!skipAutoGeneratedRows || !isAutoGeneratedRow(tree[child])) {
|
|
81
132
|
validDescendants.push(child);
|
|
82
133
|
}
|
|
83
134
|
|
|
84
|
-
validDescendants.push(...getTreeNodeDescendants(tree,
|
|
135
|
+
validDescendants.push(...getTreeNodeDescendants(tree, child, skipAutoGeneratedRows));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!skipAutoGeneratedRows && node.footerId != null) {
|
|
139
|
+
validDescendants.push(node.footerId);
|
|
85
140
|
}
|
|
86
141
|
|
|
87
142
|
return validDescendants;
|
|
88
143
|
};
|
|
144
|
+
export const updateCacheWithNewRows = ({
|
|
145
|
+
previousCache,
|
|
146
|
+
getRowId,
|
|
147
|
+
updates
|
|
148
|
+
}) => {
|
|
149
|
+
if (previousCache.updates.type === 'full') {
|
|
150
|
+
throw new Error('MUI: Unable to prepare a partial update if a full update is not applied yet');
|
|
151
|
+
} // Remove duplicate updates.
|
|
152
|
+
// A server can batch updates, and send several updates for the same row in one fn call.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
const uniqueUpdates = new Map();
|
|
156
|
+
updates.forEach(update => {
|
|
157
|
+
const id = getRowIdFromRowModel(update, getRowId, 'A row was provided without id when calling updateRows():');
|
|
158
|
+
|
|
159
|
+
if (uniqueUpdates.has(id)) {
|
|
160
|
+
uniqueUpdates.set(id, _extends({}, uniqueUpdates.get(id), update));
|
|
161
|
+
} else {
|
|
162
|
+
uniqueUpdates.set(id, update);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const partialUpdates = {
|
|
166
|
+
type: 'partial',
|
|
167
|
+
actions: {
|
|
168
|
+
insert: [...(previousCache.updates.actions.insert ?? [])],
|
|
169
|
+
modify: [...(previousCache.updates.actions.modify ?? [])],
|
|
170
|
+
remove: [...(previousCache.updates.actions.remove ?? [])]
|
|
171
|
+
},
|
|
172
|
+
idToActionLookup: _extends({}, previousCache.updates.idToActionLookup)
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const dataRowIdToModelLookup = _extends({}, previousCache.dataRowIdToModelLookup);
|
|
176
|
+
|
|
177
|
+
const dataRowIdToIdLookup = _extends({}, previousCache.dataRowIdToIdLookup);
|
|
178
|
+
|
|
179
|
+
const alreadyAppliedActionsToRemove = {
|
|
180
|
+
insert: {},
|
|
181
|
+
modify: {},
|
|
182
|
+
remove: {}
|
|
183
|
+
}; // Depending on the action already applied to the data row,
|
|
184
|
+
// We might want drop the already-applied-update.
|
|
185
|
+
// For instance:
|
|
186
|
+
// - if you delete then insert, then you don't want to apply the deletion in the tree.
|
|
187
|
+
// - if you insert, then modify, then you just want to apply the insertion in the tree.
|
|
188
|
+
|
|
189
|
+
uniqueUpdates.forEach((partialRow, id) => {
|
|
190
|
+
const actionAlreadyAppliedToRow = partialUpdates.idToActionLookup[id]; // Action === "delete"
|
|
191
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
192
|
+
|
|
193
|
+
if (partialRow._action === 'delete') {
|
|
194
|
+
// If the data row has been removed since the last state update,
|
|
195
|
+
// Then do nothing.
|
|
196
|
+
if (actionAlreadyAppliedToRow === 'remove' || !dataRowIdToModelLookup[id]) {
|
|
197
|
+
return;
|
|
198
|
+
} // If the data row has been inserted / modified since the last state update,
|
|
199
|
+
// Then drop this "insert" / "modify" update.
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
if (actionAlreadyAppliedToRow != null) {
|
|
203
|
+
alreadyAppliedActionsToRemove[actionAlreadyAppliedToRow][id] = true;
|
|
204
|
+
} // Remove the data row from the lookups and add it to the "delete" update.
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
partialUpdates.actions.remove.push(id);
|
|
208
|
+
delete dataRowIdToModelLookup[id];
|
|
209
|
+
delete dataRowIdToIdLookup[id];
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const oldRow = dataRowIdToModelLookup[id]; // Action === "modify"
|
|
214
|
+
|
|
215
|
+
if (oldRow) {
|
|
216
|
+
// If the data row has been removed since the last state update,
|
|
217
|
+
// Then drop this "remove" update and add it to the "modify" update instead.
|
|
218
|
+
if (actionAlreadyAppliedToRow === 'remove') {
|
|
219
|
+
alreadyAppliedActionsToRemove.remove[id] = true;
|
|
220
|
+
partialUpdates.actions.modify.push(id);
|
|
221
|
+
} // If the date has not been inserted / modified since the last state update,
|
|
222
|
+
// Then add it to the "modify" update (if it has been inserted it should just remain "inserted").
|
|
223
|
+
else if (actionAlreadyAppliedToRow == null) {
|
|
224
|
+
partialUpdates.actions.modify.push(id);
|
|
225
|
+
} // Update the data row lookups.
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
dataRowIdToModelLookup[id] = _extends({}, oldRow, partialRow);
|
|
229
|
+
return;
|
|
230
|
+
} // Action === "insert"
|
|
231
|
+
// If the data row has been removed since the last state update,
|
|
232
|
+
// Then drop the "remove" update and add it to the "insert" update instead.
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
if (actionAlreadyAppliedToRow === 'remove') {
|
|
236
|
+
alreadyAppliedActionsToRemove.remove[id] = true;
|
|
237
|
+
partialUpdates.actions.insert.push(id);
|
|
238
|
+
} // If the data row has not been inserted since the last state update,
|
|
239
|
+
// Then add it to the "insert" update.
|
|
240
|
+
// `actionAlreadyAppliedToRow` can't be equal to "modify", otherwise we would have an `oldRow` above.
|
|
241
|
+
else if (actionAlreadyAppliedToRow == null) {
|
|
242
|
+
partialUpdates.actions.insert.push(id);
|
|
243
|
+
} // Update the data row lookups.
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
dataRowIdToModelLookup[id] = partialRow;
|
|
247
|
+
dataRowIdToIdLookup[id] = id;
|
|
248
|
+
});
|
|
249
|
+
const actionTypeWithActionsToRemove = Object.keys(alreadyAppliedActionsToRemove);
|
|
250
|
+
|
|
251
|
+
for (let i = 0; i < actionTypeWithActionsToRemove.length; i += 1) {
|
|
252
|
+
const actionType = actionTypeWithActionsToRemove[i];
|
|
253
|
+
const idsToRemove = alreadyAppliedActionsToRemove[actionType];
|
|
254
|
+
|
|
255
|
+
if (Object.keys(idsToRemove).length > 0) {
|
|
256
|
+
partialUpdates.actions[actionType] = partialUpdates.actions[actionType].filter(id => !idsToRemove[id]);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
dataRowIdToModelLookup,
|
|
262
|
+
dataRowIdToIdLookup,
|
|
263
|
+
updates: partialUpdates,
|
|
264
|
+
rowsBeforePartialUpdates: previousCache.rowsBeforePartialUpdates,
|
|
265
|
+
loadingPropBeforePartialUpdates: previousCache.loadingPropBeforePartialUpdates
|
|
266
|
+
};
|
|
267
|
+
};
|
|
89
268
|
export function calculatePinnedRowsHeight(apiRef) {
|
|
90
269
|
const pinnedRows = gridPinnedRowsSelector(apiRef);
|
|
91
270
|
const topPinnedRowsHeight = pinnedRows?.top?.reduce((acc, value) => {
|
|
@@ -100,4 +279,8 @@ export function calculatePinnedRowsHeight(apiRef) {
|
|
|
100
279
|
top: topPinnedRowsHeight,
|
|
101
280
|
bottom: bottomPinnedRowsHeight
|
|
102
281
|
};
|
|
282
|
+
}
|
|
283
|
+
export function getMinimalContentHeight(apiRef) {
|
|
284
|
+
const rowHeight = gridDensityRowHeightSelector(apiRef);
|
|
285
|
+
return 2 * rowHeight;
|
|
103
286
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './gridRowsMetaSelector';
|
|
2
2
|
export * from './gridRowsMetaState';
|
|
3
|
-
export { gridRowsStateSelector, gridRowCountSelector, gridRowsLoadingSelector, gridTopLevelRowCountSelector, gridRowsLookupSelector,
|
|
4
|
-
export { checkGridRowIdIsValid } from './gridRowsUtils';
|
|
3
|
+
export { gridRowsStateSelector, gridRowCountSelector, gridRowsLoadingSelector, gridTopLevelRowCountSelector, gridRowsLookupSelector, gridRowsDataRowIdToIdLookupSelector, gridRowTreeSelector, gridRowGroupingNameSelector, gridRowTreeDepthsSelector, gridRowMaximumTreeDepthSelector, gridDataRowIdsSelector } from './gridRowsSelector';
|
|
4
|
+
export { GRID_ROOT_GROUP_ID, checkGridRowIdIsValid } from './gridRowsUtils';
|