@mui/x-data-grid-pro 5.12.1 → 5.12.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 (46) hide show
  1. package/CHANGELOG.md +45 -2
  2. package/DataGridPro/useDataGridProComponent.js +1 -3
  3. package/components/DataGridProColumnHeaders.js +10 -7
  4. package/hooks/features/columnPinning/useGridColumnPinning.d.ts +1 -1
  5. package/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +2 -2
  6. package/hooks/features/detailPanel/useGridDetailPanel.d.ts +1 -1
  7. package/hooks/features/detailPanel/useGridDetailPanel.js +77 -17
  8. package/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +5 -2
  9. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  10. package/index.js +1 -1
  11. package/internals/index.d.ts +0 -1
  12. package/internals/index.js +0 -1
  13. package/legacy/DataGridPro/useDataGridProComponent.js +1 -3
  14. package/legacy/components/DataGridProColumnHeaders.js +10 -7
  15. package/legacy/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +3 -1
  16. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +77 -17
  17. package/legacy/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +5 -2
  18. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  19. package/legacy/index.js +1 -1
  20. package/legacy/internals/index.js +0 -1
  21. package/legacy/utils/releaseInfo.js +1 -1
  22. package/modern/DataGridPro/useDataGridProComponent.js +1 -3
  23. package/modern/components/DataGridProColumnHeaders.js +11 -6
  24. package/modern/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +2 -2
  25. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +75 -15
  26. package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +5 -2
  27. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  28. package/modern/index.js +1 -1
  29. package/modern/internals/index.js +0 -1
  30. package/modern/utils/releaseInfo.js +1 -1
  31. package/node/DataGridPro/useDataGridProComponent.js +1 -4
  32. package/node/components/DataGridProColumnHeaders.js +11 -7
  33. package/node/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +2 -2
  34. package/node/hooks/features/detailPanel/useGridDetailPanel.js +75 -16
  35. package/node/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +8 -2
  36. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +1 -1
  37. package/node/index.js +1 -1
  38. package/node/internals/index.js +0 -9
  39. package/node/utils/releaseInfo.js +1 -1
  40. package/package.json +3 -3
  41. package/utils/releaseInfo.js +1 -1
  42. package/hooks/features/detailPanel/useGridDetailPanelCache.d.ts +0 -4
  43. package/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -57
  44. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -57
  45. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -57
  46. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -74
