@mui/x-data-grid-pro 5.17.5 → 6.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +297 -19
  2. package/DataGridPro/DataGridPro.js +4 -14
  3. package/DataGridPro/useDataGridProProps.js +2 -2
  4. package/components/DataGridProVirtualScroller.js +2 -2
  5. package/components/GridDetailPanelToggleCell.js +1 -1
  6. package/components/GridRowReorderCell.js +4 -6
  7. package/components/GridTreeDataGroupingCell.d.ts +2 -2
  8. package/components/GridTreeDataGroupingCell.js +1 -1
  9. package/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  10. package/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  11. package/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  12. package/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
  13. package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.d.ts +1 -1
  14. package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
  15. package/hooks/features/rowPinning/gridRowPinningInterface.d.ts +2 -2
  16. package/hooks/features/rowPinning/useGridRowPinningPreProcessors.d.ts +16 -16
  17. package/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
  18. package/hooks/features/rowReorder/useGridRowReorder.js +5 -5
  19. package/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  20. package/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  21. package/hooks/features/treeData/useGridTreeData.js +2 -6
  22. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
  23. package/index.js +1 -1
  24. package/internals/index.d.ts +4 -2
  25. package/internals/index.js +4 -2
  26. package/legacy/DataGridPro/DataGridPro.js +4 -14
  27. package/legacy/DataGridPro/useDataGridProProps.js +2 -2
  28. package/legacy/components/DataGridProVirtualScroller.js +2 -2
  29. package/legacy/components/GridDetailPanelToggleCell.js +1 -1
  30. package/legacy/components/GridRowReorderCell.js +4 -6
  31. package/legacy/components/GridTreeDataGroupingCell.js +1 -1
  32. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  33. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  34. package/legacy/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  35. package/legacy/hooks/features/lazyLoader/useGridLazyLoader.js +25 -15
  36. package/legacy/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +21 -7
  37. package/legacy/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
  38. package/legacy/hooks/features/rowReorder/useGridRowReorder.js +5 -5
  39. package/legacy/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  40. package/legacy/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  41. package/legacy/hooks/features/treeData/useGridTreeData.js +2 -6
  42. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +37 -22
  43. package/legacy/index.js +1 -1
  44. package/legacy/internals/index.js +4 -2
  45. package/legacy/utils/tree/createRowTree.js +36 -0
  46. package/legacy/utils/tree/index.js +1 -1
  47. package/legacy/utils/tree/insertDataRowInTree.js +127 -0
  48. package/legacy/utils/tree/models.js +1 -0
  49. package/legacy/utils/tree/removeDataRowFromTree.js +97 -0
  50. package/legacy/utils/tree/sortRowTree.js +49 -43
  51. package/legacy/utils/tree/updateRowTree.js +81 -0
  52. package/legacy/utils/tree/utils.js +184 -0
  53. package/models/dataGridProProps.d.ts +3 -3
  54. package/modern/DataGridPro/DataGridPro.js +4 -14
  55. package/modern/DataGridPro/useDataGridProProps.js +2 -2
  56. package/modern/components/DataGridProVirtualScroller.js +2 -2
  57. package/modern/components/GridDetailPanelToggleCell.js +1 -1
  58. package/modern/components/GridRowReorderCell.js +4 -4
  59. package/modern/components/GridTreeDataGroupingCell.js +1 -1
  60. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  61. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  62. package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  63. package/modern/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
  64. package/modern/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
  65. package/modern/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +60 -23
  66. package/modern/hooks/features/rowReorder/useGridRowReorder.js +5 -3
  67. package/modern/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  68. package/modern/hooks/features/treeData/gridTreeDataUtils.js +13 -9
  69. package/modern/hooks/features/treeData/useGridTreeData.js +2 -4
  70. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
  71. package/modern/index.js +1 -1
  72. package/modern/internals/index.js +4 -2
  73. package/modern/utils/tree/createRowTree.js +35 -0
  74. package/modern/utils/tree/index.js +1 -1
  75. package/modern/utils/tree/insertDataRowInTree.js +127 -0
  76. package/modern/utils/tree/models.js +1 -0
  77. package/modern/utils/tree/removeDataRowFromTree.js +100 -0
  78. package/modern/utils/tree/sortRowTree.js +46 -40
  79. package/modern/utils/tree/updateRowTree.js +83 -0
  80. package/modern/utils/tree/utils.js +180 -0
  81. package/node/DataGridPro/DataGridPro.js +4 -14
  82. package/node/DataGridPro/useDataGridProProps.js +1 -1
  83. package/node/components/DataGridProVirtualScroller.js +1 -1
  84. package/node/components/GridDetailPanelToggleCell.js +1 -1
  85. package/node/components/GridRowReorderCell.js +3 -5
  86. package/node/components/GridTreeDataGroupingCell.js +1 -1
  87. package/node/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
  88. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  89. package/node/hooks/features/infiniteLoader/useGridInfiniteLoader.js +1 -1
  90. package/node/hooks/features/lazyLoader/useGridLazyLoader.js +19 -8
  91. package/node/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +18 -5
  92. package/node/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +63 -26
  93. package/node/hooks/features/rowReorder/useGridRowReorder.js +4 -4
  94. package/node/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  95. package/node/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  96. package/node/hooks/features/treeData/useGridTreeData.js +1 -5
  97. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -17
  98. package/node/index.js +1 -1
  99. package/node/internals/index.js +35 -10
  100. package/node/utils/tree/createRowTree.js +46 -0
  101. package/node/utils/tree/index.js +2 -2
  102. package/node/utils/tree/insertDataRowInTree.js +139 -0
  103. package/node/utils/tree/models.js +5 -0
  104. package/node/utils/tree/removeDataRowFromTree.js +110 -0
  105. package/node/utils/tree/sortRowTree.js +50 -43
  106. package/node/utils/tree/updateRowTree.js +98 -0
  107. package/node/utils/tree/utils.js +217 -0
  108. package/package.json +5 -5
  109. package/utils/tree/createRowTree.d.ts +15 -0
  110. package/utils/tree/createRowTree.js +35 -0
  111. package/utils/tree/index.d.ts +1 -1
  112. package/utils/tree/index.js +1 -1
  113. package/utils/tree/insertDataRowInTree.d.ts +51 -0
  114. package/utils/tree/insertDataRowInTree.js +129 -0
  115. package/utils/tree/models.d.ts +13 -0
  116. package/utils/tree/models.js +1 -0
  117. package/utils/tree/removeDataRowFromTree.d.ts +40 -0
  118. package/utils/tree/removeDataRowFromTree.js +100 -0
  119. package/utils/tree/sortRowTree.d.ts +6 -1
  120. package/utils/tree/sortRowTree.js +46 -40
  121. package/utils/tree/updateRowTree.d.ts +19 -0
  122. package/utils/tree/updateRowTree.js +83 -0
  123. package/utils/tree/utils.d.ts +66 -0
  124. package/utils/tree/utils.js +186 -0
  125. package/legacy/utils/tree/buildRowTree.js +0 -195
  126. package/modern/utils/tree/buildRowTree.js +0 -174
  127. package/node/utils/tree/buildRowTree.js +0 -195
  128. package/utils/tree/buildRowTree.d.ts +0 -48
  129. package/utils/tree/buildRowTree.js +0 -186
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { useThemeProps } from '@mui/material/styles';
4
- import { DATA_GRID_DEFAULT_SLOTS_COMPONENTS, GRID_DEFAULT_LOCALE_TEXT, DATA_GRID_PROPS_DEFAULT_VALUES, GridFeatureModeConstant } from '@mui/x-data-grid';
4
+ import { DATA_GRID_DEFAULT_SLOTS_COMPONENTS, GRID_DEFAULT_LOCALE_TEXT, DATA_GRID_PROPS_DEFAULT_VALUES } from '@mui/x-data-grid';
5
5
 
