@mui/x-data-grid-premium 8.0.0-alpha.0 → 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.
- package/CHANGELOG.md +2215 -119
- package/DataGridPremium/DataGridPremium.js +40 -40
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +2 -2
- package/DataGridPremium/useDataGridPremiumComponent.js +4 -2
- package/DataGridPremium/useDataGridPremiumProps.js +5 -3
- package/README.md +3 -3
- 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/index.d.ts +1 -0
- package/components/index.js +12 -0
- package/components/promptControl/GridToolbarPromptControl.d.ts +26 -0
- package/components/promptControl/GridToolbarPromptControl.js +220 -0
- package/components/promptControl/RecordButton.d.ts +16 -0
- package/components/promptControl/RecordButton.js +119 -0
- package/components/promptControl/index.d.ts +1 -0
- package/components/promptControl/index.js +12 -0
- package/esm/DataGridPremium/DataGridPremium.js +42 -42
- package/esm/DataGridPremium/useDataGridPremiumComponent.js +5 -3
- 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/index.js +1 -0
- package/esm/components/promptControl/GridToolbarPromptControl.js +213 -0
- package/esm/components/promptControl/RecordButton.js +111 -0
- package/esm/components/promptControl/index.js +1 -0
- package/esm/hooks/features/aggregation/createAggregationLookup.js +52 -55
- package/esm/hooks/features/aggregation/gridAggregationUtils.js +17 -13
- package/esm/hooks/features/aggregation/index.js +0 -1
- package/esm/hooks/features/aggregation/useGridAggregation.js +22 -10
- package/esm/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
- package/esm/hooks/features/cellSelection/useGridCellSelection.js +5 -6
- 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/index.js +2 -1
- package/esm/hooks/features/promptControl/api.js +22 -0
- package/esm/hooks/features/promptControl/index.js +1 -0
- package/esm/hooks/features/promptControl/types.js +1 -0
- package/esm/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
- package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +2 -2
- 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/material/icons.js +7 -1
- package/esm/material/index.js +4 -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 +17 -13
- 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 -10
- package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +2 -2
- package/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
- package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +4 -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 +4 -5
- 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/index.d.ts +1 -0
- package/hooks/features/index.js +11 -0
- package/hooks/features/promptControl/api.d.ts +2 -0
- package/hooks/features/promptControl/api.js +28 -0
- package/hooks/features/promptControl/index.d.ts +2 -0
- package/hooks/features/promptControl/index.js +12 -0
- package/hooks/features/promptControl/types.d.ts +25 -0
- package/hooks/features/promptControl/types.js +5 -0
- 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 +1 -1
- 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 +1 -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/material/icons.d.ts +6 -0
- package/material/icons.js +8 -2
- package/material/index.d.ts +2 -0
- package/material/index.js +3 -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/models/gridPremiumIconSlotsComponent.d.ts +10 -0
- package/modern/DataGridPremium/DataGridPremium.js +42 -42
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +5 -3
- 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/index.js +1 -0
- package/modern/components/promptControl/GridToolbarPromptControl.js +213 -0
- package/modern/components/promptControl/RecordButton.js +111 -0
- package/modern/components/promptControl/index.js +1 -0
- package/modern/hooks/features/aggregation/createAggregationLookup.js +52 -55
- package/modern/hooks/features/aggregation/gridAggregationUtils.js +17 -13
- package/modern/hooks/features/aggregation/index.js +0 -1
- package/modern/hooks/features/aggregation/useGridAggregation.js +22 -10
- package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
- package/modern/hooks/features/cellSelection/useGridCellSelection.js +5 -6
- 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/index.js +2 -1
- package/modern/hooks/features/promptControl/api.js +22 -0
- package/modern/hooks/features/promptControl/index.js +1 -0
- package/modern/hooks/features/promptControl/types.js +1 -0
- package/modern/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +2 -2
- 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/material/icons.js +7 -1
- package/modern/material/index.js +4 -2
- package/modern/utils/releaseInfo.js +1 -1
- package/package.json +8 -8
- package/utils/releaseInfo.js +1 -1
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
2
|
import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
|
|
3
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
|
+
const _excluded = ["native"];
|
|
4
5
|
import * as React from 'react';
|
|
5
6
|
import PropTypes from 'prop-types';
|
|
6
7
|
import { useGridSelector } from '@mui/x-data-grid-pro';
|
|
7
|
-
import ListItemIcon from '@mui/material/ListItemIcon';
|
|
8
|
-
import ListItemText from '@mui/material/ListItemText';
|
|
9
8
|
import FormControl from '@mui/material/FormControl';
|
|
10
9
|
import InputLabel from '@mui/material/InputLabel';
|
|
11
10
|
import { unstable_useId as useId } from '@mui/utils';
|
|
@@ -14,18 +13,27 @@ import { useGridRootProps } from "../hooks/utils/useGridRootProps.js";
|
|
|
14
13
|
import { canColumnHaveAggregationFunction, getAggregationFunctionLabel, getAvailableAggregationFunctions } from "../hooks/features/aggregation/gridAggregationUtils.js";
|
|
15
14
|
import { gridAggregationModelSelector } from "../hooks/features/aggregation/gridAggregationSelectors.js";
|
|
16
15
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
import { createElement as _createElement } from "react";
|
|
17
17
|
function GridColumnMenuAggregationItem(props) {
|
|
18
18
|
const {
|
|
19
19
|
colDef
|
|
20
20
|
} = props;
|
|
21
21
|
const apiRef = useGridApiContext();
|
|
22
|
+
const inputRef = React.useRef(null);
|
|
22
23
|
const rootProps = useGridRootProps();
|
|
23
24
|
const id = useId();
|
|
24
25
|
const aggregationModel = useGridSelector(apiRef, gridAggregationModelSelector);
|
|
25
26
|
const availableAggregationFunctions = React.useMemo(() => getAvailableAggregationFunctions({
|
|
26
27
|
aggregationFunctions: rootProps.aggregationFunctions,
|
|
27
|
-
colDef
|
|
28
|
-
|
|
28
|
+
colDef,
|
|
29
|
+
isDataSource: !!rootProps.unstable_dataSource
|
|
30
|
+
}), [colDef, rootProps.aggregationFunctions, rootProps.unstable_dataSource]);
|
|
31
|
+
const _ref = rootProps.slotProps?.baseSelect || {},
|
|
32
|
+
{
|
|
33
|
+
native: isBaseSelectNative = false
|
|
34
|
+
} = _ref,
|
|
35
|
+
baseSelectProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
36
|
+
const baseSelectOptionProps = rootProps.slotProps?.baseSelectOption || {};
|
|
29
37
|
const selectedAggregationRule = React.useMemo(() => {
|
|
30
38
|
if (!colDef || !aggregationModel[colDef.field]) {
|
|
31
39
|
return '';
|
|
@@ -34,12 +42,13 @@ function GridColumnMenuAggregationItem(props) {
|
|
|
34
42
|
if (canColumnHaveAggregationFunction({
|
|
35
43
|
colDef,
|
|
36
44
|
aggregationFunctionName,
|
|
37
|
-
aggregationFunction: rootProps.aggregationFunctions[aggregationFunctionName]
|
|
45
|
+
aggregationFunction: rootProps.aggregationFunctions[aggregationFunctionName],
|
|
46
|
+
isDataSource: !!rootProps.unstable_dataSource
|
|
38
47
|
})) {
|
|
39
48
|
return aggregationFunctionName;
|
|
40
49
|
}
|
|
41
50
|
return '';
|
|
42
|
-
}, [rootProps.aggregationFunctions, aggregationModel, colDef]);
|
|
51
|
+
}, [rootProps.aggregationFunctions, rootProps.unstable_dataSource, aggregationModel, colDef]);
|
|
43
52
|
const handleAggregationItemChange = event => {
|
|
44
53
|
const newAggregationItem = event.target?.value || undefined;
|
|
45
54
|
const currentModel = gridAggregationModelSelector(apiRef);
|
|
@@ -52,47 +61,66 @@ function GridColumnMenuAggregationItem(props) {
|
|
|
52
61
|
apiRef.current.hideColumnMenu();
|
|
53
62
|
};
|
|
54
63
|
const label = apiRef.current.getLocaleText('aggregationMenuItemHeader');
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const handleMenuItemKeyDown = React.useCallback(event => {
|
|
65
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
66
|
+
inputRef.current.focus();
|
|
67
|
+
}
|
|
68
|
+
}, []);
|
|
69
|
+
const handleSelectKeyDown = React.useCallback(event => {
|
|
70
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === ' ') {
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
}
|
|
73
|
+
}, []);
|
|
74
|
+
return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, {
|
|
75
|
+
inert: true,
|
|
76
|
+
iconStart: /*#__PURE__*/_jsx(rootProps.slots.columnMenuAggregationIcon, {
|
|
77
|
+
fontSize: "small"
|
|
78
|
+
}),
|
|
79
|
+
onKeyDown: handleMenuItemKeyDown,
|
|
80
|
+
children: /*#__PURE__*/_jsxs(FormControl, {
|
|
81
|
+
size: "small",
|
|
82
|
+
fullWidth: true,
|
|
83
|
+
sx: {
|
|
84
|
+
minWidth: 150
|
|
85
|
+
},
|
|
86
|
+
children: [/*#__PURE__*/_jsx(InputLabel, {
|
|
87
|
+
id: `${id}-label`,
|
|
88
|
+
htmlFor: `${id}-input`,
|
|
89
|
+
children: label
|
|
90
|
+
}), /*#__PURE__*/_jsxs(rootProps.slots.baseSelect, _extends({
|
|
91
|
+
labelId: `${id}-label`,
|
|
92
|
+
inputRef: inputRef,
|
|
93
|
+
id: `${id}-input`,
|
|
94
|
+
value: selectedAggregationRule,
|
|
95
|
+
label: label,
|
|
96
|
+
color: "primary",
|
|
97
|
+
onChange: handleAggregationItemChange,
|
|
98
|
+
MenuProps: {
|
|
99
|
+
PaperProps: {
|
|
100
|
+
onKeyDown: handleSelectKeyDown
|
|
101
|
+
}
|
|
67
102
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
value:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
aggregationFunction: rootProps.aggregationFunctions[aggFunc]
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
}, aggFunc))]
|
|
93
|
-
})]
|
|
94
|
-
})
|
|
95
|
-
})]
|
|
103
|
+
onBlur: event => event.stopPropagation(),
|
|
104
|
+
native: isBaseSelectNative,
|
|
105
|
+
fullWidth: true
|
|
106
|
+
}, baseSelectProps, {
|
|
107
|
+
children: [/*#__PURE__*/_jsx(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
|
|
108
|
+
native: isBaseSelectNative,
|
|
109
|
+
value: "",
|
|
110
|
+
children: "..."
|
|
111
|
+
})), availableAggregationFunctions.map(aggFunc => /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
|
|
112
|
+
key: aggFunc,
|
|
113
|
+
value: aggFunc,
|
|
114
|
+
native: isBaseSelectNative
|
|
115
|
+
}), getAggregationFunctionLabel({
|
|
116
|
+
apiRef,
|
|
117
|
+
aggregationRule: {
|
|
118
|
+
aggregationFunctionName: aggFunc,
|
|
119
|
+
aggregationFunction: rootProps.aggregationFunctions[aggFunc]
|
|
120
|
+
}
|
|
121
|
+
})))]
|
|
122
|
+
}))]
|
|
123
|
+
})
|
|
96
124
|
});
|
|
97
125
|
}
|
|
98
126
|
process.env.NODE_ENV !== "production" ? GridColumnMenuAggregationItem.propTypes = {
|
|
@@ -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
|
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
5
|
+
import useEventCallback from '@mui/utils/useEventCallback';
|
|
6
|
+
import { getDataGridUtilityClass, GRID_CHECKBOX_SELECTION_FIELD, gridColumnDefinitionsSelector, gridColumnLookupSelector, GridLogicOperator, gridRowsLookupSelector } from '@mui/x-data-grid';
|
|
7
|
+
import { getValueOptions, getVisibleRows } from '@mui/x-data-grid/internals';
|
|
8
|
+
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.js";
|
|
9
|
+
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.js";
|
|
10
|
+
import { RecordButton, BrowserSpeechRecognition } from "./RecordButton.js";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
const supportsSpeechRecognition = !!BrowserSpeechRecognition;
|
|
13
|
+
const useUtilityClasses = ownerState => {
|
|
14
|
+
const {
|
|
15
|
+
classes,
|
|
16
|
+
recording
|
|
17
|
+
} = ownerState;
|
|
18
|
+
const slots = {
|
|
19
|
+
root: ['toolbarPromptControl', recording && 'toolbarPromptControl--recording'],
|
|
20
|
+
recordingIndicator: ['toolbarPromptControlRecordingIndicator'],
|
|
21
|
+
recordButton: ['toolbarPromptControlRecordButton'],
|
|
22
|
+
sendButton: ['toolbarPromptControlSendButton']
|
|
23
|
+
};
|
|
24
|
+
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
25
|
+
};
|
|
26
|
+
const GridToolbarPromptControlRoot = styled('div', {
|
|
27
|
+
name: 'MuiDataGrid',
|
|
28
|
+
slot: 'ToolbarPromptControl',
|
|
29
|
+
overridesResolver: (props, styles) => {
|
|
30
|
+
const {
|
|
31
|
+
ownerState
|
|
32
|
+
} = props;
|
|
33
|
+
return [styles.toolbarPromptControl, ownerState.recording && styles['toolbarPromptControl--recording']];
|
|
34
|
+
}
|
|
35
|
+
})({
|
|
36
|
+
flex: 1,
|
|
37
|
+
display: 'flex',
|
|
38
|
+
flexDirection: 'row'
|
|
39
|
+
});
|
|
40
|
+
function sampleData(apiRef) {
|
|
41
|
+
const columns = gridColumnDefinitionsSelector(apiRef);
|
|
42
|
+
const rows = Object.values(gridRowsLookupSelector(apiRef));
|
|
43
|
+
const columnExamples = {};
|
|
44
|
+
columns.forEach(column => {
|
|
45
|
+
columnExamples[column.field] = Array.from({
|
|
46
|
+
length: Math.min(5, rows.length)
|
|
47
|
+
}).map(() => {
|
|
48
|
+
const row = rows[Math.floor(Math.random() * rows.length)];
|
|
49
|
+
if (column.valueGetter) {
|
|
50
|
+
return column.valueGetter(row[column.field], row, column, apiRef);
|
|
51
|
+
}
|
|
52
|
+
return row[column.field];
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return columnExamples;
|
|
56
|
+
}
|
|
57
|
+
function generateContext(apiRef, examples) {
|
|
58
|
+
const columns = gridColumnDefinitionsSelector(apiRef);
|
|
59
|
+
const columnsContext = columns.map(column => ({
|
|
60
|
+
field: column.field,
|
|
61
|
+
description: column.description ?? null,
|
|
62
|
+
examples: examples?.[column.field] ?? column.unstable_examples ?? [],
|
|
63
|
+
type: column.type ?? 'string',
|
|
64
|
+
allowedOperators: column.filterOperators?.map(operator => operator.value) ?? []
|
|
65
|
+
}));
|
|
66
|
+
return `The columns are described by the following JSON:\n${JSON.stringify(columnsContext)}`;
|
|
67
|
+
}
|
|
68
|
+
function GridToolbarPromptControl(props) {
|
|
69
|
+
const apiRef = useGridApiContext();
|
|
70
|
+
const rootProps = useGridRootProps();
|
|
71
|
+
const {
|
|
72
|
+
onPrompt,
|
|
73
|
+
lang,
|
|
74
|
+
allowDataSampling = false
|
|
75
|
+
} = props;
|
|
76
|
+
const [isLoading, setLoading] = React.useState(false);
|
|
77
|
+
const [error, setError] = React.useState(null);
|
|
78
|
+
const [isRecording, setRecording] = React.useState(false);
|
|
79
|
+
const [query, setQuery] = React.useState('');
|
|
80
|
+
const ownerState = {
|
|
81
|
+
classes: rootProps.classes,
|
|
82
|
+
recording: isRecording
|
|
83
|
+
};
|
|
84
|
+
const classes = useUtilityClasses(ownerState);
|
|
85
|
+
const examplesFromData = React.useMemo(() => allowDataSampling ? sampleData(apiRef) : undefined, [apiRef, allowDataSampling]);
|
|
86
|
+
const processPrompt = React.useCallback(() => {
|
|
87
|
+
const context = generateContext(apiRef, examplesFromData);
|
|
88
|
+
const columnsByField = gridColumnLookupSelector(apiRef);
|
|
89
|
+
setLoading(true);
|
|
90
|
+
setError(null);
|
|
91
|
+
apiRef.current.setLoading(true);
|
|
92
|
+
onPrompt(context, query).then(result => {
|
|
93
|
+
const interestColumns = [];
|
|
94
|
+
apiRef.current.setFilterModel({
|
|
95
|
+
items: result.filters.map((filter, index) => {
|
|
96
|
+
const item = {
|
|
97
|
+
id: index,
|
|
98
|
+
field: filter.column,
|
|
99
|
+
operator: filter.operator,
|
|
100
|
+
value: filter.value
|
|
101
|
+
};
|
|
102
|
+
const column = columnsByField[filter.column];
|
|
103
|
+
if (column.type === 'singleSelect') {
|
|
104
|
+
const options = getValueOptions(column) ?? [];
|
|
105
|
+
const found = options.find(option => typeof option === 'object' && option.label === filter.value);
|
|
106
|
+
if (found) {
|
|
107
|
+
item.value = found.value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return item;
|
|
111
|
+
}),
|
|
112
|
+
logicOperator: result.filterOperator ?? GridLogicOperator.And,
|
|
113
|
+
quickFilterValues: []
|
|
114
|
+
});
|
|
115
|
+
apiRef.current.setRowGroupingModel(result.grouping.map(g => g.column));
|
|
116
|
+
apiRef.current.setAggregationModel(result.aggregation);
|
|
117
|
+
apiRef.current.setSortModel(result.sorting.map(s => ({
|
|
118
|
+
field: s.column,
|
|
119
|
+
sort: s.direction
|
|
120
|
+
})));
|
|
121
|
+
const rows = getVisibleRows(apiRef, rootProps);
|
|
122
|
+
const selectedRowIds = result.select === -1 ? [] : rows.rows.slice(0, result.select).map(r => {
|
|
123
|
+
return apiRef.current.getRowId(r);
|
|
124
|
+
});
|
|
125
|
+
apiRef.current.setRowSelectionModel(selectedRowIds);
|
|
126
|
+
const columns = apiRef.current.getAllColumns();
|
|
127
|
+
const targetIndex = Number(columns.find(c => c.field === GRID_CHECKBOX_SELECTION_FIELD) !== undefined) + Number(result.grouping.length);
|
|
128
|
+
interestColumns.push(...Object.keys(result.aggregation));
|
|
129
|
+
interestColumns.push(...result.filters.map(f => f.column));
|
|
130
|
+
interestColumns.reverse().forEach(c => apiRef.current.setColumnIndex(c, targetIndex));
|
|
131
|
+
}).catch(_ => {
|
|
132
|
+
setError(apiRef.current.getLocaleText('toolbarPromptControlErrorMessage'));
|
|
133
|
+
}).finally(() => {
|
|
134
|
+
setLoading(false);
|
|
135
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
136
|
+
rows: _extends({}, state.rows, {
|
|
137
|
+
loading: false
|
|
138
|
+
})
|
|
139
|
+
}));
|
|
140
|
+
});
|
|
141
|
+
}, [apiRef, rootProps, onPrompt, examplesFromData, query]);
|
|
142
|
+
const handleChange = useEventCallback(event => {
|
|
143
|
+
setQuery(event.target.value);
|
|
144
|
+
});
|
|
145
|
+
const handleKeyDown = useEventCallback(event => {
|
|
146
|
+
if (event.code === 'Enter') {
|
|
147
|
+
processPrompt();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const handleDone = useEventCallback(value => {
|
|
151
|
+
setQuery(value);
|
|
152
|
+
if (value) {
|
|
153
|
+
processPrompt();
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const placeholder = supportsSpeechRecognition ? apiRef.current.getLocaleText('toolbarPromptControlWithRecordingPlaceholder') : apiRef.current.getLocaleText('toolbarPromptControlPlaceholder');
|
|
157
|
+
return /*#__PURE__*/_jsx(GridToolbarPromptControlRoot, {
|
|
158
|
+
ownerState: ownerState,
|
|
159
|
+
className: classes.root,
|
|
160
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.baseTextField, {
|
|
161
|
+
placeholder: isRecording ? apiRef.current.getLocaleText('toolbarPromptControlRecordingPlaceholder') : placeholder,
|
|
162
|
+
"aria-label": apiRef.current.getLocaleText('toolbarPromptControlLabel'),
|
|
163
|
+
disabled: isLoading,
|
|
164
|
+
value: query,
|
|
165
|
+
style: {
|
|
166
|
+
flex: 1
|
|
167
|
+
},
|
|
168
|
+
onChange: handleChange,
|
|
169
|
+
size: "small",
|
|
170
|
+
onKeyDown: handleKeyDown,
|
|
171
|
+
error: !!error,
|
|
172
|
+
helperText: error,
|
|
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
|
+
})
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
export { GridToolbarPromptControl };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Timeout } from '@mui/utils/useTimeout';
|
|
3
|
+
import useLazyRef from '@mui/utils/useLazyRef';
|
|
4
|
+
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.js";
|
|
5
|
+
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.js";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export const BrowserSpeechRecognition = globalThis.SpeechRecognition || globalThis.webkitSpeechRecognition;
|
|
8
|
+
function RecordButton(props) {
|
|
9
|
+
const apiRef = useGridApiContext();
|
|
10
|
+
const rootProps = useGridRootProps();
|
|
11
|
+
const {
|
|
12
|
+
lang,
|
|
13
|
+
recording,
|
|
14
|
+
setRecording,
|
|
15
|
+
disabled,
|
|
16
|
+
className,
|
|
17
|
+
onDone,
|
|
18
|
+
onUpdate,
|
|
19
|
+
onError
|
|
20
|
+
} = props;
|
|
21
|
+
const buttonRef = React.useRef(null);
|
|
22
|
+
const recognition = useLazyRef(() => {
|
|
23
|
+
if (!BrowserSpeechRecognition) {
|
|
24
|
+
return {
|
|
25
|
+
start: () => {},
|
|
26
|
+
abort: () => {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const timeout = new Timeout();
|
|
30
|
+
const instance = new BrowserSpeechRecognition();
|
|
31
|
+
instance.continuous = true;
|
|
32
|
+
instance.interimResults = true;
|
|
33
|
+
instance.lang = lang;
|
|
34
|
+
let finalResult = '';
|
|
35
|
+
let interimResult = '';
|
|
36
|
+
function start(options) {
|
|
37
|
+
if (recording) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
setRecording(true);
|
|
41
|
+
instance.onresult = event => {
|
|
42
|
+
finalResult = '';
|
|
43
|
+
interimResult = '';
|
|
44
|
+
if (typeof event.results === 'undefined') {
|
|
45
|
+
instance.stop();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
for (let i = event.resultIndex; i < event.results.length; i += 1) {
|
|
49
|
+
if (event.results[i].isFinal) {
|
|
50
|
+
finalResult += event.results[i][0].transcript;
|
|
51
|
+
} else {
|
|
52
|
+
interimResult += event.results[i][0].transcript;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (finalResult === '') {
|
|
56
|
+
options.onUpdate(interimResult);
|
|
57
|
+
}
|
|
58
|
+
timeout.start(1000, () => instance.stop());
|
|
59
|
+
};
|
|
60
|
+
instance.onsoundend = () => {
|
|
61
|
+
instance.stop();
|
|
62
|
+
};
|
|
63
|
+
instance.onend = () => {
|
|
64
|
+
options.onDone(finalResult);
|
|
65
|
+
setRecording(false);
|
|
66
|
+
};
|
|
67
|
+
instance.onerror = error => {
|
|
68
|
+
options.onError(error.message);
|
|
69
|
+
instance.stop();
|
|
70
|
+
setRecording(false);
|
|
71
|
+
};
|
|
72
|
+
instance.start();
|
|
73
|
+
}
|
|
74
|
+
function abort() {
|
|
75
|
+
instance.abort();
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
start,
|
|
79
|
+
abort
|
|
80
|
+
};
|
|
81
|
+
}).current;
|
|
82
|
+
const handleClick = () => {
|
|
83
|
+
if (!recording) {
|
|
84
|
+
recognition.start({
|
|
85
|
+
onDone,
|
|
86
|
+
onUpdate,
|
|
87
|
+
onError
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
recognition.abort();
|
|
92
|
+
};
|
|
93
|
+
return /*#__PURE__*/_jsx(rootProps.slots.baseTooltip, {
|
|
94
|
+
title: recording ? apiRef.current.getLocaleText('toolbarPromptControlRecordButtonActiveLabel') : apiRef.current.getLocaleText('toolbarPromptControlRecordButtonDefaultLabel'),
|
|
95
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
96
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, {
|
|
97
|
+
color: recording ? 'primary' : 'default',
|
|
98
|
+
className: className,
|
|
99
|
+
disabled: disabled,
|
|
100
|
+
onClick: handleClick,
|
|
101
|
+
ref: buttonRef,
|
|
102
|
+
size: "small",
|
|
103
|
+
edge: "start",
|
|
104
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.toolbarPromptRecordIcon, {
|
|
105
|
+
fontSize: "small"
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export { RecordButton };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GridToolbarPromptControl as Unstable_GridToolbarPromptControl } from "./GridToolbarPromptControl.js";
|