package/CHANGELOG.md CHANGED
@@ -3,6 +3,49 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## v5.12.2
7
+
8
+ _Jun 16, 2022_
9
+
10
+ We'd like to offer a big thanks to the 7 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 🚀 Performance improvement for dynamic row height (#5135) @m4theushw
13
+ - 🕒 Add demo of how to use the data grid with date pickers (#5053) @cherniavskii
14
+ - 📚 Documentation improvements
15
+ - 🐞 Bugfixes
16
+
17
+ ### `@mui/x-data-grid@v5.12.2` / `@mui/x-data-grid-pro@v5.12.2` / `@mui/x-data-grid-premium@v5.12.2`
18
+
19
+ #### Changes
20
+
21
+ - [DataGrid] Fix for cosmetic bug on column filter badge (#5170) @simbahandiane
22
+ - [DataGrid] Hide vertical scrollbar if `autoHeight` is enabled (#5164) @m4theushw
23
+ - [DataGrid] Use exponential search to render non-measured rows (#5135) @m4theushw
24
+ - [DataGridPro] Fix label of the detail panel toggle column (#5191) @m4theushw
25
+ - [DataGridPro] Refresh detail panel caches when props change (#5110) @m4theushw
26
+
27
+ ### Docs
28
+
29
+ - [docs] Add example with custom checkbox column (#5161) @flaviendelangle
30
+ - [docs] Batch small changes (#5177) @oliviertassinari
31
+ - [docs] Fix demo currency format (#5034) @oliviertassinari
32
+ - [docs] Fix outdated license description to match the EULA (#5219) @joserodolfofreitas
33
+ - [docs] Fix redundant headers (#5104) @oliviertassinari
34
+ - [docs] Fix some capitalization to match the guidelines (#5105) @oliviertassinari
35
+ - [docs] Improve the `getRowId` doc section (#5156) @flaviendelangle
36
+ - [docs] Instruction to deal with invalid license message (#5074) @joserodolfofreitas
37
+ - [docs] Use redirection in the code (#5114) @oliviertassinari
38
+ - [docs] Add demo of how to use the data grid with date pickers (#5053) @cherniavskii
39
+
40
+ ### Core
41
+
42
+ - [core] Improve inline code rendering within the details tag (#5166) @Harmouch101
43
+ - [core] Remove unused props from plugin typing (#5185) @flaviendelangle
44
+ - [core] Use the scrollbar size from `useGridDimensions` on `DataGridProColumnHeaders` (#5201) @flaviendelangle
45
+ - [core] Fix `GridColTypeDef` type (#5167) @cherniavskii
46
+ - [core] Fix `GridColTypeDef` usage in demo (#5197) @cherniavskii
47
+ - [test] Add `waitFor` before asserting height (#5203) @m4theushw
48
+
6
49
  ## v5.12.1
7
50
 
8
51
  _Jun 9, 2022_
@@ -4084,9 +4127,9 @@ Big thanks to the 8 contributors who made this release possible. Here are some h
4084
4127
 
4085
4128
  ### Docs
4086
4129
 
4087
- - [docs] Data Grid depends on side effects (#666) @oliviertassinari
4130
+ - [docs] Data grid depends on side effects (#666) @oliviertassinari
4088
4131
  - [docs] Clarify the purpose of x-grid-data-generator (#634) @Elius94
4089
- - [docs] Data Grid is in the lab (#612) @oliviertassinari
4132
+ - [docs] Data grid is in the lab (#612) @oliviertassinari
4090
4133
  - [docs] Fix Demo app, downgrade webpack-cli, known issue in latest version (#647) @dtassone
4091
4134
  - [docs] Fix typo in columns.md @stojy
4092
4135
  - [docs] Reduce confusion on /export page (#646) @SerdarMustafa1
@@ -8,7 +8,6 @@ import { useGridTreeDataPreProcessors } from '../hooks/features/treeData/useGrid
8
8
  import { useGridColumnPinning, columnPinningStateInitializer } from '../hooks/features/columnPinning/useGridColumnPinning';
9
9
  import { useGridColumnPinningPreProcessors } from '../hooks/features/columnPinning/useGridColumnPinningPreProcessors';
10
10
  import { useGridDetailPanel, detailPanelStateInitializer } from '../hooks/features/detailPanel/useGridDetailPanel';
11
- import { useGridDetailPanelCache } from '../hooks/features/detailPanel/useGridDetailPanelCache';
12
11
  import { useGridDetailPanelPreProcessors } from '../hooks/features/detailPanel/useGridDetailPanelPreProcessors';
13
12
  import { useGridRowReorder } from '../hooks/features/rowReorder/useGridRowReorder';
14
13
  import { useGridRowReorderPreProcessors } from '../hooks/features/rowReorder/useGridRowReorderPreProcessors';
@@ -51,13 +50,12 @@ export const useDataGridProComponent = (inputApiRef, props) => {
51
50
  useGridTreeData(apiRef);
52
51
  useGridKeyboardNavigation(apiRef, props);
53
52
  useGridSelection(apiRef, props);
54
- useGridDetailPanel(apiRef, props);
55
53
  useGridColumnPinning(apiRef, props);
56
54
  useGridColumns(apiRef, props);
57
55
  useGridRows(apiRef, props);
58
56
  useGridParamsApi(apiRef);
57
+ useGridDetailPanel(apiRef, props);
59
58
  useGridColumnSpanning(apiRef);
60
- useGridDetailPanelCache(apiRef, props);
61
59
  const useGridEditing = (_props$experimentalFe2 = props.experimentalFeatures) != null && _props$experimentalFe2.newEditingApi ? useGridEditing_new : useGridEditing_old;
62
60
  useGridEditing(apiRef, props);
63
61
  useGridFocus(apiRef, props);
@@ -4,6 +4,7 @@ const _excluded = ["style", "className", "innerRef"];
4
4
  import * as React from 'react';
5
5
  import { unstable_composeClasses as composeClasses } from '@mui/material';
6
6
  import { styled, alpha } from '@mui/material/styles';
7
+ import { useEventCallback } from '@mui/material/utils';
7
8
  import { getDataGridUtilityClass, gridClasses, useGridSelector, useGridApiEventHandler, gridVisibleColumnFieldsSelector, GridColumnHeaderSeparatorSides } from '@mui/x-data-grid';
8
9
  import { GridColumnHeaders, GridColumnHeadersInner, useGridColumnHeaders } from '@mui/x-data-grid/internals';
9
10
  import { useGridRootProps } from '../hooks/utils/useGridRootProps';
@@ -76,17 +77,19 @@ export const DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function D
76
77
  const apiRef = useGridApiContext();
77
78
  const visibleColumnFields = useGridSelector(apiRef, gridVisibleColumnFieldsSelector);
78
79
  const [scrollbarSize, setScrollbarSize] = React.useState(0);
79
- const handleContentSizeChange = React.useCallback(() => {
80
- var _apiRef$current$windo;
80
+ const handleContentSizeChange = useEventCallback(() => {
81
+ const rootDimensions = apiRef.current.getRootDimensions();
81
82
 
82
- if (!((_apiRef$current$windo = apiRef.current.windowRef) != null && _apiRef$current$windo.current)) {
83
+ if (!rootDimensions) {
83
84
  return;
84
- } // TODO expose scrollbar size on getRootDimensions
85
+ }
85
86
 
87
+ const newScrollbarSize = rootDimensions.hasScrollY ? rootDimensions.scrollBarSize : 0;
86
88
 
87
- const newScrollbarSize = apiRef.current.windowRef.current.offsetWidth - apiRef.current.windowRef.current.clientWidth;
88
- setScrollbarSize(newScrollbarSize);
89
- }, [apiRef]);
89
+ if (scrollbarSize !== newScrollbarSize) {
90
+ setScrollbarSize(newScrollbarSize);
91
+ }
92
+ });
90
93
  useGridApiEventHandler(apiRef, 'virtualScrollerContentSizeChange', handleContentSizeChange);
91
94
  const pinnedColumns = useGridSelector(apiRef, gridPinnedColumnsSelector);
92
95
  const [leftPinnedColumns, rightPinnedColumns] = filterColumns(pinnedColumns, visibleColumnFields);
@@ -3,4 +3,4 @@ import { GridStateInitializer } from '@mui/x-data-grid/internals';
3
3
  import { GridApiPro } from '../../../models/gridApiPro';
4
4
  import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
5
5
  export declare const columnPinningStateInitializer: GridStateInitializer<Pick<DataGridProProcessedProps, 'pinnedColumns' | 'initialState' | 'disableColumnPinning'>>;
6
- export declare const useGridColumnPinning: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'initialState' | 'disableColumnPinning' | 'pinnedColumns' | 'onPinnedColumnsChange'>) => void;
6
+ export declare const useGridColumnPinning: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'disableColumnPinning' | 'pinnedColumns' | 'onPinnedColumnsChange'>) => void;
@@ -7,7 +7,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
7
7
  export const GRID_DETAIL_PANEL_TOGGLE_FIELD = '__detail_panel_toggle__';
8
8
  export const GRID_DETAIL_PANEL_TOGGLE_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
9
9
  field: GRID_DETAIL_PANEL_TOGGLE_FIELD,
10
- headerName: '',
11
10
  type: 'detailPanelToggle',
12
11
  editable: false,
13
12
  sortable: false,
@@ -22,5 +21,6 @@ export const GRID_DETAIL_PANEL_TOGGLE_COL_DEF = _extends({}, GRID_STRING_COL_DEF
22
21
  const expandedRowIds = gridDetailPanelExpandedRowIdsSelector(params.api.state);
23
22
  return expandedRowIds.includes(params.id);
24
23
  },
25
- renderCell: params => /*#__PURE__*/_jsx(GridDetailPanelToggleCell, _extends({}, params))
24
+ renderCell: params => /*#__PURE__*/_jsx(GridDetailPanelToggleCell, _extends({}, params)),
25
+ renderHeader: () => null
26
26
  });
@@ -3,4 +3,4 @@ import { GridStateInitializer } from '@mui/x-data-grid/internals';
3
3
  import { GridApiPro } from '../../../models/gridApiPro';
4
4
  import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
5
5
  export declare const detailPanelStateInitializer: GridStateInitializer<Pick<DataGridProProcessedProps, 'initialState' | 'detailPanelExpandedRowIds'>>;
6
- export declare const useGridDetailPanel: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'initialState' | 'getDetailPanelContent' | 'getDetailPanelHeight' | 'detailPanelExpandedRowIds' | 'onDetailPanelExpandedRowIdsChange' | 'pagination' | 'paginationMode'>) => void;
6
+ export declare const useGridDetailPanel: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'getDetailPanelContent' | 'getDetailPanelHeight' | 'detailPanelExpandedRowIds' | 'onDetailPanelExpandedRowIdsChange'>) => void;
@@ -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 } from '@mui/x-data-grid';
3
+ import { useGridSelector, useGridApiEventHandler, useGridApiMethod, gridRowIdsSelector } 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 } from './gridDetailPanelSelector';
@@ -13,6 +13,35 @@ export const detailPanelStateInitializer = (state, props) => {
13
13
  }
14
14
  });
15
15
  };
16
+
17
+ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight) {
18
+ if (typeof getDetailPanelContent !== 'function') {
19
+ return {};
20
+ } // TODO change to lazy approach using a Proxy
21
+ // only call getDetailPanelContent when asked for an id
22
+
23
+
24
+ const rowIds = gridRowIdsSelector(apiRef);
25
+ const contentCache = rowIds.reduce((acc, id) => {
26
+ const params = apiRef.current.getRowParams(id);
27
+ acc[id] = getDetailPanelContent(params);
28
+ return acc;
29
+ }, {});
30
+ const heightCache = rowIds.reduce((acc, id) => {
31
+ if (contentCache[id] == null) {
32
+ return acc;
33
+ }
34
+
35
+ const params = apiRef.current.getRowParams(id);
36
+ acc[id] = getDetailPanelHeight(params);
37
+ return acc;
38
+ }, {});
39
+ return {
40
+ contentCache,
41
+ heightCache
42
+ };
43
+ }
44
+
16
45
  export const useGridDetailPanel = (apiRef, props) => {
17
46
  const expandedRowIds = useGridSelector(apiRef, gridDetailPanelExpandedRowIdsSelector);
18
47
  const contentCache = useGridSelector(apiRef, gridDetailPanelExpandedRowsContentCacheSelector);
@@ -51,22 +80,6 @@ export const useGridDetailPanel = (apiRef, props) => {
51
80
  }, [apiRef, props.getDetailPanelContent]);
52
81
  useGridApiEventHandler(apiRef, 'cellClick', handleCellClick);
53
82
  useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
54
- const addDetailHeight = React.useCallback((initialValue, row) => {
55
- var _heightCache$row$id;
56
-
57
- if (expandedRowIds.length === 0 || !expandedRowIds.includes(row.id)) {
58
- return _extends({}, initialValue, {
59
- detail: 0
60
- });
61
- }
62
-
63
- const heightCache = gridDetailPanelExpandedRowsHeightCacheSelector(apiRef.current.state);
64
- return _extends({}, initialValue, {
65
- detail: (_heightCache$row$id = heightCache[row.id]) != null ? _heightCache$row$id : 0 // Fallback to zero because the cache might not be ready yet (e.g. page was changed)
66
-
67
- });
68
- }, [apiRef, expandedRowIds]);
69
- useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
70
83
  apiRef.current.unstable_registerControlState({
71
84
  stateId: 'detailPanels',
72
85
  propModel: props.detailPanelExpandedRowIds,
@@ -114,4 +127,51 @@ export const useGridDetailPanel = (apiRef, props) => {
114
127
  }
115
128
  }
116
129
  }, [apiRef, props.detailPanelExpandedRowIds]);
130
+ const updateCachesAndForceUpdate = React.useCallback(() => {
131
+ apiRef.current.setState(state => {
132
+ return _extends({}, state, {
133
+ detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
134
+ });
135
+ });
136
+ apiRef.current.forceUpdate();
137
+ }, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
138
+ useGridApiEventHandler(apiRef, 'sortedRowsSet', updateCachesAndForceUpdate);
139
+ const previousGetDetailPanelContentProp = React.useRef();
140
+ const previousGetDetailPanelHeightProp = React.useRef();
141
+ const updateCachesIfNeeded = React.useCallback(() => {
142
+ if (props.getDetailPanelContent === previousGetDetailPanelContentProp.current && props.getDetailPanelHeight === previousGetDetailPanelHeightProp.current) {
143
+ return;
144
+ }
145
+
146
+ apiRef.current.setState(state => {
147
+ return _extends({}, state, {
148
+ detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
149
+ });
150
+ });
151
+ previousGetDetailPanelContentProp.current = props.getDetailPanelContent;
152
+ previousGetDetailPanelHeightProp.current = props.getDetailPanelHeight;
153
+ }, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
154
+ const addDetailHeight = React.useCallback((initialValue, row) => {
155
+ var _heightCache$row$id;
156
+
157
+ if (!expandedRowIds || expandedRowIds.length === 0 || !expandedRowIds.includes(row.id)) {
158
+ return _extends({}, initialValue, {
159
+ detail: 0
160
+ });
161
+ }
162
+
163
+ updateCachesIfNeeded();
164
+ const heightCache = gridDetailPanelExpandedRowsHeightCacheSelector(apiRef.current.state);
165
+ return _extends({}, initialValue, {
166
+ detail: (_heightCache$row$id = heightCache[row.id]) != null ? _heightCache$row$id : 0 // Fallback to zero because the cache might not be ready yet (e.g. page was changed)
167
+
168
+ });
169
+ }, [apiRef, expandedRowIds, updateCachesIfNeeded]);
170
+ useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
171
+ const isFirstRender = React.useRef(true);
172
+
173
+ if (isFirstRender.current) {
174
+ isFirstRender.current = false;
175
+ updateCachesIfNeeded();
176
+ }
117
177
  };
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
2
3
  import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
3
4
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD, GRID_DETAIL_PANEL_TOGGLE_COL_DEF } from './gridDetailPanelToggleColDef';
@@ -21,8 +22,10 @@ export const useGridDetailPanelPreProcessors = (apiRef, props) => {
21
22
 
22
23
 
23
24
  columnsState.all = [GRID_DETAIL_PANEL_TOGGLE_FIELD, ...columnsState.all];
24
- columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = GRID_DETAIL_PANEL_TOGGLE_COL_DEF;
25
+ columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = _extends({}, GRID_DETAIL_PANEL_TOGGLE_COL_DEF, {
26
+ headerName: apiRef.current.getLocaleText('detailPanelToggle')
27
+ });
25
28
  return columnsState;
26
- }, [props.getDetailPanelContent]);
29
+ }, [apiRef, props.getDetailPanelContent]);
27
30
  useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', addToggleColumn);
28
31
  };
@@ -2,7 +2,7 @@ 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 } from '@mui/x-data-grid';
5
+ import { gridRowIdsSelector, 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';
@@ -61,7 +61,7 @@ export const useGridTreeDataPreProcessors = (apiRef, props) => {
61
61
  columnsState.lookup[groupingColDefField] = newGroupingColumn;
62
62
 
63
63
  if (prevGroupingColumn == null) {
64
- const index = columnsState.all[0] === '__check__' ? 1 : 0;
64
+ const index = columnsState.all[0] === GRID_CHECKBOX_SELECTION_FIELD ? 1 : 0;
65
65
  columnsState.all = [...columnsState.all.slice(0, index), groupingColDefField, ...columnsState.all.slice(index)];
66
66
  }
67
67
  } else if (!shouldHaveGroupingColumn && prevGroupingColumn) {
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.12.1
1
+ /** @license MUI v5.12.2
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.
@@ -6,7 +6,6 @@ export { useGridColumnPinning, columnPinningStateInitializer, } from '../hooks/f
6
6
  export { useGridColumnPinningPreProcessors } from '../hooks/features/columnPinning/useGridColumnPinningPreProcessors';
7
7
  export { useGridColumnReorder, columnReorderStateInitializer, } from '../hooks/features/columnReorder/useGridColumnReorder';
8
8
  export { useGridDetailPanel, detailPanelStateInitializer, } from '../hooks/features/detailPanel/useGridDetailPanel';
9
- export { useGridDetailPanelCache } from '../hooks/features/detailPanel/useGridDetailPanelCache';
10
9
  export { useGridDetailPanelPreProcessors } from '../hooks/features/detailPanel/useGridDetailPanelPreProcessors';
11
10
  export { useGridInfiniteLoader } from '../hooks/features/infiniteLoader/useGridInfiniteLoader';
12
11
  export { useGridRowReorder } from '../hooks/features/rowReorder/useGridRowReorder';
@@ -6,7 +6,6 @@ export { useGridColumnPinning, columnPinningStateInitializer } from '../hooks/fe
6
6
  export { useGridColumnPinningPreProcessors } from '../hooks/features/columnPinning/useGridColumnPinningPreProcessors';
7
7
  export { useGridColumnReorder, columnReorderStateInitializer } from '../hooks/features/columnReorder/useGridColumnReorder';
8
8
  export { useGridDetailPanel, detailPanelStateInitializer } from '../hooks/features/detailPanel/useGridDetailPanel';
9
- export { useGridDetailPanelCache } from '../hooks/features/detailPanel/useGridDetailPanelCache';
10
9
  export { useGridDetailPanelPreProcessors } from '../hooks/features/detailPanel/useGridDetailPanelPreProcessors';
11
10
  export { useGridInfiniteLoader } from '../hooks/features/infiniteLoader/useGridInfiniteLoader';
12
11
  export { useGridRowReorder } from '../hooks/features/rowReorder/useGridRowReorder';
@@ -8,7 +8,6 @@ import { useGridTreeDataPreProcessors } from '../hooks/features/treeData/useGrid
8
8
  import { useGridColumnPinning, columnPinningStateInitializer } from '../hooks/features/columnPinning/useGridColumnPinning';
9
9
  import { useGridColumnPinningPreProcessors } from '../hooks/features/columnPinning/useGridColumnPinningPreProcessors';
10
10
  import { useGridDetailPanel, detailPanelStateInitializer } from '../hooks/features/detailPanel/useGridDetailPanel';
11
- import { useGridDetailPanelCache } from '../hooks/features/detailPanel/useGridDetailPanelCache';
12
11
  import { useGridDetailPanelPreProcessors } from '../hooks/features/detailPanel/useGridDetailPanelPreProcessors';
13
12
  import { useGridRowReorder } from '../hooks/features/rowReorder/useGridRowReorder';
14
13
  import { useGridRowReorderPreProcessors } from '../hooks/features/rowReorder/useGridRowReorderPreProcessors';
@@ -51,13 +50,12 @@ export var useDataGridProComponent = function useDataGridProComponent(inputApiRe
51
50
  useGridTreeData(apiRef);
52
51
  useGridKeyboardNavigation(apiRef, props);
53
52
  useGridSelection(apiRef, props);
54
- useGridDetailPanel(apiRef, props);
55
53
  useGridColumnPinning(apiRef, props);
56
54
  useGridColumns(apiRef, props);
57
55
  useGridRows(apiRef, props);
58
56
  useGridParamsApi(apiRef);
57
+ useGridDetailPanel(apiRef, props);
59
58
  useGridColumnSpanning(apiRef);
60
- useGridDetailPanelCache(apiRef, props);
61
59
  var useGridEditing = (_props$experimentalFe2 = props.experimentalFeatures) != null && _props$experimentalFe2.newEditingApi ? useGridEditing_new : useGridEditing_old;
62
60
  useGridEditing(apiRef, props);
63
61
  useGridFocus(apiRef, props);
@@ -6,6 +6,7 @@ var _excluded = ["style", "className", "innerRef"];
6
6
  import * as React from 'react';
7
7
  import { unstable_composeClasses as composeClasses } from '@mui/material';
8
8
  import { styled, alpha } from '@mui/material/styles';
9
+ import { useEventCallback } from '@mui/material/utils';
9
10
  import { getDataGridUtilityClass, gridClasses, useGridSelector, useGridApiEventHandler, gridVisibleColumnFieldsSelector, GridColumnHeaderSeparatorSides } from '@mui/x-data-grid';
10
11
  import { GridColumnHeaders, GridColumnHeadersInner, useGridColumnHeaders } from '@mui/x-data-grid/internals';
11
12
  import { useGridRootProps } from '../hooks/utils/useGridRootProps';
@@ -79,17 +80,19 @@ export var DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function Dat
79
80
  scrollbarSize = _React$useState2[0],
80
81
  setScrollbarSize = _React$useState2[1];
81
82
 
82
- var handleContentSizeChange = React.useCallback(function () {
83
- var _apiRef$current$windo;
83
+ var handleContentSizeChange = useEventCallback(function () {
84
+ var rootDimensions = apiRef.current.getRootDimensions();
84
85
 
85
- if (!((_apiRef$current$windo = apiRef.current.windowRef) != null && _apiRef$current$windo.current)) {
86
+ if (!rootDimensions) {
86
87
  return;
87
- } // TODO expose scrollbar size on getRootDimensions
88
+ }
88
89
 
90
+ var newScrollbarSize = rootDimensions.hasScrollY ? rootDimensions.scrollBarSize : 0;
89
91
 
90
- var newScrollbarSize = apiRef.current.windowRef.current.offsetWidth - apiRef.current.windowRef.current.clientWidth;
91
- setScrollbarSize(newScrollbarSize);
92
- }, [apiRef]);
92
+ if (scrollbarSize !== newScrollbarSize) {
93
+ setScrollbarSize(newScrollbarSize);
94
+ }
95
+ });
93
96
  useGridApiEventHandler(apiRef, 'virtualScrollerContentSizeChange', handleContentSizeChange);
94
97
  var pinnedColumns = useGridSelector(apiRef, gridPinnedColumnsSelector);
95
98
 
@@ -7,7 +7,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
7
7
  export var GRID_DETAIL_PANEL_TOGGLE_FIELD = '__detail_panel_toggle__';
8
8
  export var GRID_DETAIL_PANEL_TOGGLE_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
9
9
  field: GRID_DETAIL_PANEL_TOGGLE_FIELD,
10
- headerName: '',
11
10
  type: 'detailPanelToggle',
12
11
  editable: false,
13
12
  sortable: false,
@@ -24,5 +23,8 @@ export var GRID_DETAIL_PANEL_TOGGLE_COL_DEF = _extends({}, GRID_STRING_COL_DEF,
24
23
  },
25
24
  renderCell: function renderCell(params) {
26
25
  return /*#__PURE__*/_jsx(GridDetailPanelToggleCell, _extends({}, params));
26
+ },
27
+ renderHeader: function renderHeader() {
28
+ return null;
27
29
  }
28
30
  });
@@ -1,7 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import * as React from 'react';
4
- import { useGridSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid';
4
+ import { useGridSelector, useGridApiEventHandler, useGridApiMethod, gridRowIdsSelector } from '@mui/x-data-grid';
5
5
  import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
6
6
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from './gridDetailPanelToggleColDef';
7
7
  import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector } from './gridDetailPanelSelector';
@@ -14,6 +14,35 @@ export var detailPanelStateInitializer = function detailPanelStateInitializer(st
14
14
  }
15
15
  });
16
16
  };
17
+
18
+ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight) {
19
+ if (typeof getDetailPanelContent !== 'function') {
20
+ return {};
21
+ } // TODO change to lazy approach using a Proxy
22
+ // only call getDetailPanelContent when asked for an id
23
+
24
+
25
+ var rowIds = gridRowIdsSelector(apiRef);
26
+ var contentCache = rowIds.reduce(function (acc, id) {
27
+ var params = apiRef.current.getRowParams(id);
28
+ acc[id] = getDetailPanelContent(params);
29
+ return acc;
30
+ }, {});
31
+ var heightCache = rowIds.reduce(function (acc, id) {
32
+ if (contentCache[id] == null) {
33
+ return acc;
34
+ }
35
+
36
+ var params = apiRef.current.getRowParams(id);
37
+ acc[id] = getDetailPanelHeight(params);
38
+ return acc;
39
+ }, {});
40
+ return {
41
+ contentCache: contentCache,
42
+ heightCache: heightCache
43
+ };
44
+ }
45
+
17
46
  export var useGridDetailPanel = function useGridDetailPanel(apiRef, props) {
18
47
  var expandedRowIds = useGridSelector(apiRef, gridDetailPanelExpandedRowIdsSelector);
19
48
  var contentCache = useGridSelector(apiRef, gridDetailPanelExpandedRowsContentCacheSelector);
@@ -52,22 +81,6 @@ export var useGridDetailPanel = function useGridDetailPanel(apiRef, props) {
52
81
  }, [apiRef, props.getDetailPanelContent]);
53
82
  useGridApiEventHandler(apiRef, 'cellClick', handleCellClick);
54
83
  useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
55
- var addDetailHeight = React.useCallback(function (initialValue, row) {
56
- var _heightCache$row$id;
57
-
58
- if (expandedRowIds.length === 0 || !expandedRowIds.includes(row.id)) {
59
- return _extends({}, initialValue, {
60
- detail: 0
61
- });
62
- }
63
-
64
- var heightCache = gridDetailPanelExpandedRowsHeightCacheSelector(apiRef.current.state);
65
- return _extends({}, initialValue, {
66
- detail: (_heightCache$row$id = heightCache[row.id]) != null ? _heightCache$row$id : 0 // Fallback to zero because the cache might not be ready yet (e.g. page was changed)
67
-
68
- });
69
- }, [apiRef, expandedRowIds]);
70
- useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
71
84
  apiRef.current.unstable_registerControlState({
72
85
  stateId: 'detailPanels',
73
86
  propModel: props.detailPanelExpandedRowIds,
@@ -119,4 +132,51 @@ export var useGridDetailPanel = function useGridDetailPanel(apiRef, props) {
119
132
  }
120
133
  }
121
134
  }, [apiRef, props.detailPanelExpandedRowIds]);
135
+ var updateCachesAndForceUpdate = React.useCallback(function () {
136
+ apiRef.current.setState(function (state) {
137
+ return _extends({}, state, {
138
+ detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
139
+ });
140
+ });
141
+ apiRef.current.forceUpdate();
142
+ }, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
143
+ useGridApiEventHandler(apiRef, 'sortedRowsSet', updateCachesAndForceUpdate);
144
+ var previousGetDetailPanelContentProp = React.useRef();
145
+ var previousGetDetailPanelHeightProp = React.useRef();
146
+ var updateCachesIfNeeded = React.useCallback(function () {
147
+ if (props.getDetailPanelContent === previousGetDetailPanelContentProp.current && props.getDetailPanelHeight === previousGetDetailPanelHeightProp.current) {
148
+ return;
149
+ }
150
+
151
+ apiRef.current.setState(function (state) {
152
+ return _extends({}, state, {
153
+ detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
154
+ });
155
+ });
156
+ previousGetDetailPanelContentProp.current = props.getDetailPanelContent;
157
+ previousGetDetailPanelHeightProp.current = props.getDetailPanelHeight;
158
+ }, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
159
+ var addDetailHeight = React.useCallback(function (initialValue, row) {
160
+ var _heightCache$row$id;
161
+
162
+ if (!expandedRowIds || expandedRowIds.length === 0 || !expandedRowIds.includes(row.id)) {
163
+ return _extends({}, initialValue, {
164
+ detail: 0
165
+ });
166
+ }
167
+
168
+ updateCachesIfNeeded();
169
+ var heightCache = gridDetailPanelExpandedRowsHeightCacheSelector(apiRef.current.state);
170
+ return _extends({}, initialValue, {
171
+ detail: (_heightCache$row$id = heightCache[row.id]) != null ? _heightCache$row$id : 0 // Fallback to zero because the cache might not be ready yet (e.g. page was changed)
172
+
173
+ });
174
+ }, [apiRef, expandedRowIds, updateCachesIfNeeded]);
175
+ useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
176
+ var isFirstRender = React.useRef(true);
177
+
178
+ if (isFirstRender.current) {
179
+ isFirstRender.current = false;
180
+ updateCachesIfNeeded();
181
+ }
122
182
  };
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import * as React from 'react';
3
4
  import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
@@ -24,8 +25,10 @@ export var useGridDetailPanelPreProcessors = function useGridDetailPanelPreProce
24
25
 
25
26
 
26
27
  columnsState.all = [GRID_DETAIL_PANEL_TOGGLE_FIELD].concat(_toConsumableArray(columnsState.all));
27
- columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = GRID_DETAIL_PANEL_TOGGLE_COL_DEF;
28
+ columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = _extends({}, GRID_DETAIL_PANEL_TOGGLE_COL_DEF, {
29
+ headerName: apiRef.current.getLocaleText('detailPanelToggle')
30
+ });
28
31
  return columnsState;
29
- }, [props.getDetailPanelContent]);
32
+ }, [apiRef, props.getDetailPanelContent]);
30
33
  useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', addToggleColumn);
31
34
  };
@@ -3,7 +3,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
4
  var _excluded = ["hideDescendantCount"];
5
5
  import * as React from 'react';
6
- import { gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
6
+ import { gridRowIdsSelector, gridRowTreeSelector, useFirstRender, GRID_CHECKBOX_SELECTION_FIELD } from '@mui/x-data-grid';
7
7
  import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
8
8
  import { GRID_TREE_DATA_GROUPING_COL_DEF, GRID_TREE_DATA_GROUPING_COL_DEF_FORCED_PROPERTIES } from './gridTreeDataGroupColDef';
9
9
  import { filterRowTreeFromTreeData, TREE_DATA_STRATEGY } from './gridTreeDataUtils';
@@ -66,7 +66,7 @@ export var useGridTreeDataPreProcessors = function useGridTreeDataPreProcessors(
66
66
  columnsState.lookup[groupingColDefField] = newGroupingColumn;
67
67
 
68
68
  if (prevGroupingColumn == null) {
69
- var index = columnsState.all[0] === '__check__' ? 1 : 0;
69
+ var index = columnsState.all[0] === GRID_CHECKBOX_SELECTION_FIELD ? 1 : 0;
70
70
  columnsState.all = [].concat(_toConsumableArray(columnsState.all.slice(0, index)), [groupingColDefField], _toConsumableArray(columnsState.all.slice(index)));
71
71
  }
72
72
  } else if (!shouldHaveGroupingColumn && prevGroupingColumn) {
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.12.1
1
+ /** @license MUI v5.12.2
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.
@@ -6,7 +6,6 @@ export { useGridColumnPinning, columnPinningStateInitializer } from '../hooks/fe
6
6
  export { useGridColumnPinningPreProcessors } from '../hooks/features/columnPinning/useGridColumnPinningPreProcessors';
7
7
  export { useGridColumnReorder, columnReorderStateInitializer } from '../hooks/features/columnReorder/useGridColumnReorder';
8
8
  export { useGridDetailPanel, detailPanelStateInitializer } from '../hooks/features/detailPanel/useGridDetailPanel';
9
- export { useGridDetailPanelCache } from '../hooks/features/detailPanel/useGridDetailPanelCache';
10
9
  export { useGridDetailPanelPreProcessors } from '../hooks/features/detailPanel/useGridDetailPanelPreProcessors';
11
10
  export { useGridInfiniteLoader } from '../hooks/features/infiniteLoader/useGridInfiniteLoader';
12
11
  export { useGridRowReorder } from '../hooks/features/rowReorder/useGridRowReorder';
@@ -1,6 +1,6 @@
1
1
  import { ponyfillGlobal } from '@mui/utils';
2
2
  export var getReleaseInfo = function getReleaseInfo() {
3
- var releaseInfo = "MTY1NDgxMjAwMDAwMA==";
3
+ var releaseInfo = "MTY1NTMzMDQwMDAwMA==";
4
4
 
5
5
  if (process.env.NODE_ENV !== 'production') {
6
6
  // A simple hack to set the value in the test environment (has no build step).
@@ -8,7 +8,6 @@ import { useGridTreeDataPreProcessors } from '../hooks/features/treeData/useGrid
8
8
  import { useGridColumnPinning, columnPinningStateInitializer } from '../hooks/features/columnPinning/useGridColumnPinning';
9
9
  import { useGridColumnPinningPreProcessors } from '../hooks/features/columnPinning/useGridColumnPinningPreProcessors';
10
10
  import { useGridDetailPanel, detailPanelStateInitializer } from '../hooks/features/detailPanel/useGridDetailPanel';
11
- import { useGridDetailPanelCache } from '../hooks/features/detailPanel/useGridDetailPanelCache';
12
11
  import { useGridDetailPanelPreProcessors } from '../hooks/features/detailPanel/useGridDetailPanelPreProcessors';
13
12
  import { useGridRowReorder } from '../hooks/features/rowReorder/useGridRowReorder';
14
13
  import { useGridRowReorderPreProcessors } from '../hooks/features/rowReorder/useGridRowReorderPreProcessors';
@@ -49,13 +48,12 @@ export const useDataGridProComponent = (inputApiRef, props) => {
49
48
  useGridTreeData(apiRef);
50
49
  useGridKeyboardNavigation(apiRef, props);
51
50
  useGridSelection(apiRef, props);
52
- useGridDetailPanel(apiRef, props);
53
51
  useGridColumnPinning(apiRef, props);
54
52
  useGridColumns(apiRef, props);
55
53
  useGridRows(apiRef, props);
56
54
  useGridParamsApi(apiRef);
55
+ useGridDetailPanel(apiRef, props);
57
56
  useGridColumnSpanning(apiRef);
58
- useGridDetailPanelCache(apiRef, props);
59
57
  const useGridEditing = props.experimentalFeatures?.newEditingApi ? useGridEditing_new : useGridEditing_old;
60
58
  useGridEditing(apiRef, props);
61
59
  useGridFocus(apiRef, props);