6
6
  /**
7
7
  * The default values of `DataGridProPropsWithDefaultValue` to inject in the props of DataGridPro.
@@ -14,7 +14,7 @@ export const DATA_GRID_PRO_PROPS_DEFAULT_VALUES = _extends({}, DATA_GRID_PROPS_D
14
14
  disableChildrenFiltering: false,
15
15
  disableChildrenSorting: false,
16
16
  rowReordering: false,
17
- rowsLoadingMode: GridFeatureModeConstant.client,
17
+ rowsLoadingMode: 'client',
18
18
  getDetailPanelHeight: () => 500
19
19
  });
20
20
  export const useDataGridProProps = inProps => {
@@ -4,7 +4,7 @@ const _excluded = ["className", "disableVirtualization"];
4
4
  import * as React from 'react';
5
5
  import { styled, alpha } from '@mui/material/styles';
6
6
  import { unstable_composeClasses as composeClasses } from '@mui/material';
7
- import { useGridSelector, getDataGridUtilityClass, gridClasses, gridVisibleColumnFieldsSelector, gridRowsMetaSelector, useGridApiEventHandler } from '@mui/x-data-grid';
7
+ import { useGridSelector, getDataGridUtilityClass, gridClasses, gridVisibleColumnFieldsSelector, gridRowsMetaSelector, useGridApiEventHandler, GridOverlays } from '@mui/x-data-grid';
8
8
  import { GridVirtualScroller, GridVirtualScrollerContent, GridVirtualScrollerRenderZone, useGridVirtualScroller, calculatePinnedRowsHeight } from '@mui/x-data-grid/internals';
9
9
  import { useGridApiContext } from '../hooks/utils/useGridApiContext';
10
10
  import { useGridRootProps } from '../hooks/utils/useGridRootProps';
@@ -297,7 +297,7 @@ const DataGridProVirtualScroller = /*#__PURE__*/React.forwardRef(function DataGr
297
297
  }
298
298
 
