@mui/x-data-grid-pro 5.11.0 → 5.12.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 (120) hide show
  1. package/CHANGELOG.md +237 -16
  2. package/DataGridPro/DataGridPro.js +26 -27
  3. package/DataGridPro/useDataGridProComponent.js +0 -5
  4. package/DataGridPro/useDataGridProProps.js +6 -27
  5. package/LICENSE +3 -3
  6. package/README.md +3 -4
  7. package/components/DataGridProVirtualScroller.d.ts +1 -1
  8. package/components/DataGridProVirtualScroller.js +6 -3
  9. package/components/GridRowReorderCell.js +6 -6
  10. package/hooks/features/columnPinning/gridColumnPinningInterface.d.ts +6 -0
  11. package/hooks/features/columnPinning/useGridColumnPinning.js +73 -28
  12. package/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +67 -4
  13. package/hooks/features/columnResize/useGridColumnResize.js +32 -15
  14. package/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
  15. package/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  16. package/hooks/features/rowReorder/useGridRowReorderPreProcessors.d.ts +2 -2
  17. package/index.d.ts +0 -2
  18. package/index.js +2 -5
  19. package/legacy/DataGridPro/DataGridPro.js +26 -27
  20. package/legacy/DataGridPro/useDataGridProComponent.js +0 -5
  21. package/legacy/DataGridPro/useDataGridProProps.js +1 -20
  22. package/legacy/components/DataGridProVirtualScroller.js +6 -3
  23. package/legacy/components/GridRowReorderCell.js +8 -6
  24. package/legacy/hooks/features/columnPinning/useGridColumnPinning.js +82 -33
  25. package/legacy/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +70 -5
  26. package/legacy/hooks/features/columnResize/useGridColumnResize.js +32 -15
  27. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
  28. package/legacy/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  29. package/legacy/index.js +2 -5
  30. package/legacy/utils/releaseInfo.js +1 -1
  31. package/models/dataGridProProps.d.ts +0 -26
  32. package/models/gridApiPro.d.ts +1 -2
  33. package/models/gridStatePro.d.ts +0 -3
  34. package/modern/DataGridPro/DataGridPro.js +26 -27
  35. package/modern/DataGridPro/useDataGridProComponent.js +0 -5
  36. package/modern/DataGridPro/useDataGridProProps.js +1 -16
  37. package/modern/components/DataGridProVirtualScroller.js +6 -3
  38. package/modern/components/GridRowReorderCell.js +6 -6
  39. package/modern/hooks/features/columnPinning/useGridColumnPinning.js +73 -28
  40. package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +67 -4
  41. package/modern/hooks/features/columnResize/useGridColumnResize.js +32 -15
  42. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
  43. package/modern/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  44. package/modern/index.js +2 -5
  45. package/modern/utils/releaseInfo.js +1 -1
  46. package/node/DataGridPro/DataGridPro.js +26 -27
  47. package/node/DataGridPro/useDataGridProComponent.js +0 -7
  48. package/node/DataGridPro/useDataGridProProps.js +6 -28
  49. package/node/components/DataGridProVirtualScroller.js +6 -3
  50. package/node/components/GridRowReorderCell.js +6 -6
  51. package/node/hooks/features/columnPinning/useGridColumnPinning.js +72 -24
  52. package/node/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +68 -5
  53. package/node/hooks/features/columnResize/useGridColumnResize.js +32 -14
  54. package/node/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
  55. package/node/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  56. package/node/index.js +2 -30
  57. package/node/utils/releaseInfo.js +1 -1
  58. package/package.json +9 -7
  59. package/typeOverloads/modules.d.ts +9 -21
  60. package/utils/releaseInfo.js +1 -1
  61. package/components/GridGroupingColumnLeafCell.d.ts +0 -4
  62. package/components/GridGroupingColumnLeafCell.js +0 -22
  63. package/components/GridGroupingCriteriaCell.d.ts +0 -7
  64. package/components/GridGroupingCriteriaCell.js +0 -78
  65. package/components/GridRowGroupableColumnMenuItems.d.ts +0 -11
  66. package/components/GridRowGroupableColumnMenuItems.js +0 -63
  67. package/components/GridRowGroupingColumnMenuItems.d.ts +0 -11
  68. package/components/GridRowGroupingColumnMenuItems.js +0 -58
  69. package/hooks/features/rowGrouping/createGroupingColDef.d.ts +0 -43
  70. package/hooks/features/rowGrouping/createGroupingColDef.js +0 -318
  71. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +0 -37
  72. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -1
  73. package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +0 -4
  74. package/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -5
  75. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +0 -27
  76. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -139
  77. package/hooks/features/rowGrouping/index.d.ts +0 -3
  78. package/hooks/features/rowGrouping/index.js +0 -3
  79. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +0 -11
  80. package/hooks/features/rowGrouping/useGridRowGrouping.js +0 -200
  81. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +0 -4
  82. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -203
  83. package/legacy/components/GridGroupingColumnLeafCell.js +0 -20
  84. package/legacy/components/GridGroupingCriteriaCell.js +0 -74
  85. package/legacy/components/GridRowGroupableColumnMenuItems.js +0 -61
  86. package/legacy/components/GridRowGroupingColumnMenuItems.js +0 -56
  87. package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +0 -319
  88. package/legacy/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -1
  89. package/legacy/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -13
  90. package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -147
  91. package/legacy/hooks/features/rowGrouping/index.js +0 -3
  92. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +0 -206
  93. package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -217
  94. package/legacy/models/gridGroupingValueGetterParams.js +0 -1
  95. package/models/gridGroupingValueGetterParams.d.ts +0 -31
  96. package/models/gridGroupingValueGetterParams.js +0 -1
  97. package/modern/components/GridGroupingColumnLeafCell.js +0 -20
  98. package/modern/components/GridGroupingCriteriaCell.js +0 -76
  99. package/modern/components/GridRowGroupableColumnMenuItems.js +0 -61
  100. package/modern/components/GridRowGroupingColumnMenuItems.js +0 -56
  101. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +0 -302
  102. package/modern/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -1
  103. package/modern/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -5
  104. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -137
  105. package/modern/hooks/features/rowGrouping/index.js +0 -3
  106. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +0 -192
  107. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -203
  108. package/modern/models/gridGroupingValueGetterParams.js +0 -1
  109. package/node/components/GridGroupingColumnLeafCell.js +0 -38
  110. package/node/components/GridGroupingCriteriaCell.js +0 -99
  111. package/node/components/GridRowGroupableColumnMenuItems.js +0 -82
  112. package/node/components/GridRowGroupingColumnMenuItems.js +0 -78
  113. package/node/hooks/features/rowGrouping/createGroupingColDef.js +0 -341
  114. package/node/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -5
  115. package/node/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -18
  116. package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -172
  117. package/node/hooks/features/rowGrouping/index.js +0 -51
  118. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +0 -228
  119. package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -227
  120. package/node/models/gridGroupingValueGetterParams.js +0 -5
