@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.
Files changed (161) hide show
  1. package/CHANGELOG.md +209 -0
  2. package/DataGrid/useDataGridProps.js +4 -4
  3. package/components/DataGridVirtualScroller.js +5 -3
  4. package/components/GridPagination.d.ts +43 -1
  5. package/components/GridPagination.js +1 -2
  6. package/components/GridRow.d.ts +1 -4
  7. package/components/GridRow.js +9 -8
  8. package/components/base/GridBody.js +1 -2
  9. package/components/base/GridOverlays.js +52 -12
  10. package/components/cell/GridBooleanCell.js +2 -1
  11. package/components/columnSelection/GridCellCheckboxRenderer.d.ts +2 -2
  12. package/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
  13. package/components/containers/GridOverlay.js +0 -5
  14. package/components/panel/filterPanel/GridFilterForm.js +2 -1
  15. package/components/toolbar/GridToolbarFilterButton.js +8 -4
  16. package/constants/gridClasses.d.ts +8 -0
  17. package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +1 -1
  18. package/hooks/core/strategyProcessing/gridStrategyProcessingApi.d.ts +1 -1
  19. package/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  20. package/hooks/features/editRows/useGridCellEditing.new.js +18 -9
  21. package/hooks/features/editRows/useGridEditing.new.js +3 -2
  22. package/hooks/features/editRows/useGridEditing.old.js +2 -1
  23. package/hooks/features/editRows/useGridRowEditing.new.js +18 -9
  24. package/hooks/features/export/useGridPrintExport.js +31 -17
  25. package/hooks/features/export/utils.js +1 -5
  26. package/hooks/features/filter/gridFilterSelector.js +2 -2
  27. package/hooks/features/filter/useGridFilter.js +6 -6
  28. package/hooks/features/pagination/gridPaginationSelector.js +2 -2
  29. package/hooks/features/rows/gridRowsInterfaces.d.ts +106 -0
  30. package/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
  31. package/hooks/features/rows/gridRowsSelector.d.ts +17 -7
  32. package/hooks/features/rows/gridRowsSelector.js +38 -6
  33. package/hooks/features/rows/gridRowsUtils.d.ts +16 -4
  34. package/hooks/features/rows/gridRowsUtils.js +222 -39
  35. package/hooks/features/rows/index.d.ts +3 -3
  36. package/hooks/features/rows/index.js +2 -2
  37. package/hooks/features/rows/useGridRows.js +161 -124
  38. package/hooks/features/rows/useGridRowsPreProcessors.js +78 -26
  39. package/hooks/features/selection/useGridSelection.js +2 -2
  40. package/hooks/features/sorting/gridSortingSelector.js +9 -4
  41. package/hooks/features/sorting/gridSortingState.d.ts +2 -2
  42. package/hooks/features/sorting/useGridSorting.js +9 -33
  43. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +4 -7
  44. package/hooks/features/virtualization/useGridVirtualScroller.js +11 -17
  45. package/index.js +1 -1
  46. package/internals/index.d.ts +2 -1
  47. package/internals/index.js +1 -0
  48. package/legacy/DataGrid/useDataGridProps.js +4 -4
  49. package/legacy/components/DataGridVirtualScroller.js +5 -3
  50. package/legacy/components/GridPagination.js +1 -2
  51. package/legacy/components/GridRow.js +9 -8
  52. package/legacy/components/base/GridBody.js +1 -2
  53. package/legacy/components/base/GridOverlays.js +54 -12
  54. package/legacy/components/cell/GridBooleanCell.js +2 -1
  55. package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
  56. package/legacy/components/containers/GridOverlay.js +0 -5
  57. package/legacy/components/panel/filterPanel/GridFilterForm.js +2 -1
  58. package/legacy/components/toolbar/GridToolbarFilterButton.js +3 -1
  59. package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  60. package/legacy/hooks/features/editRows/useGridCellEditing.new.js +18 -9
  61. package/legacy/hooks/features/editRows/useGridEditing.new.js +3 -2
  62. package/legacy/hooks/features/editRows/useGridEditing.old.js +2 -1
  63. package/legacy/hooks/features/editRows/useGridRowEditing.new.js +18 -9
  64. package/legacy/hooks/features/export/useGridPrintExport.js +33 -20
  65. package/legacy/hooks/features/export/utils.js +1 -3
  66. package/legacy/hooks/features/filter/gridFilterSelector.js +2 -2
  67. package/legacy/hooks/features/filter/useGridFilter.js +6 -6
  68. package/legacy/hooks/features/pagination/gridPaginationSelector.js +2 -2
  69. package/legacy/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
  70. package/legacy/hooks/features/rows/gridRowsSelector.js +52 -9
  71. package/legacy/hooks/features/rows/gridRowsUtils.js +238 -46
  72. package/legacy/hooks/features/rows/index.js +2 -2
  73. package/legacy/hooks/features/rows/useGridRows.js +163 -134
  74. package/legacy/hooks/features/rows/useGridRowsPreProcessors.js +81 -26
  75. package/legacy/hooks/features/selection/useGridSelection.js +2 -2
  76. package/legacy/hooks/features/sorting/gridSortingSelector.js +5 -2
  77. package/legacy/hooks/features/sorting/useGridSorting.js +11 -33
  78. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +11 -17
  79. package/legacy/index.js +1 -1
  80. package/legacy/internals/index.js +1 -0
  81. package/legacy/models/gridFeatureMode.js +1 -4
  82. package/models/api/gridParamsApi.d.ts +2 -2
  83. package/models/api/gridRowApi.d.ts +7 -5
  84. package/models/events/gridEventLookup.d.ts +3 -3
  85. package/models/gridApiCaches.d.ts +1 -1
  86. package/models/gridFeatureMode.d.ts +0 -4
  87. package/models/gridFeatureMode.js +1 -4
  88. package/models/gridRows.d.ts +100 -30
  89. package/models/gridSortModel.d.ts +2 -2
  90. package/models/params/gridCellParams.d.ts +7 -11
  91. package/modern/DataGrid/useDataGridProps.js +4 -4
  92. package/modern/components/DataGridVirtualScroller.js +5 -3
  93. package/modern/components/GridPagination.js +1 -2
  94. package/modern/components/GridRow.js +9 -8
  95. package/modern/components/base/GridBody.js +1 -2
  96. package/modern/components/base/GridOverlays.js +52 -12
  97. package/modern/components/cell/GridBooleanCell.js +2 -1
  98. package/modern/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
  99. package/modern/components/containers/GridOverlay.js +0 -5
  100. package/modern/components/panel/filterPanel/GridFilterForm.js +2 -1
  101. package/modern/components/toolbar/GridToolbarFilterButton.js +1 -1
  102. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  103. package/modern/hooks/features/editRows/useGridCellEditing.new.js +18 -9
  104. package/modern/hooks/features/editRows/useGridEditing.new.js +3 -2
  105. package/modern/hooks/features/editRows/useGridEditing.old.js +2 -1
  106. package/modern/hooks/features/editRows/useGridRowEditing.new.js +18 -9
  107. package/modern/hooks/features/export/useGridPrintExport.js +30 -16
  108. package/modern/hooks/features/export/utils.js +1 -1
  109. package/modern/hooks/features/filter/gridFilterSelector.js +2 -2
  110. package/modern/hooks/features/filter/useGridFilter.js +6 -6
  111. package/modern/hooks/features/pagination/gridPaginationSelector.js +2 -2
  112. package/modern/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
  113. package/modern/hooks/features/rows/gridRowsSelector.js +28 -6
  114. package/modern/hooks/features/rows/gridRowsUtils.js +220 -37
  115. package/modern/hooks/features/rows/index.js +2 -2
  116. package/modern/hooks/features/rows/useGridRows.js +158 -121
  117. package/modern/hooks/features/rows/useGridRowsPreProcessors.js +78 -26
  118. package/modern/hooks/features/selection/useGridSelection.js +2 -2
  119. package/modern/hooks/features/sorting/gridSortingSelector.js +3 -2
  120. package/modern/hooks/features/sorting/useGridSorting.js +9 -33
  121. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +10 -16
  122. package/modern/index.js +1 -1
  123. package/modern/internals/index.js +1 -0
  124. package/modern/models/gridFeatureMode.js +1 -4
  125. package/node/DataGrid/useDataGridProps.js +3 -3
  126. package/node/components/DataGridVirtualScroller.js +5 -3
  127. package/node/components/GridPagination.js +1 -2
  128. package/node/components/GridRow.js +9 -7
  129. package/node/components/base/GridBody.js +1 -3
  130. package/node/components/base/GridOverlays.js +57 -12
  131. package/node/components/cell/GridBooleanCell.js +3 -1
  132. package/node/components/columnSelection/GridCellCheckboxRenderer.js +1 -6
  133. package/node/components/containers/GridOverlay.js +0 -5
  134. package/node/components/panel/filterPanel/GridFilterForm.js +2 -1
  135. package/node/components/toolbar/GridToolbarFilterButton.js +8 -4
  136. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  137. package/node/hooks/features/editRows/useGridCellEditing.new.js +20 -10
  138. package/node/hooks/features/editRows/useGridEditing.new.js +4 -2
  139. package/node/hooks/features/editRows/useGridEditing.old.js +3 -1
  140. package/node/hooks/features/editRows/useGridRowEditing.new.js +20 -10
  141. package/node/hooks/features/export/useGridPrintExport.js +31 -17
  142. package/node/hooks/features/export/utils.js +1 -5
  143. package/node/hooks/features/filter/gridFilterSelector.js +1 -1
  144. package/node/hooks/features/filter/useGridFilter.js +5 -6
  145. package/node/hooks/features/pagination/gridPaginationSelector.js +1 -1
  146. package/node/hooks/features/rows/{gridRowsState.js → gridRowsInterfaces.js} +0 -0
  147. package/node/hooks/features/rows/gridRowsSelector.js +43 -10
  148. package/node/hooks/features/rows/gridRowsUtils.js +239 -40
  149. package/node/hooks/features/rows/index.js +23 -9
  150. package/node/hooks/features/rows/useGridRows.js +161 -122
  151. package/node/hooks/features/rows/useGridRowsPreProcessors.js +81 -26
  152. package/node/hooks/features/selection/useGridSelection.js +2 -2
  153. package/node/hooks/features/sorting/gridSortingSelector.js +9 -4
  154. package/node/hooks/features/sorting/useGridSorting.js +9 -33
  155. package/node/hooks/features/virtualization/useGridVirtualScroller.js +11 -17
  156. package/node/index.js +1 -1
  157. package/node/internals/index.js +14 -2
  158. package/node/models/gridFeatureMode.js +1 -7
  159. package/package.json +1 -1
  160. package/themeAugmentation/props.d.ts +2 -2
  161. 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 { gridRowIdsSelector } from '../rows';
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 === GridFeatureModeConstant.client ? buildAggregatedFilterApplier(filterModel, apiRef) : null;
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 === GridFeatureModeConstant.client && params.isRowMatchingFilters) {
248
- const rowIds = gridRowIdsSelector(apiRef);
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 { gridRowTreeDepthSelector, gridRowTreeSelector } from '../rows/gridRowsSelector';
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, gridRowTreeDepthSelector, gridVisibleSortedRowEntriesSelector, gridVisibleSortedTopLevelRowEntriesSelector, (pagination, rowTree, rowTreeDepth, visibleSortedRowEntries, visibleSortedTopLevelRowEntries) => {
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
@@ -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
- export const gridRowsLookupSelector = createSelector(gridRowsStateSelector, rows => rows.idRowsLookup);
7
- export const gridRowsIdToIdLookupSelector = createSelector(gridRowsStateSelector, rows => rows.idToIdLookup);
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 gridRowTreeDepthSelector = createSelector(gridRowsStateSelector, rows => rows.treeDepth);
11
- export const gridRowIdsSelector = createSelector(gridRowsStateSelector, rows => rows.ids);
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 => additionalRowGroups?.pinnedRows);
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 cache = {
28
- rowsBeforePartialUpdates: rows,
29
- loadingPropBeforePartialUpdates: loading,
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 row = rows[i];
37
- const id = getRowIdFromRowModel(row, getRowId);
38
- cache.idRowsLookup[id] = row;
39
- cache.idToIdLookup[id] = id;
40
- cache.ids.push(id);
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 cache;
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
- rowCountProp,
49
- loadingProp
74
+ previousTreeDepths
50
75
  }) => {
51
- const _apiRef$current$unsta = apiRef.current.unstable_caches.rows,
52
- cacheForGrouping = _objectWithoutPropertiesLoose(_apiRef$current$unsta, _excluded);
53
-
54
- const rowCount = rowCountProp ?? 0;
55
- const groupingResponse = apiRef.current.unstable_applyStrategyProcessor('rowTreeCreation', _extends({}, cacheForGrouping, {
56
- previousTree
57
- }));
58
- const processedGroupingResponse = apiRef.current.unstable_applyPipeProcessors('hydrateRows', groupingResponse);
59
- const dataTopLevelRowCount = processedGroupingResponse.treeDepth === 1 ? processedGroupingResponse.ids.length : Object.values(processedGroupingResponse.tree).filter(node => node.parent == null && !node.isPinned).length;
60
- return _extends({}, processedGroupingResponse, {
61
- groupingResponseBeforeRowHydration: groupingResponse,
62
- loading: loadingProp,
63
- totalRowCount: Math.max(rowCount, processedGroupingResponse.ids.length),
64
- totalTopLevelRowCount: Math.max(rowCount, dataTopLevelRowCount)
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 children = tree[parentId]?.children;
120
+ const node = tree[parentId];
69
121
 
70
- if (children == null) {
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 || !childNode.isAutoGenerated) {
131
+ if (!skipAutoGeneratedRows || !isAutoGeneratedRow(tree[child])) {
81
132
  validDescendants.push(child);
82
133
  }
83
134
 
84
- validDescendants.push(...getTreeNodeDescendants(tree, childNode.id, skipAutoGeneratedRows));
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, gridRowsIdToIdLookupSelector, gridRowTreeSelector, gridRowGroupingNameSelector, gridRowTreeDepthSelector, gridRowIdsSelector } from './gridRowsSelector';
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';