299
299
  return /*#__PURE__*/_jsxs(GridVirtualScroller, _extends({}, getRootProps(other), {
300
- children: [topPinnedRowsData.length > 0 ? /*#__PURE__*/_jsxs(VirtualScrollerPinnedRows, {
300
+ children: [/*#__PURE__*/_jsx(GridOverlays, {}), topPinnedRowsData.length > 0 ? /*#__PURE__*/_jsxs(VirtualScrollerPinnedRows, {
301
301
  className: classes.topPinnedRows,
302
302
  ownerState: {
303
303
  position: 'top'
@@ -116,7 +116,7 @@ process.env.NODE_ENV !== "production" ? GridDetailPanelToggleCell.propTypes = {
116
116
  /**
117
117
  * The row model of the row that the current cell belongs to.
118
118
  */
119
- row: PropTypes.object.isRequired,
119
+ row: PropTypes.any.isRequired,
120
120
 
121
121
  /**
122
122
  * The node of the row that the current cell belongs to.
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { unstable_composeClasses as composeClasses } from '@mui/material';
4
- import { gridRowTreeDepthSelector, gridSortModelSelector, useGridApiContext, useGridSelector, getDataGridUtilityClass, gridEditRowsStateSelector } from '@mui/x-data-grid';
4
+ import { gridRowMaximumTreeDepthSelector, gridSortModelSelector, useGridApiContext, useGridSelector, getDataGridUtilityClass, gridEditRowsStateSelector } from '@mui/x-data-grid';
5
5
  import { useGridRootProps } from '../hooks/utils/useGridRootProps';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -22,7 +22,7 @@ const GridRowReorderCell = params => {
22
22
  const apiRef = useGridApiContext();
23
23
  const rootProps = useGridRootProps();
24
24
  const sortModel = useGridSelector(apiRef, gridSortModelSelector);
25
- const treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
25
+ const treeDepth = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector);
26
26
  const editRowsState = useGridSelector(apiRef, gridEditRowsStateSelector); // eslint-disable-next-line no-underscore-dangle
27
27
 
28
28
  const cellValue = params.row.__reorder__ || params.id; // TODO: remove sortModel and treeDepth checks once row reorder is compatible
@@ -58,7 +58,7 @@ const GridRowReorderCell = params => {
58
58
  onDragEnd: publish('rowDragEnd')
59
59
  } : null;
60
60
 
61
- if ((params.rowNode.position ?? 'body') !== 'body') {
61
+ if (params.rowNode.type === 'footer') {
62
62
  return null;
63
63
  }
64
64
 
@@ -75,7 +75,7 @@ const GridRowReorderCell = params => {
75
75
 
76
76
  export { GridRowReorderCell };
77
77
  export const renderRowReorderCell = params => {
78
- if (params.rowNode.isPinned) {
78
+ if (params.rowNode.type === 'footer' || params.rowNode.type === 'pinnedRow') {
79
79
  return null;
80
80
  }
81
81
 
@@ -149,7 +149,7 @@ process.env.NODE_ENV !== "production" ? GridTreeDataGroupingCell.propTypes = {
149
149
  /**
150
150
  * The row model of the row that the current cell belongs to.
151
151
  */
152
- row: PropTypes.object.isRequired,
152
+ row: PropTypes.any.isRequired,
153
153
 
154
154
  /**
155
155
  * The node of the row that the current cell belongs to.
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import { useGridSelector, useGridApiEventHandler, useGridApiMethod, gridRowIdsSelector } from '@mui/x-data-grid';
3
+ import { useGridSelector, useGridApiEventHandler, useGridApiMethod, gridDataRowIdsSelector } from '@mui/x-data-grid';
4
4
  import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
5
5
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from './gridDetailPanelToggleColDef';
6
6
  import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector, gridDetailPanelRawHeightCacheSelector } from './gridDetailPanelSelector';
@@ -20,7 +20,7 @@ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeig
20
20
  // only call getDetailPanelContent when asked for an id
21
21
 
22
22
 
23
- const rowIds = gridRowIdsSelector(apiRef);
23
+ const rowIds = gridDataRowIdsSelector(apiRef);
24
24
  const contentCache = rowIds.reduce((acc, id) => {
25
25
  const params = apiRef.current.getRowParams(id);
26
26
  acc[id] = getDetailPanelContent(params);
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import { useGridApiEventHandler, gridRowIdsSelector } from '@mui/x-data-grid';
3
+ import { useGridApiEventHandler, gridDataRowIdsSelector } from '@mui/x-data-grid';
4
4
 
5
5
  function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight, previousHeightCache) {
6
6
  if (typeof getDetailPanelContent !== 'function') {
@@ -9,7 +9,7 @@ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeig
9
9
  // only call getDetailPanelContent when asked for an id
10
10
 
11
11
 
12
- const rowIds = gridRowIdsSelector(apiRef);
12
+ const rowIds = gridDataRowIdsSelector(apiRef);
13
13
  const contentCache = rowIds.reduce((acc, id) => {
14
14
  const params = apiRef.current.getRowParams(id);
15
15
  acc[id] = getDetailPanelContent(params);
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useGridSelector, useGridApiEventHandler, useGridApiOptionHandler, gridVisibleColumnDefinitionsSelector, gridRowsMetaSelector, GridFeatureModeConstant } from '@mui/x-data-grid';
2
+ import { useGridSelector, useGridApiEventHandler, useGridApiOptionHandler, gridVisibleColumnDefinitionsSelector, gridRowsMetaSelector } from '@mui/x-data-grid';
3
3
  import { useGridVisibleRows } from '@mui/x-data-grid/internals';
4
4
 
5
5
  /**
@@ -16,7 +16,7 @@ export const useGridInfiniteLoader = (apiRef, props) => {
16
16
  const handleRowsScrollEnd = React.useCallback(scrollPosition => {
17
17
  const dimensions = apiRef.current.getRootDimensions(); // Prevent the infite loading working in combination with lazy loading
18
18
 
19
- if (!dimensions || props.rowsLoadingMode !== GridFeatureModeConstant.client) {
19
+ if (!dimensions || props.rowsLoadingMode !== 'client') {
20
20
  return;
21
21
  }
22
22
 
@@ -1,8 +1,12 @@
1
1
  import * as React from 'react';
2
- import { useGridApiEventHandler, GridFeatureModeConstant, useGridSelector, gridSortModelSelector, gridFilterModelSelector, useGridApiOptionHandler } from '@mui/x-data-grid';
2
+ import { useGridApiEventHandler, useGridSelector, gridSortModelSelector, gridFilterModelSelector, useGridApiOptionHandler } from '@mui/x-data-grid';
3
3
  import { useGridVisibleRows, getRenderableIndexes } from '@mui/x-data-grid/internals';
4
4
 
5
- function findSkeletonRowsSection(visibleRows, range) {
5
+ function findSkeletonRowsSection({
6
+ apiRef,
7
+ visibleRows,
8
+ range
9
+ }) {
6
10
  let {
7
11
  firstRowIndex,
8
12
  lastRowIndex
@@ -13,16 +17,19 @@ function findSkeletonRowsSection(visibleRows, range) {
13
17
  let isSkeletonSectionFound = false;
14
18
 
15
19
  while (!isSkeletonSectionFound && firstRowIndex < lastRowIndex) {
16
- if (!visibleRowsSection[startIndex].model && !visibleRowsSection[endIndex].model) {
20
+ const isStartingWithASkeletonRow = apiRef.current.getRowNode(visibleRowsSection[startIndex].id).type === 'skeletonRow';
21
+ const isEndingWithASkeletonRow = apiRef.current.getRowNode(visibleRowsSection[endIndex].id).type === 'skeletonRow';
22
+
23
+ if (isStartingWithASkeletonRow && isEndingWithASkeletonRow) {
17
24
  isSkeletonSectionFound = true;
18
25
  }
19
26
 
20
- if (visibleRowsSection[startIndex].model) {
27
+ if (!isStartingWithASkeletonRow) {
21
28
  startIndex += 1;
22
29
  firstRowIndex += 1;
23
30
  }
24
31
 
25
- if (visibleRowsSection[endIndex].model) {
32
+ if (!isEndingWithASkeletonRow) {
26
33
  endIndex -= 1;
27
34
  lastRowIndex -= 1;
28
35
  }
@@ -43,7 +50,7 @@ function isLazyLoadingDisabled({
43
50
  return true;
44
51
  }
45
52
 
46
- if (rowsLoadingMode !== GridFeatureModeConstant.server) {
53
+ if (rowsLoadingMode !== 'server') {
47
54
  return true;
48
55
  }
49
56
 
@@ -105,9 +112,13 @@ export const useGridLazyLoader = (apiRef, props) => {
105
112
  }
106
113
 
107
114
  if (sortModel.length === 0 && filterModel.items.length === 0) {
108
- const skeletonRowsSection = findSkeletonRowsSection(visibleRows.rows, {
109
- firstRowIndex: params.firstRowToRender,
110
- lastRowIndex: params.lastRowToRender
115
+ const skeletonRowsSection = findSkeletonRowsSection({
116
+ apiRef,
117
+ visibleRows: visibleRows.rows,
118
+ range: {
119
+ firstRowIndex: params.firstRowToRender,
120
+ lastRowIndex: params.lastRowToRender
121
+ }
111
122
  });
112
123
 
113
124
  if (!skeletonRowsSection) {
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
4
- import { GridFeatureModeConstant } from '@mui/x-data-grid';
4
+ import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
5
5
  export const GRID_SKELETON_ROW_ROOT_ID = 'auto-generated-skeleton-row-root';
6
6
 
7
7
  const getSkeletonRowId = index => `${GRID_SKELETON_ROW_ROOT_ID}-${index}`;
@@ -11,19 +11,33 @@ export const useGridLazyLoaderPreProcessors = (apiRef, props) => {
11
11
  lazyLoading
12
12
  } = props.experimentalFeatures ?? {};
13
13
  const addSkeletonRows = React.useCallback(groupingParams => {
14
- if (!lazyLoading || props.rowsLoadingMode !== GridFeatureModeConstant.server || !props.rowCount || groupingParams.ids.length >= props.rowCount) {
14
+ const tree = _extends({}, groupingParams.tree);
15
+
16
+ const rootGroup = tree[GRID_ROOT_GROUP_ID];
17
+
18
+ if (!lazyLoading || props.rowsLoadingMode !== 'server' || !props.rowCount || rootGroup.children.length >= props.rowCount) {
15
19
  return groupingParams;
16
20
  }
17
21
 
18
- const newRowsIds = [...groupingParams.ids];
22
+ const rootGroupChildren = [...rootGroup.children];
19
23
 
20
- for (let i = 0; i < props.rowCount - groupingParams.ids.length; i += 1) {
24
+ for (let i = 0; i < props.rowCount - rootGroup.children.length; i += 1) {
21
25
  const skeletonId = getSkeletonRowId(i);
22
- newRowsIds.push(skeletonId);
26
+ rootGroupChildren.push(skeletonId);
27
+ const skeletonRowNode = {
28
+ type: 'skeletonRow',
29
+ id: skeletonId,
30
+ parent: GRID_ROOT_GROUP_ID,
31
+ depth: 0
32
+ };
33
+ tree[skeletonId] = skeletonRowNode;
23
34
  }
24
35
 
36
+ tree[GRID_ROOT_GROUP_ID] = _extends({}, rootGroup, {
37
+ children: rootGroupChildren
38
+ });
25
39
  return _extends({}, groupingParams, {
26
- ids: newRowsIds
40
+ tree
27
41
  });
28
42
  }, [props.rowCount, props.rowsLoadingMode, lazyLoading]);
29
43
  useGridRegisterPipeProcessor(apiRef, 'hydrateRows', addSkeletonRows);
@@ -1,40 +1,66 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
4
+ import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
5
+ import { insertNodeInTree } from '../../../utils/tree/utils';
4
6
  export function addPinnedRow({
5
7
  groupingParams,
6
8
  rowModel,
7
9
  rowId,
8
10
  position,
9
- apiRef
11
+ apiRef,
12
+ isAutoGenerated
10
13
  }) {
11
- const idRowsLookup = _extends({}, groupingParams.idRowsLookup);
14
+ const dataRowIdToModelLookup = _extends({}, groupingParams.dataRowIdToModelLookup);
12
15
 
13
- const tree = _extends({}, groupingParams.tree); // TODO: warn if id is already present in `props.rows`
16
+ const dataRowIdToIdLookup = _extends({}, groupingParams.dataRowIdToIdLookup);
14
17
 
18
+ const tree = _extends({}, groupingParams.tree);
15
19
 
16
- idRowsLookup[rowId] = rowModel; // Do not push it to ids list so that pagination is not affected by pinned rows
17
- // ids.push(rowId);
20
+ const treeDepths = _extends({}, groupingParams.treeDepths); // TODO: warn if id is already present in `props.rows`
18
21
 
19
- tree[rowId] = {
22
+
23
+ const node = {
24
+ type: 'pinnedRow',
20
25
  id: rowId,
21
- isAutoGenerated: false,
22
- parent: null,
23
26
  depth: 0,
24
- groupingKey: null,
25
- groupingField: null,
26
- isPinned: true
27
+ parent: GRID_ROOT_GROUP_ID,
28
+ isAutoGenerated
27
29
  };
28
- apiRef.current.unstable_caches.rows.idRowsLookup[rowId] = _extends({}, rowModel);
29
- apiRef.current.unstable_caches.rows.idToIdLookup[rowId] = rowId;
30
+ insertNodeInTree({
31
+ node,
32
+ tree,
33
+ treeDepths
34
+ });
35
+
36
+ if (!isAutoGenerated) {
37
+ dataRowIdToModelLookup[rowId] = rowModel;
38
+ dataRowIdToIdLookup[rowId] = rowId;
39
+ } // Do not push it to ids list so that pagination is not affected by pinned rows
40
+
41
+
42
+ apiRef.current.unstable_caches.rows.dataRowIdToModelLookup[rowId] = _extends({}, rowModel);
43
+ apiRef.current.unstable_caches.rows.dataRowIdToIdLookup[rowId] = rowId;
30
44
  const previousPinnedRows = groupingParams.additionalRowGroups?.pinnedRows || {};
31
45
  const newPinnedRow = {
32
46
  id: rowId,
33
47
  model: rowModel
34
48
  };
49
+
50
+ if (groupingParams.additionalRowGroups?.pinnedRows?.[position]?.includes(newPinnedRow)) {
51
+ return _extends({}, groupingParams, {
52
+ dataRowIdToModelLookup,
53
+ dataRowIdToIdLookup,
54
+ tree,
55
+ treeDepths
56
+ });
57
+ }
58
+
35
59
  return _extends({}, groupingParams, {
36
- idRowsLookup,
60
+ dataRowIdToModelLookup,
61
+ dataRowIdToIdLookup,
37
62
  tree,
63
+ treeDepths,
38
64
  additionalRowGroups: _extends({}, groupingParams.additionalRowGroups, {
39
65
  pinnedRows: _extends({}, previousPinnedRows, {
40
66
  [position]: [...(previousPinnedRows[position] || []), newPinnedRow]
@@ -59,7 +85,8 @@ export const useGridRowPinningPreProcessors = apiRef => {
59
85
  rowModel: pinnedRowsCache.idLookup[rowId],
60
86
  rowId,
61
87
  position: 'top',
62
- apiRef
88
+ apiRef,
89
+ isAutoGenerated: false
63
90
  });
64
91
  });
65
92
  pinnedRowsCache.bottomIds?.forEach(rowId => {
@@ -68,17 +95,27 @@ export const useGridRowPinningPreProcessors = apiRef => {
68
95
  rowModel: pinnedRowsCache.idLookup[rowId],
69
96
  rowId,
70
97
  position: 'bottom',
71
- apiRef
98
+ apiRef,
99
+ isAutoGenerated: false
72
100
  });
73
- }); // If row with the same `id` is present both in `rows` and `pinnedRows` - remove it from `ids`
101
+ }); // If row with the same `id` is present both in `rows` and `pinnedRows` - remove it from the root group children
74
102
 
75
- newGroupingParams.ids = newGroupingParams.ids.filter(rowId => {
76
- if (newGroupingParams.tree[rowId] && newGroupingParams.tree[rowId].isPinned) {
77
- return false;
78
- }
103
+ if (pinnedRowsCache.bottomIds?.length || pinnedRowsCache.topIds?.length) {
104
+ const shouldKeepRow = rowId => {
105
+ if (newGroupingParams.tree[rowId] && newGroupingParams.tree[rowId].type === 'pinnedRow') {
106
+ return false;
107
+ }
108
+
109
+ return true;
110
+ };
111
+
112
+ const rootGroupNode = newGroupingParams.tree[GRID_ROOT_GROUP_ID];
113
+ newGroupingParams.tree[GRID_ROOT_GROUP_ID] = _extends({}, rootGroupNode, {
114
+ children: rootGroupNode.children.filter(shouldKeepRow)
115
+ });
116
+ newGroupingParams.dataRowIds = newGroupingParams.dataRowIds.filter(shouldKeepRow);
117
+ }
79
118
 
80
- return true;
81
- });
82
119
  return newGroupingParams;
83
120
  }, [apiRef]);
84
121
  useGridRegisterPipeProcessor(apiRef, 'hydrateRows', addPinnedRows);
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { unstable_composeClasses as composeClasses } from '@mui/material';
3
- import { useGridLogger, useGridApiEventHandler, getDataGridUtilityClass, useGridSelector, gridSortModelSelector, gridRowTreeDepthSelector, useGridApiOptionHandler, gridEditRowsStateSelector } from '@mui/x-data-grid';
3
+ import { useGridLogger, useGridApiEventHandler, getDataGridUtilityClass, useGridSelector, gridSortModelSelector, gridRowMaximumTreeDepthSelector, useGridApiOptionHandler, gridEditRowsStateSelector } from '@mui/x-data-grid';
4
4
 
5
5
  const useUtilityClasses = ownerState => {
6
6
  const {
@@ -20,7 +20,7 @@ const useUtilityClasses = ownerState => {
20
20
  export const useGridRowReorder = (apiRef, props) => {
21
21
  const logger = useGridLogger(apiRef, 'useGridRowReorder');
22
22
  const sortModel = useGridSelector(apiRef, gridSortModelSelector);
23
- const treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
23
+ const treeDepth = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector);
24
24
  const dragRowNode = React.useRef(null);
25
25
  const originRowIndex = React.useRef(null);
26
26
  const removeDnDStylesTimeout = React.useRef();
@@ -64,7 +64,9 @@ export const useGridRowReorder = (apiRef, props) => {
64
64
  return;
65
65
  }
66
66
 
67
- if (apiRef.current.getRowNode(params.id)?.isPinned) {
67
+ const rowNode = apiRef.current.getRowNode(params.id);
68
+
69
+ if (!rowNode || rowNode.type === 'footer' || rowNode.type === 'pinnedRow') {
68
70
  return;
69
71
  }
70
72
 
@@ -12,7 +12,7 @@ export const GRID_TREE_DATA_GROUPING_COL_DEF = _extends({}, GRID_STRING_COL_DEF,
12
12
  disableReorder: true,
13
13
  align: 'left',
14
14
  width: 200,
15
- valueGetter: params => params.rowNode.groupingKey
15
+ valueGetter: params => params.rowNode.type === 'group' ? params.rowNode.groupingKey : undefined
16
16
  });
17
17
  export const GRID_TREE_DATA_GROUPING_FIELD = '__tree_data_group__';
18
18
  export const GRID_TREE_DATA_GROUPING_COL_DEF_FORCED_PROPERTIES = {
@@ -22,7 +22,7 @@ export const filterRowTreeFromTreeData = params => {
22
22
 
23
23
  if (shouldSkipFilters) {
24
24
  isMatchingFilters = null;
25
- } else if (!isRowMatchingFilters || node.position === 'footer') {
25
+ } else if (!isRowMatchingFilters || node.type === 'footer') {
26
26
  isMatchingFilters = true;
27
27
  } else {
28
28
  const {
@@ -33,11 +33,15 @@ export const filterRowTreeFromTreeData = params => {
33
33
  }
34
34
 
35
35
  let filteredDescendantCount = 0;
36
- node.children?.forEach(childId => {
37
- const childNode = rowTree[childId];
38
- const childSubTreeSize = filterTreeNode(childNode, isMatchingFilters ?? isParentMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
39
- filteredDescendantCount += childSubTreeSize;
40
- });
36
+
37
+ if (node.type === 'group') {
38
+ node.children.forEach(childId => {
39
+ const childNode = rowTree[childId];
40
+ const childSubTreeSize = filterTreeNode(childNode, isMatchingFilters ?? isParentMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
41
+ filteredDescendantCount += childSubTreeSize;
42
+ });
43
+ }
44
+
41
45
  let shouldPassFilters;
42
46
 
43
47
  switch (isMatchingFilters) {
@@ -61,9 +65,9 @@ export const filterRowTreeFromTreeData = params => {
61
65
  }
62
66
 
63
67
  visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
64
- filteredRowsLookup[node.id] = shouldPassFilters;
68
+ filteredRowsLookup[node.id] = shouldPassFilters; // TODO: Should we keep storing the visibility status of footer independently or rely on the group visibility in the selector ?
65
69
 
66
- if (node.footerId != null) {
70
+ if (node.type === 'group' && node.footerId != null) {
67
71
  visibleRowsLookup[node.footerId] = shouldPassFilters && areAncestorsExpanded && !!node.childrenExpanded;
68
72
  }
69
73
 
@@ -73,7 +77,7 @@ export const filterRowTreeFromTreeData = params => {
73
77
 
74
78
  filteredDescendantCountLookup[node.id] = filteredDescendantCount;
75
79
 
76
- if (node.position === 'footer') {
80
+ if (node.type === 'footer') {
77
81
  return filteredDescendantCount;
78
82
  }
79
83
 
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useGridApiEventHandler, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
2
+ import { useGridApiEventHandler } from '@mui/x-data-grid';
3
3
  export const useGridTreeData = apiRef => {
4
4
  /**
5
5
  * EVENTS
@@ -8,9 +8,7 @@ export const useGridTreeData = apiRef => {
8
8
  const cellParams = apiRef.current.getCellParams(params.id, params.field);
9
9
 
10
10
  if (cellParams.colDef.type === 'treeDataGroup' && event.key === ' ' && !event.shiftKey) {
11
- const filteredDescendantCount = gridFilteredDescendantCountLookupSelector(apiRef)[params.id] ?? 0;
12
-
13
- if (filteredDescendantCount === 0) {
11
+ if (params.rowNode.type !== 'group') {
14
12
  return;
15
13
  }
16
14
 
@@ -2,13 +2,14 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["hideDescendantCount"];
4
4
  import * as React from 'react';
5
- import { gridRowIdsSelector, gridRowTreeSelector, useFirstRender, GRID_CHECKBOX_SELECTION_FIELD } from '@mui/x-data-grid';
5
+ import { gridRowTreeSelector, useFirstRender, GRID_CHECKBOX_SELECTION_FIELD } from '@mui/x-data-grid';
6
6
  import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
7
7
  import { GRID_TREE_DATA_GROUPING_COL_DEF, GRID_TREE_DATA_GROUPING_COL_DEF_FORCED_PROPERTIES } from './gridTreeDataGroupColDef';
8
8
  import { filterRowTreeFromTreeData, TREE_DATA_STRATEGY } from './gridTreeDataUtils';
9
9
  import { GridTreeDataGroupingCell } from '../../../components';
10
- import { buildRowTree } from '../../../utils/tree/buildRowTree';
10
+ import { createRowTree } from '../../../utils/tree/createRowTree';
11
11
  import { sortRowTree } from '../../../utils/tree/sortRowTree';
12
+ import { updateRowTree } from '../../../utils/tree/updateRowTree';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  export const useGridTreeDataPreProcessors = (apiRef, props) => {
14
15
  const setStrategyAvailability = React.useCallback(() => {
@@ -69,28 +70,45 @@ export const useGridTreeDataPreProcessors = (apiRef, props) => {
69
70
 
70
71
  return columnsState;
71
72
  }, [props.treeData, getGroupingColDef]);
72
- const createRowTree = React.useCallback(params => {
73
+ const createRowTreeForTreeData = React.useCallback(params => {
73
74
  if (!props.getTreeDataPath) {
74
75
  throw new Error('MUI: No getTreeDataPath given.');
75
76
  }
76
77
 
77
- const rows = params.ids.map(rowId => ({
78
+ const getRowTreeBuilderNode = rowId => ({
78
79
  id: rowId,
79
- path: props.getTreeDataPath(params.idRowsLookup[rowId]).map(key => ({
80
+ path: props.getTreeDataPath(params.dataRowIdToModelLookup[rowId]).map(key => ({
80
81
  key,
81
82
  field: null
82
83
  }))
83
- })).sort((a, b) => a.path.length - b.path.length);
84
- return buildRowTree(_extends({
85
- rows
86
- }, params, {
84
+ });
85
+
86
+ const onDuplicatePath = (firstId, secondId, path) => {
87
+ throw new Error(['MUI: The path returned by `getTreeDataPath` should be unique.', `The rows with id #${firstId} and #${secondId} have the same.`, `Path: ${JSON.stringify(path.map(step => step.key))}.`].join('\n'));
88
+ };
89
+
90
+ if (params.updates.type === 'full') {
91
+ return createRowTree({
92
+ nodes: params.updates.rows.map(getRowTreeBuilderNode),
93
+ defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
94
+ isGroupExpandedByDefault: props.isGroupExpandedByDefault,
95
+ groupingName: TREE_DATA_STRATEGY,
96
+ onDuplicatePath
97
+ });
98
+ }
99
+
100
+ return updateRowTree({
101
+ nodes: {
102
+ inserted: params.updates.actions.insert.map(getRowTreeBuilderNode),
103
+ modified: params.updates.actions.modify.map(getRowTreeBuilderNode),
104
+ removed: params.updates.actions.remove
105
+ },
106
+ previousTree: params.previousTree,
107
+ previousTreeDepth: params.previousTreeDepths,
87
108
  defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
88
109
  isGroupExpandedByDefault: props.isGroupExpandedByDefault,
89
- groupingName: TREE_DATA_STRATEGY,
90
- onDuplicatePath: (firstId, secondId, path) => {
91
- throw new Error(['MUI: The path returned by `getTreeDataPath` should be unique.', `The rows with id #${firstId} and #${secondId} have the same.`, `Path: ${JSON.stringify(path.map(step => step.key))}.`].join('\n'));
92
- }
93
- }));
110
+ groupingName: TREE_DATA_STRATEGY
111
+ });
94
112
  }, [props.getTreeDataPath, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
95
113
  const filterRows = React.useCallback(params => {
96
114
  const rowTree = gridRowTreeSelector(apiRef);
@@ -104,16 +122,15 @@ export const useGridTreeDataPreProcessors = (apiRef, props) => {
104
122
  }, [apiRef, props.disableChildrenFiltering]);
105
123
  const sortRows = React.useCallback(params => {
106
124
  const rowTree = gridRowTreeSelector(apiRef);
107
- const rowIds = gridRowIdsSelector(apiRef);
108
125
  return sortRowTree({
109
126
  rowTree,
110
- rowIds,
111
127
  sortRowList: params.sortRowList,
112
- disableChildrenSorting: props.disableChildrenSorting
128
+ disableChildrenSorting: props.disableChildrenSorting,
129
+ shouldRenderGroupBelowLeaves: false
113
130
  });
114
131
  }, [apiRef, props.disableChildrenSorting]);
115
132
  useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
116
- useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'rowTreeCreation', createRowTree);
133
+ useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'rowTreeCreation', createRowTreeForTreeData);
117
134
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'filtering', filterRows);
118
135
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'sorting', sortRows);
119
136
  /**
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.17.5
1
+ /** @license MUI v6.0.0-alpha.1
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -15,5 +15,7 @@ export { useGridTreeDataPreProcessors } from '../hooks/features/treeData/useGrid
15
15
  export { TREE_DATA_STRATEGY } from '../hooks/features/treeData/gridTreeDataUtils';
16
16
  export { useGridRowPinning, rowPinningStateInitializer } from '../hooks/features/rowPinning/useGridRowPinning';
17
17
  export { useGridRowPinningPreProcessors, addPinnedRow } from '../hooks/features/rowPinning/useGridRowPinningPreProcessors';
18
- export { buildRowTree } from '../utils/tree/buildRowTree';
19
- export { sortRowTree } from '../utils/tree/sortRowTree';
18
+ export { createRowTree } from '../utils/tree/createRowTree';
19
+ export { updateRowTree } from '../utils/tree/updateRowTree';
20
+ export { sortRowTree } from '../utils/tree/sortRowTree';
21
+ export { insertNodeInTree, removeNodeFromTree } from '../utils/tree/utils';
@@ -0,0 +1,35 @@
1
+ import { GRID_ROOT_GROUP_ID } from '@mui/x-data-grid';
2
+ import { buildRootGroup } from '@mui/x-data-grid/internals';
3
+ import { insertDataRowInTree } from './insertDataRowInTree';
4
+
5
+ /**
6
+ * Transform a list of rows into a tree structure where each row references its parent and children.
7
+ */
8
+ export const createRowTree = params => {
9
+ const dataRowIds = [];
10
+ const tree = {
11
+ [GRID_ROOT_GROUP_ID]: buildRootGroup()
12
+ };
13
+ const treeDepths = {};
14
+
15
+ for (let i = 0; i < params.nodes.length; i += 1) {
16
+ const node = params.nodes[i];
17
+ dataRowIds.push(node.id);
18
+ insertDataRowInTree({
19
+ tree,
20
+ id: node.id,
21
+ path: node.path,
22
+ onDuplicatePath: params.onDuplicatePath,
23
+ treeDepths,
24
+ isGroupExpandedByDefault: params.isGroupExpandedByDefault,
25
+ defaultGroupingExpansionDepth: params.defaultGroupingExpansionDepth
26
+ });
27
+ }
28
+
29
+ return {
30
+ tree,
31
+ treeDepths,
32
+ groupingName: params.groupingName,
33
+ dataRowIds
34
+ };
35
+ };
@@ -1 +1 @@
1
- export { getGroupRowIdFromPath } from './buildRowTree';
1
+ export { getGroupRowIdFromPath } from './utils';