@@ -1,206 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- import * as React from 'react';
4
- import Divider from '@mui/material/Divider';
5
- import { useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
6
- import { useGridRegisterPipeProcessor, isDeepEqual } from '@mui/x-data-grid/internals';
7
- import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector, gridRowGroupingStateSelector } from './gridRowGroupingSelector';
8
- import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability } from './gridRowGroupingUtils';
9
- import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
10
- import { GridRowGroupingColumnMenuItems } from '../../../components/GridRowGroupingColumnMenuItems';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- export var rowGroupingStateInitializer = function rowGroupingStateInitializer(state, props) {
13
- var _ref, _props$rowGroupingMod, _props$initialState, _props$initialState$r;
14
-
15
- return _extends({}, state, {
16
- rowGrouping: {
17
- model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : [],
18
- unstable_sanitizedModelOnLastRowTreeCreation: []
19
- }
20
- });
21
- };
22
- /**
23
- * @requires useGridColumns (state, method) - can be after, async only
24
- * @requires useGridRows (state, method) - can be after, async only
25
- * @requires useGridParamsApi (method) - can be after, async only
26
- */
27
-
28
- export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
29
- apiRef.current.unstable_updateControlState({
30
- stateId: 'rowGrouping',
31
- propModel: props.rowGroupingModel,
32
- propOnChange: props.onRowGroupingModelChange,
33
- stateSelector: gridRowGroupingModelSelector,
34
- changeEvent: 'rowGroupingModelChange'
35
- });
36
- /**
37
- * API METHODS
38
- */
39
-
40
- var setRowGroupingModel = React.useCallback(function (model) {
41
- var currentModel = gridRowGroupingModelSelector(apiRef);
42
-
43
- if (currentModel !== model) {
44
- apiRef.current.setState(mergeStateWithRowGroupingModel(model));
45
- setStrategyAvailability(apiRef, props.disableRowGrouping);
46
- apiRef.current.forceUpdate();
47
- }
48
- }, [apiRef, props.disableRowGrouping]);
49
- var addRowGroupingCriteria = React.useCallback(function (field, groupingIndex) {
50
- var currentModel = gridRowGroupingModelSelector(apiRef);
51
-
52
- if (currentModel.includes(field)) {
53
- return;
54
- }
55
-
56
- var cleanGroupingIndex = groupingIndex != null ? groupingIndex : currentModel.length;
57
- var updatedModel = [].concat(_toConsumableArray(currentModel.slice(0, cleanGroupingIndex)), [field], _toConsumableArray(currentModel.slice(cleanGroupingIndex)));
58
- apiRef.current.setRowGroupingModel(updatedModel);
59
- }, [apiRef]);
60
- var removeRowGroupingCriteria = React.useCallback(function (field) {
61
- var currentModel = gridRowGroupingModelSelector(apiRef);
62
-
63
- if (!currentModel.includes(field)) {
64
- return;
65
- }
66
-
67
- apiRef.current.setRowGroupingModel(currentModel.filter(function (el) {
68
- return el !== field;
69
- }));
70
- }, [apiRef]);
71
- var setRowGroupingCriteriaIndex = React.useCallback(function (field, targetIndex) {
72
- var currentModel = gridRowGroupingModelSelector(apiRef);
73
- var currentTargetIndex = currentModel.indexOf(field);
74
-
75
- if (currentTargetIndex === -1) {
76
- return;
77
- }
78
-
79
- var updatedModel = _toConsumableArray(currentModel);
80
-
81
- updatedModel.splice(targetIndex, 0, updatedModel.splice(currentTargetIndex, 1)[0]);
82
- apiRef.current.setRowGroupingModel(updatedModel);
83
- }, [apiRef]);
84
- var rowGroupingApi = {
85
- setRowGroupingModel: setRowGroupingModel,
86
- addRowGroupingCriteria: addRowGroupingCriteria,
87
- removeRowGroupingCriteria: removeRowGroupingCriteria,
88
- setRowGroupingCriteriaIndex: setRowGroupingCriteriaIndex
89
- };
90
- useGridApiMethod(apiRef, rowGroupingApi, 'GridRowGroupingApi');
91
- /**
92
- * PRE-PROCESSING
93
- */
94
-
95
- var addColumnMenuButtons = React.useCallback(function (initialValue, columns) {
96
- if (props.disableRowGrouping) {
97
- return initialValue;
98
- }
99
-
100
- var menuItems;
101
-
102
- if (isGroupingColumn(columns.field)) {
103
- menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
104
- } else if (columns.groupable) {
105
- menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
106
- } else {
107
- menuItems = null;
108
- }
109
-
110
- if (menuItems == null) {
111
- return initialValue;
112
- }
113
-
114
- return [].concat(_toConsumableArray(initialValue), [/*#__PURE__*/_jsx(Divider, {}), menuItems]);
115
- }, [props.disableRowGrouping]);
116
- var stateExportPreProcessing = React.useCallback(function (prevState) {
117
- if (props.disableRowGrouping) {
118
- return prevState;
119
- }
120
-
121
- var rowGroupingModelToExport = gridRowGroupingModelSelector(apiRef);
122
-
123
- if (rowGroupingModelToExport.length === 0) {
124
- return prevState;
125
- }
126
-
127
- return _extends({}, prevState, {
128
- rowGrouping: {
129
- model: rowGroupingModelToExport
130
- }
131
- });
132
- }, [apiRef, props.disableRowGrouping]);
133
- var stateRestorePreProcessing = React.useCallback(function (params, context) {
134
- var _context$stateToResto;
135
-
136
- if (props.disableRowGrouping) {
137
- return params;
138
- }
139
-
140
- var rowGroupingModel = (_context$stateToResto = context.stateToRestore.rowGrouping) == null ? void 0 : _context$stateToResto.model;
141
-
142
- if (rowGroupingModel != null) {
143
- apiRef.current.setState(mergeStateWithRowGroupingModel(rowGroupingModel));
144
- }
145
-
146
- return params;
147
- }, [apiRef, props.disableRowGrouping]);
148
- useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
149
- useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
150
- useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
151
- /**
152
- * EVENTS
153
- */
154
-
155
- var handleCellKeyDown = React.useCallback(function (params, event) {
156
- var cellParams = apiRef.current.getCellParams(params.id, params.field);
157
-
158
- if (isGroupingColumn(cellParams.field) && event.key === ' ' && !event.shiftKey) {
159
- var _gridFilteredDescenda;
160
-
161
- event.stopPropagation();
162
- event.preventDefault();
163
- var filteredDescendantCount = (_gridFilteredDescenda = gridFilteredDescendantCountLookupSelector(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
164
- var isOnGroupingCell = props.rowGroupingColumnMode === 'single' || getRowGroupingFieldFromGroupingCriteria(params.rowNode.groupingField) === params.field;
165
-
166
- if (!isOnGroupingCell || filteredDescendantCount === 0) {
167
- return;
168
- }
169
-
170
- apiRef.current.setRowChildrenExpansion(params.id, !params.rowNode.childrenExpanded);
171
- }
172
- }, [apiRef, props.rowGroupingColumnMode]);
173
- var checkGroupingColumnsModelDiff = React.useCallback(function () {
174
- var rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
175
- var lastGroupingColumnsModelApplied = gridRowGroupingStateSelector(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
176
-
177
- if (!isDeepEqual(lastGroupingColumnsModelApplied, rowGroupingModel)) {
178
- apiRef.current.setState(function (state) {
179
- return _extends({}, state, {
180
- rowGrouping: _extends({}, state.rowGrouping, {
181
- unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
182
- })
183
- });
184
- });
185
- apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
186
- setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
187
- // TODO: Add a clean way to re-run a strategy processing without publishing a private event
188
-
189
- if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
190
- apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
191
- }
192
- }
193
- }, [apiRef, props.disableRowGrouping]);
194
- useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
195
- useGridApiEventHandler(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
196
- useGridApiEventHandler(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
197
- /**
198
- * EFFECTS
199
- */
200
-
201
- React.useEffect(function () {
202
- if (props.rowGroupingModel !== undefined) {
203
- apiRef.current.setRowGroupingModel(props.rowGroupingModel);
204
- }
205
- }, [apiRef, props.rowGroupingModel]);
206
- };
@@ -1,217 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- import * as React from 'react';
4
- import { gridColumnLookupSelector, gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
5
- import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
6
- import { sortRowTree } from '../../../utils/tree/sortRowTree';
7
- import { buildRowTree } from '../../../utils/tree/buildRowTree';
8
- import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
9
- import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
10
- import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
11
- export var useGridRowGroupingPreProcessors = function useGridRowGroupingPreProcessors(apiRef, props) {
12
- var getGroupingColDefs = React.useCallback(function (columnsState) {
13
- if (props.disableRowGrouping) {
14
- return [];
15
- }
16
-
17
- var groupingColDefProp = props.groupingColDef; // We can't use `gridGroupingRowsSanitizedModelSelector` here because the new columns are not in the state yet
18
-
19
- var rowGroupingModel = gridRowGroupingModelSelector(apiRef).filter(function (field) {
20
- return !!columnsState.lookup[field];
21
- });
22
-
23
- if (rowGroupingModel.length === 0) {
24
- return [];
25
- }
26
-
27
- switch (props.rowGroupingColumnMode) {
28
- case 'single':
29
- {
30
- return [createGroupingColDefForAllGroupingCriteria({
31
- apiRef: apiRef,
32
- rowGroupingModel: rowGroupingModel,
33
- colDefOverride: getColDefOverrides(groupingColDefProp, rowGroupingModel),
34
- columnsLookup: columnsState.lookup
35
- })];
36
- }
37
-
38
- case 'multiple':
39
- {
40
- return rowGroupingModel.map(function (groupingCriteria) {
41
- return createGroupingColDefForOneGroupingCriteria({
42
- groupingCriteria: groupingCriteria,
43
- colDefOverride: getColDefOverrides(groupingColDefProp, [groupingCriteria]),
44
- groupedByColDef: columnsState.lookup[groupingCriteria],
45
- columnsLookup: columnsState.lookup
46
- });
47
- });
48
- }
49
-
50
- default:
51
- {
52
- return [];
53
- }
54
- }
55
- }, [apiRef, props.groupingColDef, props.rowGroupingColumnMode, props.disableRowGrouping]);
56
- var updateGroupingColumn = React.useCallback(function (columnsState) {
57
- var groupingColDefs = getGroupingColDefs(columnsState);
58
- var newColumnFields = [];
59
- var newColumnsLookup = {}; // We only keep the non-grouping columns
60
-
61
- columnsState.all.forEach(function (field) {
62
- if (!isGroupingColumn(field)) {
63
- newColumnFields.push(field);
64
- newColumnsLookup[field] = columnsState.lookup[field];
65
- }
66
- }); // We add the grouping column
67
-
68
- groupingColDefs.forEach(function (groupingColDef) {
69
- var matchingGroupingColDef = columnsState.lookup[groupingColDef.field];
70
-
71
- if (matchingGroupingColDef) {
72
- groupingColDef.width = matchingGroupingColDef.width;
73
- groupingColDef.flex = matchingGroupingColDef.flex;
74
- }
75
-
76
- newColumnsLookup[groupingColDef.field] = groupingColDef;
77
- });
78
- var startIndex = newColumnFields[0] === '__check__' ? 1 : 0;
79
- newColumnFields = [].concat(_toConsumableArray(newColumnFields.slice(0, startIndex)), _toConsumableArray(groupingColDefs.map(function (colDef) {
80
- return colDef.field;
81
- })), _toConsumableArray(newColumnFields.slice(startIndex)));
82
- columnsState.all = newColumnFields;
83
- columnsState.lookup = newColumnsLookup;
84
- return columnsState;
85
- }, [getGroupingColDefs]);
86
- var createRowTree = React.useCallback(function (params) {
87
- var rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
88
- var columnsLookup = gridColumnLookupSelector(apiRef);
89
- apiRef.current.setState(function (state) {
90
- return _extends({}, state, {
91
- rowGrouping: _extends({}, state.rowGrouping, {
92
- unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
93
- })
94
- });
95
- });
96
- var distinctValues = Object.fromEntries(rowGroupingModel.map(function (groupingField) {
97
- return [groupingField, {
98
- lookup: {},
99
- list: []
100
- }];
101
- }));
102
-
103
- var getCellGroupingCriteria = function getCellGroupingCriteria(_ref) {
104
- var row = _ref.row,
105
- id = _ref.id,
106
- colDef = _ref.colDef;
107
- var key;
108
-
109
- if (colDef.groupingValueGetter) {
110
- var groupingValueGetterParams = {
111
- colDef: colDef,
112
- field: colDef.field,
113
- value: row[colDef.field],
114
- id: id,
115
- row: row,
116
- rowNode: {
117
- isAutoGenerated: false,
118
- id: id
119
- }
120
- };
121
- key = colDef.groupingValueGetter(groupingValueGetterParams);
122
- } else {
123
- key = row[colDef.field];
124
- }
125
-
126
- return {
127
- key: key,
128
- field: colDef.field
129
- };
130
- };
131
-
132
- params.ids.forEach(function (rowId) {
133
- var row = params.idRowsLookup[rowId];
134
- rowGroupingModel.forEach(function (groupingCriteria) {
135
- var _getCellGroupingCrite = getCellGroupingCriteria({
136
- row: row,
137
- id: rowId,
138
- colDef: columnsLookup[groupingCriteria]
139
- }),
140
- key = _getCellGroupingCrite.key;
141
-
142
- var groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
143
-
144
- if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
145
- groupingFieldsDistinctKeys.lookup[key.toString()] = true;
146
- groupingFieldsDistinctKeys.list.push(key);
147
- }
148
- });
149
- });
150
- var rows = params.ids.map(function (rowId) {
151
- var row = params.idRowsLookup[rowId];
152
- var parentPath = rowGroupingModel.map(function (groupingField) {
153
- return getCellGroupingCriteria({
154
- row: row,
155
- id: rowId,
156
- colDef: columnsLookup[groupingField]
157
- });
158
- }).filter(function (cell) {
159
- return cell.key != null;
160
- });
161
- var leafGroupingCriteria = {
162
- key: rowId.toString(),
163
- field: null
164
- };
165
- return {
166
- path: [].concat(_toConsumableArray(parentPath), [leafGroupingCriteria]),
167
- id: rowId
168
- };
169
- });
170
- return buildRowTree(_extends({}, params, {
171
- rows: rows,
172
- defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
173
- isGroupExpandedByDefault: props.isGroupExpandedByDefault,
174
- groupingName: ROW_GROUPING_STRATEGY
175
- }));
176
- }, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
177
- var filterRows = React.useCallback(function (params) {
178
- var rowTree = gridRowTreeSelector(apiRef);
179
- return filterRowTreeFromGroupingColumns({
180
- rowTree: rowTree,
181
- isRowMatchingFilters: params.isRowMatchingFilters
182
- });
183
- }, [apiRef]);
184
- var sortRows = React.useCallback(function (params) {
185
- var rowTree = gridRowTreeSelector(apiRef);
186
- var rowIds = gridRowIdsSelector(apiRef);
187
- return sortRowTree({
188
- rowTree: rowTree,
189
- rowIds: rowIds,
190
- sortRowList: params.sortRowList,
191
- disableChildrenSorting: false
192
- });
193
- }, [apiRef]);
194
- useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
195
- useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
196
- useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'filtering', filterRows);
197
- useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'sorting', sortRows);
198
- /**
199
- * 1ST RENDER
200
- */
201
-
202
- useFirstRender(function () {
203
- setStrategyAvailability(apiRef, props.disableRowGrouping);
204
- });
205
- /**
206
- * EFFECTS
207
- */
208
-
209
- var isFirstRender = React.useRef(true);
210
- React.useEffect(function () {
211
- if (!isFirstRender.current) {
212
- setStrategyAvailability(apiRef, props.disableRowGrouping);
213
- } else {
214
- isFirstRender.current = false;
215
- }
216
- }, [apiRef, props.disableRowGrouping]);
217
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- import { GridRowId, GridRowModel, GridRowTreeNodeConfig, GridColDef, GridStateColDef } from '@mui/x-data-grid';
2
- /**
3
- * Parameters passed to `colDef.groupingValueGetter`.
4
- */
5
- export interface GridGroupingValueGetterParams<V = any, R = any> {
6
- /**
7
- * The grid row id.
8
- */
9
- id: GridRowId;
10
- /**
11
- * The column field of the cell that triggered the event.
12
- */
13
- field: string;
14
- /**
15
- * The cell value, does not take `valueGetter` into account.
16
- */
17
- value: V;
18
- /**
19
- * The row model of the row that the current cell belongs to.
20
- */
21
- row: GridRowModel<R>;
22
- /**
23
- * The column of the row that the current cell belongs to.
24
- */
25
- colDef: GridColDef<R, V, any> | GridStateColDef<R, V, any>;
26
- /**
27
- * The node of the row that the current cell belongs to.
28
- * It only contains the information available before the actual grouping.
29
- */
30
- rowNode: Pick<GridRowTreeNodeConfig, 'id' | 'isAutoGenerated'>;
31
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import Box from '@mui/material/Box';
3
- import { useGridRootProps } from '../hooks/utils/useGridRootProps';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
-
6
- const GridGroupingColumnLeafCell = props => {
7
- const {
8
- rowNode
9
- } = props;
10
- const rootProps = useGridRootProps();
11
- const marginLeft = rootProps.rowGroupingColumnMode === 'multiple' ? 1 : rowNode.depth * 2;
12
- return /*#__PURE__*/_jsx(Box, {
13
- sx: {
14
- ml: marginLeft
15
- },
16
- children: props.formattedValue ?? props.value
17
- });
18
- };
19
-
20
- export { GridGroupingColumnLeafCell };
@@ -1,76 +0,0 @@
1
- import * as React from 'react';
2
- import { unstable_composeClasses as composeClasses } from '@mui/material';
3
- import IconButton from '@mui/material/IconButton';
4
- import Box from '@mui/material/Box';
5
- import { useGridSelector, gridFilteredDescendantCountLookupSelector, getDataGridUtilityClass } from '@mui/x-data-grid';
6
- import { useGridApiContext } from '../hooks/utils/useGridApiContext';
7
- import { useGridRootProps } from '../hooks/utils/useGridRootProps';
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- import { jsxs as _jsxs } from "react/jsx-runtime";
10
-
11
- const useUtilityClasses = ownerState => {
12
- const {
13
- classes
14
- } = ownerState;
15
- const slots = {
16
- root: ['groupingCriteriaCell'],
17
- toggle: ['groupingCriteriaCellToggle']
18
- };
19
- return composeClasses(slots, getDataGridUtilityClass, classes);
20
- };
21
-
22
- export const GridGroupingCriteriaCell = props => {
23
- const {
24
- id,
25
- field,
26
- rowNode,
27
- hideDescendantCount,
28
- formattedValue
29
- } = props;
30
- const rootProps = useGridRootProps();
31
- const apiRef = useGridApiContext();
32
- const ownerState = {
33
- classes: rootProps.classes
34
- };
35
- const classes = useUtilityClasses(ownerState);
36
- const filteredDescendantCountLookup = useGridSelector(apiRef, gridFilteredDescendantCountLookupSelector);
37
- const filteredDescendantCount = filteredDescendantCountLookup[rowNode.id] ?? 0;
38
- const Icon = rowNode.childrenExpanded ? rootProps.components.GroupingCriteriaCollapseIcon : rootProps.components.GroupingCriteriaExpandIcon;
39
-
40
- const handleKeyDown = event => {
41
- if (event.key === ' ') {
42
- event.stopPropagation();
43
- }
44
-
45
- apiRef.current.publishEvent('cellKeyDown', props, event);
46
- };
47
-
48
- const handleClick = event => {
49
- apiRef.current.setRowChildrenExpansion(id, !rowNode.childrenExpanded);
50
- apiRef.current.setCellFocus(id, field);
51
- event.stopPropagation();
52
- };
53
-
54
- const marginLeft = rootProps.rowGroupingColumnMode === 'multiple' ? 0 : rowNode.depth * 2;
55
- return /*#__PURE__*/_jsxs(Box, {
56
- className: classes.root,
57
- sx: {
58
- ml: marginLeft
59
- },
60
- children: [/*#__PURE__*/_jsx("div", {
61
- className: classes.toggle,
62
- children: filteredDescendantCount > 0 && /*#__PURE__*/_jsx(IconButton, {
63
- size: "small",
64
- onClick: handleClick,
65
- onKeyDown: handleKeyDown,
66
- tabIndex: -1,
67
- "aria-label": rowNode.childrenExpanded ? apiRef.current.getLocaleText('treeDataCollapse') : apiRef.current.getLocaleText('treeDataExpand'),
68
- children: /*#__PURE__*/_jsx(Icon, {
69
- fontSize: "inherit"
70
- })
71
- })
72
- }), /*#__PURE__*/_jsxs("span", {
73
- children: [formattedValue === undefined ? rowNode.groupingKey : formattedValue, !hideDescendantCount && filteredDescendantCount > 0 ? ` (${filteredDescendantCount})` : '']
74
- })]
75
- });
76
- };
@@ -1,61 +0,0 @@
1
- import * as React from 'react';
2
- import PropTypes from 'prop-types';
3
- import MenuItem from '@mui/material/MenuItem';
4
- import { gridColumnLookupSelector, useGridSelector } from '@mui/x-data-grid';
5
- import { useGridApiContext } from '../hooks/utils/useGridApiContext';
6
- import { gridRowGroupingSanitizedModelSelector } from '../hooks/features/rowGrouping/gridRowGroupingSelector';
7
- import { jsx as _jsx } from "react/jsx-runtime";
8
-
9
- const GridRowGroupableColumnMenuItems = props => {
10
- const {
11
- column,
12
- onClick
13
- } = props;
14
- const apiRef = useGridApiContext();
15
- const rowGroupingModel = useGridSelector(apiRef, gridRowGroupingSanitizedModelSelector);
16
- const columnsLookup = useGridSelector(apiRef, gridColumnLookupSelector);
17
-
18
- if (!column?.groupable) {
19
- return null;
20
- }
21
-
22
- const ungroupColumn = event => {
23
- apiRef.current.removeRowGroupingCriteria(column.field);
24
-
25
- if (onClick) {
26
- onClick(event);
27
- }
28
- };
29
-
30
- const groupColumn = event => {
31
- apiRef.current.addRowGroupingCriteria(column.field);
32
-
33
- if (onClick) {
34
- onClick(event);
35
- }
36
- };
37
-
38
- const name = columnsLookup[column.field].headerName ?? column.field;
39
-
40
- if (rowGroupingModel.includes(column.field)) {
41
- return /*#__PURE__*/_jsx(MenuItem, {
42
- onClick: ungroupColumn,
43
- children: apiRef.current.getLocaleText('unGroupColumn')(name)
44
- });
45
- }
46
-
47
- return /*#__PURE__*/_jsx(MenuItem, {
48
- onClick: groupColumn,
49
- children: apiRef.current.getLocaleText('groupColumn')(name)
50
- });
51
- };
52
-
53
- process.env.NODE_ENV !== "production" ? GridRowGroupableColumnMenuItems.propTypes = {
54
- // ----------------------------- Warning --------------------------------
55
- // | These PropTypes are generated from the TypeScript type definitions |
56
- // | To update them edit the TypeScript types and run "yarn proptypes" |
57
- // ----------------------------------------------------------------------
58
- column: PropTypes.object,
59
- onClick: PropTypes.func
60
- } : void 0;
61
- export { GridRowGroupableColumnMenuItems };
@@ -1,56 +0,0 @@
1
- import * as React from 'react';
2
- import PropTypes from 'prop-types';
3
- import MenuItem from '@mui/material/MenuItem';
4
- import { useGridSelector, gridColumnLookupSelector } from '@mui/x-data-grid';
5
- import { useGridApiContext } from '../hooks/utils/useGridApiContext';
6
- import { gridRowGroupingSanitizedModelSelector } from '../hooks/features/rowGrouping/gridRowGroupingSelector';
7
- import { getRowGroupingCriteriaFromGroupingField, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, isGroupingColumn } from '../hooks/features/rowGrouping/gridRowGroupingUtils';
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
-
10
- const GridRowGroupingColumnMenuItems = props => {
11
- const {
12
- column,
13
- onClick
14
- } = props;
15
- const apiRef = useGridApiContext();
16
- const rowGroupingModel = useGridSelector(apiRef, gridRowGroupingSanitizedModelSelector);
17
- const columnsLookup = useGridSelector(apiRef, gridColumnLookupSelector);
18
-
19
- const renderUnGroupingMenuItem = field => {
20
- const ungroupColumn = event => {
21
- apiRef.current.removeRowGroupingCriteria(field);
22
-
23
- if (onClick) {
24
- onClick(event);
25
- }
26
- };
27
-
28
- const name = columnsLookup[field].headerName ?? field;
29
- return /*#__PURE__*/_jsx(MenuItem, {
30
- onClick: ungroupColumn,
31
- children: apiRef.current.getLocaleText('unGroupColumn')(name)
32
- }, field);
33
- };
34
-
35
- if (!column || !isGroupingColumn(column.field)) {
36
- return null;
37
- }
38
-
39
- if (column.field === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD) {
40
- return /*#__PURE__*/_jsx(React.Fragment, {
41
- children: rowGroupingModel.map(renderUnGroupingMenuItem)
42
- });
43
- }
44
-
45
- return renderUnGroupingMenuItem(getRowGroupingCriteriaFromGroupingField(column.field));
46
- };
47
-
48
- process.env.NODE_ENV !== "production" ? GridRowGroupingColumnMenuItems.propTypes = {
49
- // ----------------------------- Warning --------------------------------
50
- // | These PropTypes are generated from the TypeScript type definitions |
51
- // | To update them edit the TypeScript types and run "yarn proptypes" |
52
- // ----------------------------------------------------------------------
53
- column: PropTypes.object,
54
- onClick: PropTypes.func
55
- } : void 0;
56
- export { GridRowGroupingColumnMenuItems };