@mui/x-data-grid-premium 8.0.0-alpha.1 → 8.0.0-alpha.10

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 (119) hide show
  1. package/CHANGELOG.md +1903 -231
  2. package/DataGridPremium/DataGridPremium.js +40 -40
  3. package/DataGridPremium/useDataGridPremiumComponent.d.ts +2 -2
  4. package/DataGridPremium/useDataGridPremiumComponent.js +4 -2
  5. package/DataGridPremium/useDataGridPremiumProps.js +5 -3
  6. package/README.md +1 -1
  7. package/components/GridAggregationHeader.js +6 -1
  8. package/components/GridColumnMenuAggregationItem.js +77 -49
  9. package/components/GridColumnMenuRowGroupItem.js +5 -11
  10. package/components/GridColumnMenuRowUngroupItem.js +10 -19
  11. package/components/GridDataSourceGroupingCriteriaCell.js +1 -2
  12. package/components/GridPremiumColumnMenu.d.ts +1 -1
  13. package/components/GridPremiumColumnMenu.js +5 -5
  14. package/components/promptControl/GridToolbarPromptControl.js +47 -36
  15. package/esm/DataGridPremium/DataGridPremium.js +42 -42
  16. package/esm/DataGridPremium/useDataGridPremiumComponent.js +5 -3
  17. package/esm/DataGridPremium/useDataGridPremiumProps.js +6 -4
  18. package/esm/components/GridAggregationHeader.js +6 -1
  19. package/esm/components/GridColumnMenuAggregationItem.js +75 -47
  20. package/esm/components/GridColumnMenuRowGroupItem.js +6 -11
  21. package/esm/components/GridColumnMenuRowUngroupItem.js +11 -19
  22. package/esm/components/GridDataSourceGroupingCriteriaCell.js +1 -2
  23. package/esm/components/GridPremiumColumnMenu.js +5 -5
  24. package/esm/components/promptControl/GridToolbarPromptControl.js +47 -36
  25. package/esm/hooks/features/aggregation/createAggregationLookup.js +52 -55
  26. package/esm/hooks/features/aggregation/gridAggregationUtils.js +17 -13
  27. package/esm/hooks/features/aggregation/index.js +0 -1
  28. package/esm/hooks/features/aggregation/useGridAggregation.js +22 -10
  29. package/esm/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
  30. package/esm/hooks/features/cellSelection/useGridCellSelection.js +5 -6
  31. package/esm/hooks/features/clipboard/useGridClipboardImport.js +1 -1
  32. package/esm/hooks/features/dataSource/cache.js +3 -0
  33. package/esm/hooks/features/dataSource/models.js +1 -0
  34. package/esm/hooks/features/dataSource/useGridDataSourcePremium.js +53 -0
  35. package/esm/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
  36. package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +2 -2
  37. package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +2 -2
  38. package/esm/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
  39. package/esm/hooks/utils/useGridAriaAttributes.js +1 -3
  40. package/esm/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
  41. package/esm/utils/releaseInfo.js +1 -1
  42. package/hooks/features/aggregation/createAggregationLookup.d.ts +7 -6
  43. package/hooks/features/aggregation/createAggregationLookup.js +52 -55
  44. package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +18 -5
  45. package/hooks/features/aggregation/gridAggregationSelectors.d.ts +2 -2
  46. package/hooks/features/aggregation/gridAggregationUtils.d.ts +12 -13
  47. package/hooks/features/aggregation/gridAggregationUtils.js +17 -13
  48. package/hooks/features/aggregation/index.d.ts +1 -1
  49. package/hooks/features/aggregation/index.js +0 -12
  50. package/hooks/features/aggregation/useGridAggregation.d.ts +2 -2
  51. package/hooks/features/aggregation/useGridAggregation.js +22 -10
  52. package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +2 -2
  53. package/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
  54. package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +3 -2
  55. package/hooks/features/cellSelection/gridCellSelectionInterfaces.d.ts +3 -3
  56. package/hooks/features/cellSelection/useGridCellSelection.d.ts +2 -2
  57. package/hooks/features/cellSelection/useGridCellSelection.js +4 -5
  58. package/hooks/features/clipboard/useGridClipboardImport.d.ts +2 -2
  59. package/hooks/features/clipboard/useGridClipboardImport.js +1 -1
  60. package/hooks/features/dataSource/cache.d.ts +2 -0
  61. package/hooks/features/dataSource/cache.js +9 -0
  62. package/hooks/features/dataSource/models.d.ts +47 -0
  63. package/hooks/features/dataSource/models.js +5 -0
  64. package/hooks/features/dataSource/useGridDataSourcePremium.d.ts +4 -0
  65. package/hooks/features/dataSource/useGridDataSourcePremium.js +62 -0
  66. package/hooks/features/export/serializer/excelSerializer.d.ts +3 -2
  67. package/hooks/features/export/useGridExcelExport.d.ts +2 -2
  68. package/hooks/features/rowGrouping/createGroupingColDef.d.ts +2 -2
  69. package/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
  70. package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +2 -2
  71. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +4 -4
  72. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +1 -1
  73. package/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.d.ts +2 -2
  74. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +2 -2
  75. package/hooks/features/rowGrouping/useGridRowGrouping.js +1 -1
  76. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +2 -2
  77. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
  78. package/hooks/utils/useGridApiContext.d.ts +1 -1
  79. package/hooks/utils/useGridApiRef.d.ts +3 -1
  80. package/hooks/utils/useGridAriaAttributes.js +1 -3
  81. package/hooks/utils/useGridPrivateApiContext.d.ts +1 -1
  82. package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +2 -2
  83. package/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
  84. package/index.d.ts +2 -0
  85. package/index.js +1 -1
  86. package/models/dataGridPremiumProps.d.ts +8 -12
  87. package/models/gridApiPremium.d.ts +5 -3
  88. package/models/gridGroupingValueGetter.d.ts +2 -1
  89. package/models/gridPastedValueParser.d.ts +2 -1
  90. package/modern/DataGridPremium/DataGridPremium.js +42 -42
  91. package/modern/DataGridPremium/useDataGridPremiumComponent.js +5 -3
  92. package/modern/DataGridPremium/useDataGridPremiumProps.js +6 -4
  93. package/modern/components/GridAggregationHeader.js +6 -1
  94. package/modern/components/GridColumnMenuAggregationItem.js +75 -47
  95. package/modern/components/GridColumnMenuRowGroupItem.js +6 -11
  96. package/modern/components/GridColumnMenuRowUngroupItem.js +11 -19
  97. package/modern/components/GridDataSourceGroupingCriteriaCell.js +1 -2
  98. package/modern/components/GridPremiumColumnMenu.js +5 -5
  99. package/modern/components/promptControl/GridToolbarPromptControl.js +47 -36
  100. package/modern/hooks/features/aggregation/createAggregationLookup.js +52 -55
  101. package/modern/hooks/features/aggregation/gridAggregationUtils.js +17 -13
  102. package/modern/hooks/features/aggregation/index.js +0 -1
  103. package/modern/hooks/features/aggregation/useGridAggregation.js +22 -10
  104. package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
  105. package/modern/hooks/features/cellSelection/useGridCellSelection.js +5 -6
  106. package/modern/hooks/features/clipboard/useGridClipboardImport.js +1 -1
  107. package/modern/hooks/features/dataSource/cache.js +3 -0
  108. package/modern/hooks/features/dataSource/models.js +1 -0
  109. package/modern/hooks/features/dataSource/useGridDataSourcePremium.js +53 -0
  110. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
  111. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +2 -2
  112. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +2 -2
  113. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
  114. package/modern/hooks/utils/useGridAriaAttributes.js +1 -3
  115. package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
  116. package/modern/index.js +1 -1
  117. package/modern/utils/releaseInfo.js +1 -1
  118. package/package.json +6 -6
  119. package/utils/releaseInfo.js +1 -1
