@mui/x-data-grid-premium 8.0.0-alpha.1 → 8.0.0-alpha.11
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.
- package/CHANGELOG.md +2007 -230
- package/DataGridPremium/DataGridPremium.js +41 -40
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +2 -2
- package/DataGridPremium/useDataGridPremiumComponent.js +6 -4
- package/DataGridPremium/useDataGridPremiumProps.js +5 -3
- package/README.md +1 -1
- package/components/GridAggregationHeader.js +6 -1
- package/components/GridColumnMenuAggregationItem.js +77 -49
- package/components/GridColumnMenuRowGroupItem.js +5 -11
- package/components/GridColumnMenuRowUngroupItem.js +10 -19
- package/components/GridDataSourceGroupingCriteriaCell.js +1 -2
- package/components/GridPremiumColumnMenu.d.ts +1 -1
- package/components/GridPremiumColumnMenu.js +5 -5
- package/components/promptControl/GridToolbarPromptControl.js +47 -36
- package/esm/DataGridPremium/DataGridPremium.js +43 -42
- package/esm/DataGridPremium/useDataGridPremiumComponent.js +7 -5
- package/esm/DataGridPremium/useDataGridPremiumProps.js +6 -4
- package/esm/components/GridAggregationHeader.js +6 -1
- package/esm/components/GridColumnMenuAggregationItem.js +75 -47
- package/esm/components/GridColumnMenuRowGroupItem.js +6 -11
- package/esm/components/GridColumnMenuRowUngroupItem.js +11 -19
- package/esm/components/GridDataSourceGroupingCriteriaCell.js +1 -2
- package/esm/components/GridPremiumColumnMenu.js +5 -5
- package/esm/components/promptControl/GridToolbarPromptControl.js +47 -36
- package/esm/hooks/features/aggregation/createAggregationLookup.js +52 -55
- package/esm/hooks/features/aggregation/gridAggregationUtils.js +18 -14
- package/esm/hooks/features/aggregation/index.js +0 -1
- package/esm/hooks/features/aggregation/useGridAggregation.js +22 -12
- package/esm/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
- package/esm/hooks/features/cellSelection/useGridCellSelection.js +17 -15
- package/esm/hooks/features/clipboard/useGridClipboardImport.js +1 -1
- package/esm/hooks/features/dataSource/cache.js +3 -0
- package/esm/hooks/features/dataSource/models.js +1 -0
- package/esm/hooks/features/dataSource/useGridDataSourcePremium.js +53 -0
- package/esm/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
- package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -3
- package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +2 -2
- package/esm/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
- package/esm/hooks/utils/useGridAriaAttributes.js +1 -3
- package/esm/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
- package/esm/utils/releaseInfo.js +1 -1
- package/hooks/features/aggregation/createAggregationLookup.d.ts +7 -6
- package/hooks/features/aggregation/createAggregationLookup.js +52 -55
- package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +18 -5
- package/hooks/features/aggregation/gridAggregationSelectors.d.ts +2 -2
- package/hooks/features/aggregation/gridAggregationUtils.d.ts +12 -13
- package/hooks/features/aggregation/gridAggregationUtils.js +18 -14
- package/hooks/features/aggregation/index.d.ts +1 -1
- package/hooks/features/aggregation/index.js +0 -12
- package/hooks/features/aggregation/useGridAggregation.d.ts +2 -2
- package/hooks/features/aggregation/useGridAggregation.js +22 -12
- package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +2 -2
- package/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
- package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +3 -2
- package/hooks/features/cellSelection/gridCellSelectionInterfaces.d.ts +3 -3
- package/hooks/features/cellSelection/useGridCellSelection.d.ts +2 -2
- package/hooks/features/cellSelection/useGridCellSelection.js +15 -13
- package/hooks/features/clipboard/useGridClipboardImport.d.ts +2 -2
- package/hooks/features/clipboard/useGridClipboardImport.js +1 -1
- package/hooks/features/dataSource/cache.d.ts +2 -0
- package/hooks/features/dataSource/cache.js +9 -0
- package/hooks/features/dataSource/models.d.ts +47 -0
- package/hooks/features/dataSource/models.js +5 -0
- package/hooks/features/dataSource/useGridDataSourcePremium.d.ts +4 -0
- package/hooks/features/dataSource/useGridDataSourcePremium.js +62 -0
- package/hooks/features/export/serializer/excelSerializer.d.ts +3 -2
- package/hooks/features/export/useGridExcelExport.d.ts +2 -2
- package/hooks/features/rowGrouping/createGroupingColDef.d.ts +2 -2
- package/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
- package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +2 -2
- package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +4 -4
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +4 -2
- package/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.d.ts +2 -2
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +2 -2
- package/hooks/features/rowGrouping/useGridRowGrouping.js +1 -1
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +2 -2
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
- package/hooks/utils/useGridApiContext.d.ts +3 -1
- package/hooks/utils/useGridApiRef.d.ts +3 -1
- package/hooks/utils/useGridAriaAttributes.js +1 -3
- package/hooks/utils/useGridPrivateApiContext.d.ts +1 -1
- package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +2 -2
- package/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
- package/index.d.ts +2 -0
- package/index.js +1 -1
- package/models/dataGridPremiumProps.d.ts +8 -12
- package/models/gridApiPremium.d.ts +5 -3
- package/models/gridGroupingValueGetter.d.ts +2 -1
- package/models/gridPastedValueParser.d.ts +2 -1
- package/modern/DataGridPremium/DataGridPremium.js +43 -42
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +7 -5
- package/modern/DataGridPremium/useDataGridPremiumProps.js +6 -4
- package/modern/components/GridAggregationHeader.js +6 -1
- package/modern/components/GridColumnMenuAggregationItem.js +75 -47
- package/modern/components/GridColumnMenuRowGroupItem.js +6 -11
- package/modern/components/GridColumnMenuRowUngroupItem.js +11 -19
- package/modern/components/GridDataSourceGroupingCriteriaCell.js +1 -2
- package/modern/components/GridPremiumColumnMenu.js +5 -5
- package/modern/components/promptControl/GridToolbarPromptControl.js +47 -36
- package/modern/hooks/features/aggregation/createAggregationLookup.js +52 -55
- package/modern/hooks/features/aggregation/gridAggregationUtils.js +18 -14
- package/modern/hooks/features/aggregation/index.js +0 -1
- package/modern/hooks/features/aggregation/useGridAggregation.js +22 -12
- package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
- package/modern/hooks/features/cellSelection/useGridCellSelection.js +17 -15
- package/modern/hooks/features/clipboard/useGridClipboardImport.js +1 -1
- package/modern/hooks/features/dataSource/cache.js +3 -0
- package/modern/hooks/features/dataSource/models.js +1 -0
- package/modern/hooks/features/dataSource/useGridDataSourcePremium.js +53 -0
- package/modern/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -3
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +2 -2
- package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
- package/modern/hooks/utils/useGridAriaAttributes.js +1 -3
- package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
- package/modern/index.js +1 -1
- package/modern/utils/releaseInfo.js +1 -1
- package/package.json +6 -6
- 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
|
|
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__*/
|
|
24
|
+
return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, {
|
|
27
25
|
onClick: ungroupColumn,
|
|
28
26
|
disabled: !groupedColumn.groupable,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
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__*/
|
|
29
|
+
return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, {
|
|
32
30
|
onClick: ungroupColumn,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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__*/
|
|
37
|
+
return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, {
|
|
43
38
|
onClick: groupColumn,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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(
|
|
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 =
|
|
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 =
|
|
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: (
|
|
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
|
|
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:
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
children: /*#__PURE__*/_jsx(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
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:
|
|
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
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -107,7 +111,7 @@ export const addFooterRows = ({
|
|
|
107
111
|
}
|
|
108
112
|
};
|
|
109
113
|
const updateRootGroupFooter = groupNode => {
|
|
110
|
-
const shouldHaveFooter = hasAggregationRule && getAggregationPosition(groupNode) === 'footer';
|
|
114
|
+
const shouldHaveFooter = hasAggregationRule && getAggregationPosition(groupNode) === 'footer' && groupNode.children.length > 0;
|
|
111
115
|
if (shouldHaveFooter) {
|
|
112
116
|
const rowId = getAggregationFooterRowIdFromGroupId(null);
|
|
113
117
|
newGroupingParams = addPinnedRow({
|
|
@@ -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";
|
|
@@ -31,7 +32,6 @@ export const useGridAggregation = (apiRef, props) => {
|
|
|
31
32
|
const currentModel = gridAggregationModelSelector(apiRef);
|
|
32
33
|
if (currentModel !== model) {
|
|
33
34
|
apiRef.current.setState(mergeStateWithAggregationModel(model));
|
|
34
|
-
apiRef.current.forceUpdate();
|
|
35
35
|
}
|
|
36
36
|
}, [apiRef]);
|
|
37
37
|
const applyAggregation = React.useCallback(() => {
|
|
@@ -39,18 +39,29 @@ export const useGridAggregation = (apiRef, props) => {
|
|
|
39
39
|
apiRef,
|
|
40
40
|
getAggregationPosition: props.getAggregationPosition,
|
|
41
41
|
aggregationFunctions: props.aggregationFunctions,
|
|
42
|
-
aggregationRowsScope: props.aggregationRowsScope
|
|
42
|
+
aggregationRowsScope: props.aggregationRowsScope,
|
|
43
|
+
isDataSource: !!props.unstable_dataSource
|
|
43
44
|
});
|
|
44
45
|
apiRef.current.setState(state => _extends({}, state, {
|
|
45
46
|
aggregation: _extends({}, state.aggregation, {
|
|
46
47
|
lookup: aggregationLookup
|
|
47
48
|
})
|
|
48
49
|
}));
|
|
49
|
-
}, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope]);
|
|
50
|
+
}, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope, props.unstable_dataSource]);
|
|
50
51
|
const aggregationApi = {
|
|
51
52
|
setAggregationModel
|
|
52
53
|
};
|
|
54
|
+
const aggregationPrivateApi = {
|
|
55
|
+
applyAggregation
|
|
56
|
+
};
|
|
53
57
|
useGridApiMethod(apiRef, aggregationApi, 'public');
|
|
58
|
+
useGridApiMethod(apiRef, aggregationPrivateApi, 'private');
|
|
59
|
+
const addGetRowsParams = React.useCallback(params => {
|
|
60
|
+
return _extends({}, params, {
|
|
61
|
+
aggregationModel: gridAggregationModelSelector(apiRef)
|
|
62
|
+
});
|
|
63
|
+
}, [apiRef]);
|
|
64
|
+
useGridRegisterPipeProcessor(apiRef, 'getRowsParams', addGetRowsParams);
|
|
54
65
|
|
|
55
66
|
/**
|
|
56
67
|
* EVENTS
|
|
@@ -60,24 +71,23 @@ export const useGridAggregation = (apiRef, props) => {
|
|
|
60
71
|
rulesOnLastRowHydration,
|
|
61
72
|
rulesOnLastColumnHydration
|
|
62
73
|
} = apiRef.current.caches.aggregation;
|
|
63
|
-
const aggregationRules = props.disableAggregation ? {} : getAggregationRules(
|
|
64
|
-
columnsLookup: gridColumnLookupSelector(apiRef),
|
|
65
|
-
aggregationModel: gridAggregationModelSelector(apiRef),
|
|
66
|
-
aggregationFunctions: props.aggregationFunctions
|
|
67
|
-
});
|
|
74
|
+
const aggregationRules = props.disableAggregation ? {} : getAggregationRules(gridColumnLookupSelector(apiRef), gridAggregationModelSelector(apiRef), props.aggregationFunctions, !!props.unstable_dataSource);
|
|
68
75
|
|
|
69
76
|
// Re-apply the row hydration to add / remove the aggregation footers
|
|
70
77
|
if (!areAggregationRulesEqual(rulesOnLastRowHydration, aggregationRules)) {
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
if (props.unstable_dataSource) {
|
|
79
|
+
apiRef.current.unstable_dataSource.fetchRows();
|
|
80
|
+
} else {
|
|
81
|
+
apiRef.current.requestPipeProcessorsApplication('hydrateRows');
|
|
82
|
+
applyAggregation();
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
// Re-apply the column hydration to wrap / unwrap the aggregated columns
|
|
76
87
|
if (!areAggregationRulesEqual(rulesOnLastColumnHydration, aggregationRules)) {
|
|
77
|
-
apiRef.current.caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
|
|
78
88
|
apiRef.current.requestPipeProcessorsApplication('hydrateColumns');
|
|
79
89
|
}
|
|
80
|
-
}, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation]);
|
|
90
|
+
}, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation, props.unstable_dataSource]);
|
|
81
91
|
useGridApiEventHandler(apiRef, 'aggregationModelChange', checkAggregationRulesDiff);
|
|
82
92
|
useGridApiEventHandler(apiRef, 'columnsChange', checkAggregationRulesDiff);
|
|
83
93
|
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;
|