@@ -1,12 +1,10 @@
1
1
  import * as React from 'react';
2
- import ListItemIcon from '@mui/material/ListItemIcon';
3
- import ListItemText from '@mui/material/ListItemText';
4
2
  import { useGridSelector, gridColumnLookupSelector } from '@mui/x-data-grid-pro';
5
3
  import { useGridApiContext } from "../hooks/utils/useGridApiContext.js";
6
4
  import { gridRowGroupingSanitizedModelSelector } from "../hooks/features/rowGrouping/gridRowGroupingSelector.js";
7
5
  import { getRowGroupingCriteriaFromGroupingField, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, isGroupingColumn } from "../hooks/features/rowGrouping/gridRowGroupingUtils.js";
8
6
  import { useGridRootProps } from "../hooks/utils/useGridRootProps.js";
9
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
10
8
  export function GridColumnMenuRowGroupItem(props) {
11
9
  const {
12
10
  colDef,
@@ -23,16 +21,13 @@ export function GridColumnMenuRowGroupItem(props) {
23
21
  };
24
22
  const groupedColumn = columnsLookup[field];
25
23
  const name = groupedColumn.headerName ?? field;
26
- return /*#__PURE__*/_jsxs(rootProps.slots.baseMenuItem, {
24
+ return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, {
27
25
  onClick: ungroupColumn,
28
26
  disabled: !groupedColumn.groupable,
29
- children: [/*#__PURE__*/_jsx(ListItemIcon, {
30
- children: /*#__PURE__*/_jsx(rootProps.slots.columnMenuUngroupIcon, {
31
- fontSize: "small"
32
- })
33
- }), /*#__PURE__*/_jsx(ListItemText, {
34
- children: apiRef.current.getLocaleText('unGroupColumn')(name)
35
- })]
27
+ iconStart: /*#__PURE__*/_jsx(rootProps.slots.columnMenuUngroupIcon, {
28
+ fontSize: "small"
29
+ }),
30
+ children: apiRef.current.getLocaleText('unGroupColumn')(name)
36
31
  }, field);
37
32
  };
38
33
  if (!colDef || !isGroupingColumn(colDef.field)) {
@@ -1,11 +1,9 @@
1
1
  import * as React from 'react';
2
- import ListItemIcon from '@mui/material/ListItemIcon';
3
- import ListItemText from '@mui/material/ListItemText';
4
2
  import { gridColumnLookupSelector, useGridSelector } from '@mui/x-data-grid-pro';
5
3
  import { useGridApiContext } from "../hooks/utils/useGridApiContext.js";
6
4
  import { gridRowGroupingSanitizedModelSelector } from "../hooks/features/rowGrouping/gridRowGroupingSelector.js";
7
5
  import { useGridRootProps } from "../hooks/utils/useGridRootProps.js";
8
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
9
7
  export function GridColumnMenuRowUngroupItem(props) {
10
8
  const {
11
9
  colDef,
@@ -28,25 +26,19 @@ export function GridColumnMenuRowUngroupItem(props) {
28
26
  };
29
27
  const name = columnsLookup[colDef.field].headerName ?? colDef.field;
30
28
  if (rowGroupingModel.includes(colDef.field)) {
31
- return /*#__PURE__*/_jsxs(rootProps.slots.baseMenuItem, {
29
+ return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, {
32
30
  onClick: ungroupColumn,
33
- children: [/*#__PURE__*/_jsx(ListItemIcon, {
34
- children: /*#__PURE__*/_jsx(rootProps.slots.columnMenuUngroupIcon, {
35
- fontSize: "small"
36
- })
37
- }), /*#__PURE__*/_jsx(ListItemText, {
38
- children: apiRef.current.getLocaleText('unGroupColumn')(name)
39
- })]
31
+ iconStart: /*#__PURE__*/_jsx(rootProps.slots.columnMenuUngroupIcon, {
32
+ fontSize: "small"
33
+ }),
34
+ children: apiRef.current.getLocaleText('unGroupColumn')(name)
40
35
  });
41
36
  }
42
- return /*#__PURE__*/_jsxs(rootProps.slots.baseMenuItem, {
37
+ return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, {
43
38
  onClick: groupColumn,
44
- children: [/*#__PURE__*/_jsx(ListItemIcon, {
45
- children: /*#__PURE__*/_jsx(rootProps.slots.columnMenuGroupIcon, {
46
- fontSize: "small"
47
- })
48
- }), /*#__PURE__*/_jsx(ListItemText, {
49
- children: apiRef.current.getLocaleText('groupColumn')(name)
50
- })]
39
+ iconStart: /*#__PURE__*/_jsx(rootProps.slots.columnMenuGroupIcon, {
40
+ fontSize: "small"
41
+ }),
42
+ children: apiRef.current.getLocaleText('groupColumn')(name)
51
43
  });
52
44
  }
@@ -2,7 +2,6 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
4
4
  import Box from '@mui/material/Box';
5
- import CircularProgress from '@mui/material/CircularProgress';
6
5
  import { useGridPrivateApiContext } from '@mui/x-data-grid-pro/internals';
7
6
  import { useGridSelector, getDataGridUtilityClass } from '@mui/x-data-grid-pro';
8
7
  import { useGridApiContext } from "../hooks/utils/useGridApiContext.js";
@@ -47,7 +46,7 @@ function GridGroupingCriteriaCellIcon(props) {
47
46
  if (isDataLoading) {
48
47
  return /*#__PURE__*/_jsx("div", {
49
48
  className: classes.loadingContainer,
50
- children: /*#__PURE__*/_jsx(CircularProgress, {
49
+ children: /*#__PURE__*/_jsx(rootProps.slots.baseCircularProgress, {
51
50
  size: "1rem",
52
51
  color: "inherit"
53
52
  })
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { GridGenericColumnMenu, GRID_COLUMN_MENU_SLOTS, GRID_COLUMN_MENU_SLOT_PROPS } from '@mui/x-data-grid-pro';
4
+ import { forwardRef } from '@mui/x-internals/forwardRef';
4
5
  import { GridColumnMenuAggregationItem } from "./GridColumnMenuAggregationItem.js";
5
6
  import { isGroupingColumn } from "../hooks/features/rowGrouping/index.js";
6
7
  import { GridColumnMenuRowGroupItem } from "./GridColumnMenuRowGroupItem.js";
@@ -27,11 +28,10 @@ export const GRID_COLUMN_MENU_SLOT_PROPS_PREMIUM = _extends({}, GRID_COLUMN_MENU
27
28
  displayOrder: 27
28
29
  }
29
30
  });
30
- export const GridPremiumColumnMenu = /*#__PURE__*/React.forwardRef(function GridPremiumColumnMenuSimple(props, ref) {
31
- return /*#__PURE__*/_jsx(GridGenericColumnMenu, _extends({
32
- ref: ref
33
- }, props, {
31
+ export const GridPremiumColumnMenu = forwardRef(function GridPremiumColumnMenuSimple(props, ref) {
32
+ return /*#__PURE__*/_jsx(GridGenericColumnMenu, _extends({}, props, {
34
33
  defaultSlots: GRID_COLUMN_MENU_SLOTS_PREMIUM,
35
- defaultSlotProps: GRID_COLUMN_MENU_SLOT_PROPS_PREMIUM
34
+ defaultSlotProps: GRID_COLUMN_MENU_SLOT_PROPS_PREMIUM,
35
+ ref: ref
36
36
  }));
37
37
  });
@@ -10,9 +10,10 @@ import { useGridRootProps } from "../../hooks/utils/useGridRootProps.js";
10
10
  import { RecordButton, BrowserSpeechRecognition } from "./RecordButton.js";
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  const supportsSpeechRecognition = !!BrowserSpeechRecognition;
13
- const useUtilityClasses = (ownerState, recording) => {
13
+ const useUtilityClasses = ownerState => {
14
14
  const {
15
- classes
15
+ classes,
16
+ recording
16
17
  } = ownerState;
17
18
  const slots = {
18
19
  root: ['toolbarPromptControl', recording && 'toolbarPromptControl--recording'],
@@ -25,7 +26,12 @@ const useUtilityClasses = (ownerState, recording) => {
25
26
  const GridToolbarPromptControlRoot = styled('div', {
26
27
  name: 'MuiDataGrid',
27
28
  slot: 'ToolbarPromptControl',
28
- overridesResolver: (_, styles) => styles.toolbarPromptControl
29
+ overridesResolver: (props, styles) => {
30
+ const {
31
+ ownerState
32
+ } = props;
33
+ return [styles.toolbarPromptControl, ownerState.recording && styles['toolbarPromptControl--recording']];
34
+ }
29
35
  })({
30
36
  flex: 1,
31
37
  display: 'flex',
@@ -71,7 +77,11 @@ function GridToolbarPromptControl(props) {
71
77
  const [error, setError] = React.useState(null);
72
78
  const [isRecording, setRecording] = React.useState(false);
73
79
  const [query, setQuery] = React.useState('');
74
- const classes = useUtilityClasses(rootProps, isRecording);
80
+ const ownerState = {
81
+ classes: rootProps.classes,
82
+ recording: isRecording
83
+ };
84
+ const classes = useUtilityClasses(ownerState);
75
85
  const examplesFromData = React.useMemo(() => allowDataSampling ? sampleData(apiRef) : undefined, [apiRef, allowDataSampling]);
76
86
  const processPrompt = React.useCallback(() => {
77
87
  const context = generateContext(apiRef, examplesFromData);
@@ -145,10 +155,9 @@ function GridToolbarPromptControl(props) {
145
155
  });
146
156
  const placeholder = supportsSpeechRecognition ? apiRef.current.getLocaleText('toolbarPromptControlWithRecordingPlaceholder') : apiRef.current.getLocaleText('toolbarPromptControlPlaceholder');
147
157
  return /*#__PURE__*/_jsx(GridToolbarPromptControlRoot, {
148
- ownerState: rootProps,
158
+ ownerState: ownerState,
149
159
  className: classes.root,
150
160
  children: /*#__PURE__*/_jsx(rootProps.slots.baseTextField, {
151
- variant: "outlined",
152
161
  placeholder: isRecording ? apiRef.current.getLocaleText('toolbarPromptControlRecordingPlaceholder') : placeholder,
153
162
  "aria-label": apiRef.current.getLocaleText('toolbarPromptControlLabel'),
154
163
  disabled: isLoading,
@@ -161,40 +170,42 @@ function GridToolbarPromptControl(props) {
161
170
  onKeyDown: handleKeyDown,
162
171
  error: !!error,
163
172
  helperText: error,
164
- InputProps: {
165
- startAdornment: supportsSpeechRecognition && /*#__PURE__*/_jsx(rootProps.slots.baseInputAdornment, {
166
- position: "start",
167
- children: /*#__PURE__*/_jsx(RecordButton, {
168
- className: classes.recordButton,
169
- lang: lang,
170
- recording: isRecording,
171
- setRecording: setRecording,
172
- disabled: isLoading,
173
- onUpdate: setQuery,
174
- onDone: handleDone,
175
- onError: setError
176
- })
177
- }),
178
- endAdornment: /*#__PURE__*/_jsx(rootProps.slots.baseInputAdornment, {
179
- position: "end",
180
- children: /*#__PURE__*/_jsx(rootProps.slots.baseTooltip, {
181
- title: apiRef.current.getLocaleText('toolbarPromptControlSendActionLabel'),
182
- children: /*#__PURE__*/_jsx("div", {
183
- children: /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, {
184
- className: classes.sendButton,
185
- disabled: isLoading || isRecording || query === '',
186
- color: "primary",
187
- onClick: processPrompt,
188
- size: "small",
189
- "aria-label": apiRef.current.getLocaleText('toolbarPromptControlSendActionAriaLabel'),
190
- edge: "end",
191
- children: /*#__PURE__*/_jsx(rootProps.slots.toolbarPromptSendIcon, {
192
- fontSize: "small"
173
+ slotProps: {
174
+ input: {
175
+ startAdornment: supportsSpeechRecognition && /*#__PURE__*/_jsx(rootProps.slots.baseInputAdornment, {
176
+ position: "start",
177
+ children: /*#__PURE__*/_jsx(RecordButton, {
178
+ className: classes.recordButton,
179
+ lang: lang,
180
+ recording: isRecording,
181
+ setRecording: setRecording,
182
+ disabled: isLoading,
183
+ onUpdate: setQuery,
184
+ onDone: handleDone,
185
+ onError: setError
186
+ })
187
+ }),
188
+ endAdornment: /*#__PURE__*/_jsx(rootProps.slots.baseInputAdornment, {
189
+ position: "end",
190
+ children: /*#__PURE__*/_jsx(rootProps.slots.baseTooltip, {
191
+ title: apiRef.current.getLocaleText('toolbarPromptControlSendActionLabel'),
192
+ children: /*#__PURE__*/_jsx("div", {
193
+ children: /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, {
194
+ className: classes.sendButton,
195
+ disabled: isLoading || isRecording || query === '',
196
+ color: "primary",
197
+ onClick: processPrompt,
198
+ size: "small",
199
+ "aria-label": apiRef.current.getLocaleText('toolbarPromptControlSendActionAriaLabel'),
200
+ edge: "end",
201
+ children: /*#__PURE__*/_jsx(rootProps.slots.toolbarPromptSendIcon, {
202
+ fontSize: "small"
203
+ })
193
204
  })
194
205
  })
195
206
  })
196
207
  })
197
- })
208
+ }
198
209
  }
199
210
  })
200
211
  });
@@ -1,18 +1,13 @@
1
1
  import { gridColumnLookupSelector, gridFilteredRowsLookupSelector, gridRowTreeSelector, GRID_ROOT_GROUP_ID } from '@mui/x-data-grid-pro';
2
2
  import { getAggregationRules } from "./gridAggregationUtils.js";
3
3
  import { gridAggregationModelSelector } from "./gridAggregationSelectors.js";
4
- const getAggregationCellValue = ({
5
- apiRef,
6
- groupId,
7
- field,
8
- aggregationFunction,
9
- aggregationRowsScope
10
- }) => {
11
- const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
4
+ const getGroupAggregatedValue = (groupId, apiRef, aggregationRowsScope, aggregatedFields, aggregationRules, position) => {
5
+ const groupAggregationLookup = {};
6
+ const aggregatedValues = [];
12
7
  const rowIds = apiRef.current.getRowGroupChildren({
13
8
  groupId
14
9
  });
15
- const values = [];
10
+ const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
16
11
  rowIds.forEach(rowId => {
17
12
  if (aggregationRowsScope === 'filtered' && filteredRowsLookup[rowId] === false) {
18
13
  return;
@@ -29,42 +24,53 @@ const getAggregationCellValue = ({
29
24
  if (rowNode.type === 'group') {
30
25
  return;
31
26
  }
32
- if (typeof aggregationFunction.getCellValue === 'function') {
33
- const row = apiRef.current.getRow(rowId);
34
- values.push(aggregationFunction.getCellValue({
35
- row
36
- }));
37
- } else {
38
- values.push(apiRef.current.getCellValue(rowId, field));
27
+ const row = apiRef.current.getRow(rowId);
28
+ for (let j = 0; j < aggregatedFields.length; j += 1) {
29
+ const aggregatedField = aggregatedFields[j];
30
+ const columnAggregationRules = aggregationRules[aggregatedField];
31
+ const aggregationFunction = columnAggregationRules.aggregationFunction;
32
+ const field = aggregatedField;
33
+ if (aggregatedValues[j] === undefined) {
34
+ aggregatedValues[j] = {
35
+ aggregatedField,
36
+ values: []
37
+ };
38
+ }
39
+ if (typeof aggregationFunction.getCellValue === 'function') {
40
+ aggregatedValues[j].values.push(aggregationFunction.getCellValue({
41
+ row
42
+ }));
43
+ } else {
44
+ const colDef = apiRef.current.getColumn(field);
45
+ aggregatedValues[j].values.push(apiRef.current.getRowValue(row, colDef));
46
+ }
39
47
  }
40
48
  });
41
- return aggregationFunction.apply({
42
- values,
43
- groupId,
44
- field // Added per user request in https://github.com/mui/mui-x/issues/6995#issuecomment-1327423455
45
- });
49
+ for (let i = 0; i < aggregatedValues.length; i += 1) {
50
+ const {
51
+ aggregatedField,
52
+ values
53
+ } = aggregatedValues[i];
54
+ const aggregationFunction = aggregationRules[aggregatedField].aggregationFunction;
55
+ const value = aggregationFunction.apply({
56
+ values,
57
+ groupId,
58
+ field: aggregatedField // Added per user request in https://github.com/mui/mui-x/issues/6995#issuecomment-1327423455
59
+ });
60
+ groupAggregationLookup[aggregatedField] = {
61
+ position,
62
+ value
63
+ };
64
+ }
65
+ return groupAggregationLookup;
46
66
  };
47
- const getGroupAggregatedValue = ({
48
- groupId,
49
- apiRef,
50
- aggregationRowsScope,
51
- aggregatedFields,
52
- aggregationRules,
53
- position
54
- }) => {
67
+ const getGroupAggregatedValueDataSource = (groupId, apiRef, aggregatedFields, position) => {
55
68
  const groupAggregationLookup = {};
56
69
  for (let j = 0; j < aggregatedFields.length; j += 1) {
57
70
  const aggregatedField = aggregatedFields[j];
58
- const columnAggregationRules = aggregationRules[aggregatedField];
59
71
  groupAggregationLookup[aggregatedField] = {
60
72
  position,
61
- value: getAggregationCellValue({
62
- apiRef,
63
- groupId,
64
- field: aggregatedField,
65
- aggregationFunction: columnAggregationRules.aggregationFunction,
66
- aggregationRowsScope
67
- })
73
+ value: apiRef.current.resolveGroupAggregation(groupId, aggregatedField)
68
74
  };
69
75
  }
70
76
  return groupAggregationLookup;
@@ -73,13 +79,10 @@ export const createAggregationLookup = ({
73
79
  apiRef,
74
80
  aggregationFunctions,
75
81
  aggregationRowsScope,
76
- getAggregationPosition
82
+ getAggregationPosition,
83
+ isDataSource
77
84
  }) => {
78
- const aggregationRules = getAggregationRules({
79
- columnsLookup: gridColumnLookupSelector(apiRef),
80
- aggregationModel: gridAggregationModelSelector(apiRef),
81
- aggregationFunctions
82
- });
85
+ const aggregationRules = getAggregationRules(gridColumnLookupSelector(apiRef), gridAggregationModelSelector(apiRef), aggregationFunctions, isDataSource);
83
86
  const aggregatedFields = Object.keys(aggregationRules);
84
87
  if (aggregatedFields.length === 0) {
85
88
  return {};
@@ -94,18 +97,12 @@ export const createAggregationLookup = ({
94
97
  createGroupAggregationLookup(childNode);
95
98
  }
96
99
  }
97
- const hasAggregableChildren = groupNode.children.length;
98
- if (hasAggregableChildren) {
99
- const position = getAggregationPosition(groupNode);
100
- if (position != null) {
101
- aggregationLookup[groupNode.id] = getGroupAggregatedValue({
102
- groupId: groupNode.id,
103
- apiRef,
104
- aggregatedFields,
105
- aggregationRowsScope,
106
- aggregationRules,
107
- position
108
- });
100
+ const position = getAggregationPosition(groupNode);
101
+ if (position !== null) {
102
+ if (isDataSource) {
103
+ aggregationLookup[groupNode.id] = getGroupAggregatedValueDataSource(groupNode.id, apiRef, aggregatedFields, position);
104
+ } else if (groupNode.children.length) {
105
+ aggregationLookup[groupNode.id] = getGroupAggregatedValue(groupNode.id, apiRef, aggregationRowsScope, aggregatedFields, aggregationRules, position);
109
106
  }
110
107
  }
111
108
  };
@@ -10,56 +10,60 @@ export const getAggregationFooterRowIdFromGroupId = groupId => {
10
10
  }
11
11
  return `auto-generated-group-footer-${groupId}`;
12
12
  };
13
+ const isClientSideAggregateFunction = aggregationFunction => !!aggregationFunction && 'apply' in aggregationFunction;
13
14
  export const canColumnHaveAggregationFunction = ({
14
15
  colDef,
15
16
  aggregationFunctionName,
16
- aggregationFunction
17
+ aggregationFunction,
18
+ isDataSource
17
19
  }) => {
18
20
  if (!colDef) {
19
21
  return false;
20
22
  }
21
- if (!aggregationFunction) {
23
+ if (!isClientSideAggregateFunction(aggregationFunction) && !isDataSource) {
22
24
  return false;
23
25
  }
24
26
  if (colDef.availableAggregationFunctions != null) {
25
27
  return colDef.availableAggregationFunctions.includes(aggregationFunctionName);
26
28
  }
27
- if (!aggregationFunction.columnTypes) {
29
+ if (!aggregationFunction?.columnTypes) {
28
30
  return true;
29
31
  }
30
32
  return aggregationFunction.columnTypes.includes(colDef.type);
31
33
  };
32
34
  export const getAvailableAggregationFunctions = ({
33
35
  aggregationFunctions,
34
- colDef
36
+ colDef,
37
+ isDataSource
35
38
  }) => Object.keys(aggregationFunctions).filter(aggregationFunctionName => canColumnHaveAggregationFunction({
36
39
  colDef,
37
40
  aggregationFunctionName,
38
- aggregationFunction: aggregationFunctions[aggregationFunctionName]
41
+ aggregationFunction: aggregationFunctions[aggregationFunctionName],
42
+ isDataSource
39
43
  }));
40
44
  export const mergeStateWithAggregationModel = aggregationModel => state => _extends({}, state, {
41
45
  aggregation: _extends({}, state.aggregation, {
42
46
  model: aggregationModel
43
47
  })
44
48
  });
45
- export const getAggregationRules = ({
46
- columnsLookup,
47
- aggregationModel,
48
- aggregationFunctions
49
- }) => {
49
+ export const getAggregationRules = (columnsLookup, aggregationModel, aggregationFunctions, isDataSource) => {
50
50
  const aggregationRules = {};
51
- Object.entries(aggregationModel).forEach(([field, columnItem]) => {
51
+
52
+ // eslint-disable-next-line guard-for-in
53
+ for (const field in aggregationModel) {
54
+ const columnItem = aggregationModel[field];
52
55
  if (columnsLookup[field] && canColumnHaveAggregationFunction({
53
56
  colDef: columnsLookup[field],
54
57
  aggregationFunctionName: columnItem,
55
- aggregationFunction: aggregationFunctions[columnItem]
58
+ aggregationFunction: aggregationFunctions[columnItem],
59
+ isDataSource
56
60
  })) {
57
61
  aggregationRules[field] = {
58
62
  aggregationFunctionName: columnItem,
59
63
  aggregationFunction: aggregationFunctions[columnItem]
60
64
  };
61
65
  }
62
- });
66
+ }
63
67
  return aggregationRules;
64
68
  };
65
69
  /**
@@ -1,4 +1,3 @@
1
- export * from "./gridAggregationInterfaces.js";
2
1
  export * from "./gridAggregationSelectors.js";
3
2
  export * from "./gridAggregationFunctions.js";
4
3
  export { GRID_AGGREGATION_ROOT_FOOTER_ROW_ID, getAggregationFooterRowIdFromGroupId } from "./gridAggregationUtils.js";
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { gridColumnLookupSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid-pro';
4
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
4
5
  import { gridAggregationModelSelector } from "./gridAggregationSelectors.js";
5
6
  import { getAggregationRules, mergeStateWithAggregationModel, areAggregationRulesEqual } from "./gridAggregationUtils.js";
6
7
  import { createAggregationLookup } from "./createAggregationLookup.js";
@@ -39,18 +40,29 @@ export const useGridAggregation = (apiRef, props) => {
39
40
  apiRef,
40
41
  getAggregationPosition: props.getAggregationPosition,
41
42
  aggregationFunctions: props.aggregationFunctions,
42
- aggregationRowsScope: props.aggregationRowsScope
43
+ aggregationRowsScope: props.aggregationRowsScope,
44
+ isDataSource: !!props.unstable_dataSource
43
45
  });
44
46
  apiRef.current.setState(state => _extends({}, state, {
45
47
  aggregation: _extends({}, state.aggregation, {
46
48
  lookup: aggregationLookup
47
49
  })
48
50
  }));
49
- }, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope]);
51
+ }, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope, props.unstable_dataSource]);
50
52
  const aggregationApi = {
51
53
  setAggregationModel
52
54
  };
55
+ const aggregationPrivateApi = {
56
+ applyAggregation
57
+ };
53
58
  useGridApiMethod(apiRef, aggregationApi, 'public');
59
+ useGridApiMethod(apiRef, aggregationPrivateApi, 'private');
60
+ const addGetRowsParams = React.useCallback(params => {
61
+ return _extends({}, params, {
62
+ aggregationModel: gridAggregationModelSelector(apiRef)
63
+ });
64
+ }, [apiRef]);
65
+ useGridRegisterPipeProcessor(apiRef, 'getRowsParams', addGetRowsParams);
54
66
 
55
67
  /**
56
68
  * EVENTS
@@ -60,16 +72,16 @@ export const useGridAggregation = (apiRef, props) => {
60
72
  rulesOnLastRowHydration,
61
73
  rulesOnLastColumnHydration
62
74
  } = apiRef.current.caches.aggregation;
63
- const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
64
- columnsLookup: gridColumnLookupSelector(apiRef),
65
- aggregationModel: gridAggregationModelSelector(apiRef),
66
- aggregationFunctions: props.aggregationFunctions
67
- });
75
+ const aggregationRules = props.disableAggregation ? {} : getAggregationRules(gridColumnLookupSelector(apiRef), gridAggregationModelSelector(apiRef), props.aggregationFunctions, !!props.unstable_dataSource);
68
76
 
69
77
  // Re-apply the row hydration to add / remove the aggregation footers
70
78
  if (!areAggregationRulesEqual(rulesOnLastRowHydration, aggregationRules)) {
71
- apiRef.current.requestPipeProcessorsApplication('hydrateRows');
72
- applyAggregation();
79
+ if (props.unstable_dataSource) {
80
+ apiRef.current.unstable_dataSource.fetchRows();
81
+ } else {
82
+ apiRef.current.requestPipeProcessorsApplication('hydrateRows');
83
+ applyAggregation();
84
+ }
73
85
  }
74
86
 
75
87
  // Re-apply the column hydration to wrap / unwrap the aggregated columns
@@ -77,7 +89,7 @@ export const useGridAggregation = (apiRef, props) => {
77
89
  apiRef.current.caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
78
90
  apiRef.current.requestPipeProcessorsApplication('hydrateColumns');
79
91
  }
80
- }, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation]);
92
+ }, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation, props.unstable_dataSource]);
81
93
  useGridApiEventHandler(apiRef, 'aggregationModelChange', checkAggregationRulesDiff);
82
94
  useGridApiEventHandler(apiRef, 'columnsChange', checkAggregationRulesDiff);
83
95
  useGridApiEventHandler(apiRef, 'filteredRowsSet', applyAggregation);
@@ -10,11 +10,7 @@ export const useGridAggregationPreProcessors = (apiRef, props) => {
10
10
  // that the pre-processor is called it will already have been updated with the current rules.
11
11
  const rulesOnLastColumnHydration = React.useRef({});
12
12
  const updateAggregatedColumns = React.useCallback(columnsState => {
13
- const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
14
- columnsLookup: columnsState.lookup,
15
- aggregationModel: gridAggregationModelSelector(apiRef),
16
- aggregationFunctions: props.aggregationFunctions
17
- });
13
+ const aggregationRules = props.disableAggregation ? {} : getAggregationRules(columnsState.lookup, gridAggregationModelSelector(apiRef), props.aggregationFunctions, !!props.unstable_dataSource);
18
14
  columnsState.orderedFields.forEach(field => {
19
15
  const shouldHaveAggregationValue = !!aggregationRules[field];
20
16
  const haveAggregationColumnValue = !!rulesOnLastColumnHydration.current[field];
@@ -34,14 +30,11 @@ export const useGridAggregationPreProcessors = (apiRef, props) => {
34
30
  columnsState.lookup[field] = column;
35
31
  });
36
32
  rulesOnLastColumnHydration.current = aggregationRules;
33
+ apiRef.current.caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
37
34
  return columnsState;
38
- }, [apiRef, props.aggregationFunctions, props.disableAggregation]);
35
+ }, [apiRef, props.aggregationFunctions, props.disableAggregation, props.unstable_dataSource]);
39
36
  const addGroupFooterRows = React.useCallback(value => {
40
- const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
41
- columnsLookup: gridColumnLookupSelector(apiRef),
42
- aggregationModel: gridAggregationModelSelector(apiRef),
43
- aggregationFunctions: props.aggregationFunctions
44
- });
37
+ const aggregationRules = props.disableAggregation ? {} : getAggregationRules(gridColumnLookupSelector(apiRef), gridAggregationModelSelector(apiRef), props.aggregationFunctions, !!props.unstable_dataSource);
45
38
  const hasAggregationRule = Object.keys(aggregationRules).length > 0;
46
39
 
47
40
  // If we did not have any aggregation footer before, and we still don't have any,
@@ -56,20 +49,21 @@ export const useGridAggregationPreProcessors = (apiRef, props) => {
56
49
  getAggregationPosition: props.getAggregationPosition,
57
50
  hasAggregationRule
58
51
  });
59
- }, [apiRef, props.disableAggregation, props.getAggregationPosition, props.aggregationFunctions]);
52
+ }, [apiRef, props.disableAggregation, props.getAggregationPosition, props.aggregationFunctions, props.unstable_dataSource]);
60
53
  const addColumnMenuButtons = React.useCallback((columnMenuItems, colDef) => {
61
54
  if (props.disableAggregation || !colDef.aggregable) {
62
55
  return columnMenuItems;
63
56
  }
64
57
  const availableAggregationFunctions = getAvailableAggregationFunctions({
65
58
  aggregationFunctions: props.aggregationFunctions,
66
- colDef
59
+ colDef,
60
+ isDataSource: !!props.unstable_dataSource
67
61
  });
68
62
  if (availableAggregationFunctions.length === 0) {
69
63
  return columnMenuItems;
70
64
  }
71
65
  return [...columnMenuItems, 'columnMenuAggregationItem'];
72
- }, [props.aggregationFunctions, props.disableAggregation]);
66
+ }, [props.aggregationFunctions, props.disableAggregation, props.unstable_dataSource]);
73
67
  const stateExportPreProcessing = React.useCallback(prevState => {
74
68
  if (props.disableAggregation) {
75
69
  return prevState;
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import ownerDocument from '@mui/utils/ownerDocument';
4
4
  import useEventCallback from '@mui/utils/useEventCallback';
5
5
  import { getTotalHeaderHeight, getVisibleRows, isNavigationKey, serializeCellValue, useGridRegisterPipeProcessor, useGridVisibleRows } from '@mui/x-data-grid-pro/internals';
6
- import { useGridApiEventHandler, useGridApiMethod, GRID_ACTIONS_COLUMN_TYPE, GRID_CHECKBOX_SELECTION_COL_DEF, GRID_DETAIL_PANEL_TOGGLE_FIELD, gridRowsDataRowIdToIdLookupSelector, gridClasses, gridFocusCellSelector, GRID_REORDER_COL_DEF, useGridSelector, gridSortedRowIdsSelector, gridDimensionsSelector } from '@mui/x-data-grid-pro';
6
+ import { useGridApiEventHandler, useGridApiMethod, GRID_ACTIONS_COLUMN_TYPE, GRID_CHECKBOX_SELECTION_COL_DEF, GRID_DETAIL_PANEL_TOGGLE_FIELD, gridClasses, gridFocusCellSelector, GRID_REORDER_COL_DEF, useGridSelector, gridSortedRowIdsSelector, gridDimensionsSelector } from '@mui/x-data-grid-pro';
7
7
  import { gridCellSelectionStateSelector } from "./gridCellSelectionSelector.js";
8
8
  export const cellSelectionStateInitializer = (state, props) => _extends({}, state, {
9
9
  cellSelection: _extends({}, props.cellSelectionModel ?? props.initialState?.cellSelection)
@@ -17,10 +17,10 @@ const AUTO_SCROLL_SPEED = 20; // The speed to scroll once the mouse enters the s
17
17
  export const useGridCellSelection = (apiRef, props) => {
18
18
  const hasRootReference = apiRef.current.rootElementRef.current !== null;
19
19
  const visibleRows = useGridVisibleRows(apiRef, props);
20
- const cellWithVirtualFocus = React.useRef();
21
- const lastMouseDownCell = React.useRef();
20
+ const cellWithVirtualFocus = React.useRef(null);
21
+ const lastMouseDownCell = React.useRef(null);
22
22
  const mousePosition = React.useRef(null);
23
- const autoScrollRAF = React.useRef();
23
+ const autoScrollRAF = React.useRef(null);
24
24
  const sortedRowIds = useGridSelector(apiRef, gridSortedRowIdsSelector);
25
25
  const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
26
26
  const totalHeaderHeight = getTotalHeaderHeight(apiRef, props);
@@ -91,7 +91,6 @@ export const useGridCellSelection = (apiRef, props) => {
91
91
  }, [apiRef, visibleRows.rows]);
92
92
  const getSelectedCellsAsArray = React.useCallback(() => {
93
93
  const selectionModel = apiRef.current.getCellSelectionModel();
94
- const idToIdLookup = gridRowsDataRowIdToIdLookupSelector(apiRef);
95
94
  const currentVisibleRows = getVisibleRows(apiRef, props);
96
95
  const sortedEntries = currentVisibleRows.rows.reduce((result, row) => {
97
96
  if (row.id in selectionModel) {
@@ -103,7 +102,7 @@ export const useGridCellSelection = (apiRef, props) => {
103
102
  selectedCells.push(...Object.entries(fields).reduce((selectedFields, [field, isSelected]) => {
104
103
  if (isSelected) {
105
104
  selectedFields.push({
106
- id: idToIdLookup[id],
105
+ id,
107
106
  field
108
107
  });
109
108
  }