@mui/x-data-grid 6.0.0-beta.3 → 6.0.0-beta.4
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 +71 -0
- package/colDef/gridSingleSelectColDef.d.ts +2 -2
- package/colDef/gridSingleSelectColDef.js +4 -1
- package/components/GridPagination.d.ts +3 -3
- package/components/cell/GridActionsCellItem.d.ts +5 -5
- package/components/cell/GridEditInputCell.d.ts +1 -1
- package/components/cell/GridEditSingleSelectCell.d.ts +1 -1
- package/components/cell/GridEditSingleSelectCell.js +16 -9
- package/components/panel/GridColumnsPanel.js +1 -0
- package/components/panel/GridPanel.d.ts +1 -1
- package/components/panel/GridPanelWrapper.d.ts +4 -0
- package/components/panel/GridPanelWrapper.js +15 -5
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +16 -9
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +17 -8
- package/components/panel/filterPanel/filterPanelUtils.d.ts +2 -1
- package/components/panel/filterPanel/filterPanelUtils.js +3 -0
- package/components/toolbar/GridToolbar.d.ts +1 -1
- package/components/toolbar/GridToolbarColumnsButton.d.ts +1 -1
- package/components/toolbar/GridToolbarDensitySelector.d.ts +1 -1
- package/components/toolbar/GridToolbarExport.d.ts +1 -1
- package/components/toolbar/GridToolbarExportContainer.d.ts +1 -1
- package/components/toolbar/GridToolbarFilterButton.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
- package/index.js +1 -1
- package/internals/index.d.ts +2 -1
- package/internals/index.js +1 -0
- package/legacy/colDef/gridSingleSelectColDef.js +4 -1
- package/legacy/components/cell/GridEditSingleSelectCell.js +16 -9
- package/legacy/components/panel/GridColumnsPanel.js +1 -0
- package/legacy/components/panel/GridPanelWrapper.js +15 -4
- package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +16 -9
- package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +17 -8
- package/legacy/components/panel/filterPanel/filterPanelUtils.js +3 -0
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +1 -0
- package/models/colDef/gridColDef.d.ts +18 -5
- package/models/colDef/index.d.ts +1 -1
- package/modern/colDef/gridSingleSelectColDef.js +4 -1
- package/modern/components/cell/GridEditSingleSelectCell.js +15 -9
- package/modern/components/panel/GridColumnsPanel.js +1 -0
- package/modern/components/panel/GridPanelWrapper.js +15 -5
- package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +14 -8
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +17 -8
- package/modern/components/panel/filterPanel/filterPanelUtils.js +3 -0
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -0
- package/node/colDef/gridSingleSelectColDef.js +3 -0
- package/node/components/cell/GridEditSingleSelectCell.js +14 -8
- package/node/components/panel/GridColumnsPanel.js +1 -0
- package/node/components/panel/GridPanelWrapper.js +16 -6
- package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +13 -7
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +16 -7
- package/node/components/panel/filterPanel/filterPanelUtils.js +4 -0
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
- package/node/index.js +1 -1
- package/node/internals/index.js +7 -0
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
|
|
|
6
6
|
import { unstable_useId as useId } from '@mui/utils';
|
|
7
7
|
import MenuItem from '@mui/material/MenuItem';
|
|
8
8
|
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
|
|
9
|
-
import { getLabelFromValueOption, getValueFromValueOptions } from './filterPanelUtils';
|
|
9
|
+
import { getLabelFromValueOption, getValueFromValueOptions, isSingleSelectColDef } from './filterPanelUtils';
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
const renderSingleSelectOptions = ({
|
|
12
12
|
valueOptions,
|
|
@@ -41,15 +41,21 @@ function GridFilterInputSingleSelect(props) {
|
|
|
41
41
|
const rootProps = useGridRootProps();
|
|
42
42
|
const baseSelectProps = ((_rootProps$components = rootProps.componentsProps) == null ? void 0 : _rootProps$components.baseSelect) || {};
|
|
43
43
|
const isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : true;
|
|
44
|
-
|
|
44
|
+
let resolvedColumn = null;
|
|
45
|
+
if (item.field) {
|
|
46
|
+
const column = apiRef.current.getColumn(item.field);
|
|
47
|
+
if (isSingleSelectColDef(column)) {
|
|
48
|
+
resolvedColumn = column;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
45
51
|
const currentValueOptions = React.useMemo(() => {
|
|
46
|
-
if (
|
|
52
|
+
if (!resolvedColumn) {
|
|
47
53
|
return undefined;
|
|
48
54
|
}
|
|
49
|
-
return typeof
|
|
50
|
-
field:
|
|
51
|
-
}) :
|
|
52
|
-
}, [
|
|
55
|
+
return typeof resolvedColumn.valueOptions === 'function' ? resolvedColumn.valueOptions({
|
|
56
|
+
field: resolvedColumn.field
|
|
57
|
+
}) : resolvedColumn.valueOptions;
|
|
58
|
+
}, [resolvedColumn]);
|
|
53
59
|
const onFilterChange = React.useCallback(event => {
|
|
54
60
|
let value = event.target.value;
|
|
55
61
|
|
|
@@ -78,6 +84,9 @@ function GridFilterInputSingleSelect(props) {
|
|
|
78
84
|
itemValue = (_itemValue = itemValue) != null ? _itemValue : '';
|
|
79
85
|
setFilterValueState(String(itemValue));
|
|
80
86
|
}, [item, currentValueOptions, applyValue]);
|
|
87
|
+
if (!isSingleSelectColDef(resolvedColumn)) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
81
90
|
return /*#__PURE__*/_jsx(rootProps.components.BaseTextField, _extends({
|
|
82
91
|
id: id,
|
|
83
92
|
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
|
|
@@ -95,7 +104,7 @@ function GridFilterInputSingleSelect(props) {
|
|
|
95
104
|
native: isSelectNative
|
|
96
105
|
}, (_rootProps$components2 = rootProps.componentsProps) == null ? void 0 : _rootProps$components2.baseSelect)
|
|
97
106
|
}, others, (_rootProps$components3 = rootProps.componentsProps) == null ? void 0 : _rootProps$components3.baseTextField, {
|
|
98
|
-
children: renderSingleSelectOptions(
|
|
107
|
+
children: renderSingleSelectOptions(resolvedColumn, isSelectNative ? 'option' : MenuItem, getOptionLabel)
|
|
99
108
|
}));
|
|
100
109
|
}
|
|
101
110
|
process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes = {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ValueOptions } from '../../../models/colDef/gridColDef';
|
|
1
|
+
import type { GridColDef, GridSingleSelectColDef, ValueOptions } from '../../../models/colDef/gridColDef';
|
|
2
|
+
export declare function isSingleSelectColDef(colDef: GridColDef | null): colDef is GridSingleSelectColDef;
|
|
2
3
|
export declare function getValueFromOption(option: any | undefined): any;
|
|
3
4
|
export declare function getValueFromValueOptions(value: string, valueOptions?: any[]): any;
|
|
4
5
|
export declare const getLabelFromValueOption: (valueOption: ValueOptions) => string;
|
|
@@ -13,5 +13,5 @@ export interface GridToolbarProps extends GridToolbarContainerProps, Omit<GridTo
|
|
|
13
13
|
*/
|
|
14
14
|
quickFilterProps?: GridToolbarQuickFilterProps;
|
|
15
15
|
}
|
|
16
|
-
declare const GridToolbar: React.ForwardRefExoticComponent<
|
|
16
|
+
declare const GridToolbar: React.ForwardRefExoticComponent<Omit<GridToolbarProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
17
17
|
export { GridToolbar };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ButtonProps } from '@mui/material/Button';
|
|
3
|
-
export declare const GridToolbarColumnsButton: React.ForwardRefExoticComponent<
|
|
3
|
+
export declare const GridToolbarColumnsButton: React.ForwardRefExoticComponent<Omit<ButtonProps<"button", {}>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ButtonProps } from '@mui/material/Button';
|
|
3
|
-
export declare const GridToolbarDensitySelector: React.ForwardRefExoticComponent<
|
|
3
|
+
export declare const GridToolbarDensitySelector: React.ForwardRefExoticComponent<Omit<ButtonProps<"button", {}>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -21,5 +21,5 @@ export interface GridToolbarExportProps extends ButtonProps {
|
|
|
21
21
|
}
|
|
22
22
|
export declare function GridCsvExportMenuItem(props: GridCsvExportMenuItemProps): JSX.Element;
|
|
23
23
|
export declare function GridPrintExportMenuItem(props: GridPrintExportMenuItemProps): JSX.Element;
|
|
24
|
-
declare const GridToolbarExport: React.ForwardRefExoticComponent<
|
|
24
|
+
declare const GridToolbarExport: React.ForwardRefExoticComponent<Omit<GridToolbarExportProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
25
25
|
export { GridToolbarExport };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ButtonProps } from '@mui/material/Button';
|
|
3
|
-
export declare const GridToolbarExportContainer: React.ForwardRefExoticComponent<
|
|
3
|
+
export declare const GridToolbarExportContainer: React.ForwardRefExoticComponent<Omit<ButtonProps<"button", {}>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -10,5 +10,5 @@ export interface GridToolbarFilterButtonProps extends Omit<TooltipProps, 'title'
|
|
|
10
10
|
button?: ButtonProps;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
declare const GridToolbarFilterButton: React.ForwardRefExoticComponent<
|
|
13
|
+
declare const GridToolbarFilterButton: React.ForwardRefExoticComponent<Omit<GridToolbarFilterButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
14
14
|
export { GridToolbarFilterButton };
|
|
@@ -51,6 +51,12 @@ export const getRenderableIndexes = ({
|
|
|
51
51
|
}) => {
|
|
52
52
|
return [clamp(firstIndex - buffer, minFirstIndex, maxLastIndex), clamp(lastIndex + buffer, minFirstIndex, maxLastIndex)];
|
|
53
53
|
};
|
|
54
|
+
const areRenderContextsEqual = (context1, context2) => {
|
|
55
|
+
if (context1 === context2) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
|
|
59
|
+
};
|
|
54
60
|
export const useGridVirtualScroller = props => {
|
|
55
61
|
var _currentPage$range3, _currentPage$range4;
|
|
56
62
|
const apiRef = useGridPrivateApiContext();
|
|
@@ -207,6 +213,10 @@ export const useGridVirtualScroller = props => {
|
|
|
207
213
|
}
|
|
208
214
|
}, [apiRef, currentPage.rows, onRenderZonePositioning, renderZoneMinColumnIndex, renderZoneMaxColumnIndex, rootProps.columnBuffer, rootProps.rowBuffer, theme.direction]);
|
|
209
215
|
const updateRenderContext = React.useCallback(nextRenderContext => {
|
|
216
|
+
if (prevRenderContext.current && areRenderContextsEqual(nextRenderContext, prevRenderContext.current)) {
|
|
217
|
+
updateRenderZonePosition(nextRenderContext);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
210
220
|
setRenderContext(nextRenderContext);
|
|
211
221
|
updateRenderZonePosition(nextRenderContext);
|
|
212
222
|
const [firstRowToRender, lastRowToRender] = getRenderableIndexes({
|
package/index.js
CHANGED
package/internals/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { GridBaseColDef, GridStateColDef } from '../models/colDef/gridColDef';
|
|
1
|
+
export type { GridBaseColDef, GridStateColDef, GridSingleSelectColDef, } from '../models/colDef/gridColDef';
|
|
2
2
|
export { GridVirtualScroller } from '../components/virtualization/GridVirtualScroller';
|
|
3
3
|
export { GridVirtualScrollerContent } from '../components/virtualization/GridVirtualScrollerContent';
|
|
4
4
|
export { GridVirtualScrollerRenderZone } from '../components/virtualization/GridVirtualScrollerRenderZone';
|
|
@@ -22,6 +22,7 @@ export { useGridCsvExport } from '../hooks/features/export/useGridCsvExport';
|
|
|
22
22
|
export { useGridPrintExport } from '../hooks/features/export/useGridPrintExport';
|
|
23
23
|
export { useGridFilter, filterStateInitializer } from '../hooks/features/filter/useGridFilter';
|
|
24
24
|
export { passFilterLogic } from '../hooks/features/filter/gridFilterUtils';
|
|
25
|
+
export { isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
|
|
25
26
|
export type { GridAggregatedFilterItemApplier } from '../hooks/features/filter/gridFilterState';
|
|
26
27
|
export { useGridFocus, focusStateInitializer } from '../hooks/features/focus/useGridFocus';
|
|
27
28
|
export { useGridKeyboardNavigation } from '../hooks/features/keyboardNavigation/useGridKeyboardNavigation';
|
package/internals/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { useGridCsvExport } from '../hooks/features/export/useGridCsvExport';
|
|
|
18
18
|
export { useGridPrintExport } from '../hooks/features/export/useGridPrintExport';
|
|
19
19
|
export { useGridFilter, filterStateInitializer } from '../hooks/features/filter/useGridFilter';
|
|
20
20
|
export { passFilterLogic } from '../hooks/features/filter/gridFilterUtils';
|
|
21
|
+
export { isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
|
|
21
22
|
export { useGridFocus, focusStateInitializer } from '../hooks/features/focus/useGridFocus';
|
|
22
23
|
export { useGridKeyboardNavigation } from '../hooks/features/keyboardNavigation/useGridKeyboardNavigation';
|
|
23
24
|
export { useGridPagination, paginationStateInitializer } from '../hooks/features/pagination/useGridPagination';
|
|
@@ -3,7 +3,7 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
|
3
3
|
import { GRID_STRING_COL_DEF } from './gridStringColDef';
|
|
4
4
|
import { renderEditSingleSelectCell } from '../components/cell/GridEditSingleSelectCell';
|
|
5
5
|
import { getGridSingleSelectOperators } from './gridSingleSelectOperators';
|
|
6
|
-
import { getLabelFromValueOption } from '../components/panel/filterPanel/filterPanelUtils';
|
|
6
|
+
import { getLabelFromValueOption, isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
|
|
7
7
|
var isArrayOfObjects = function isArrayOfObjects(options) {
|
|
8
8
|
return _typeof(options[0]) === 'object';
|
|
9
9
|
};
|
|
@@ -15,6 +15,9 @@ export var GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
|
15
15
|
value = params.value,
|
|
16
16
|
api = params.api;
|
|
17
17
|
var colDef = params.api.getColumn(field);
|
|
18
|
+
if (!isSingleSelectColDef(colDef)) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
18
21
|
var valueOptions;
|
|
19
22
|
if (typeof colDef.valueOptions === 'function') {
|
|
20
23
|
valueOptions = colDef.valueOptions({
|
|
@@ -12,7 +12,7 @@ import MenuItem from '@mui/material/MenuItem';
|
|
|
12
12
|
import { isEscapeKey } from '../../utils/keyboardUtils';
|
|
13
13
|
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
14
14
|
import { GridEditModes } from '../../models/gridEditRowModel';
|
|
15
|
-
import { getLabelFromValueOption, getValueFromValueOptions } from '../panel/filterPanel/filterPanelUtils';
|
|
15
|
+
import { getLabelFromValueOption, getValueFromValueOptions, isSingleSelectColDef } from '../panel/filterPanel/filterPanelUtils';
|
|
16
16
|
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
18
|
function isKeyboardEvent(event) {
|
|
@@ -52,15 +52,27 @@ function GridEditSingleSelectCell(props) {
|
|
|
52
52
|
setOpen = _React$useState2[1];
|
|
53
53
|
var baseSelectProps = ((_rootProps$components = rootProps.componentsProps) == null ? void 0 : _rootProps$components.baseSelect) || {};
|
|
54
54
|
var isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : false;
|
|
55
|
+
useEnhancedEffect(function () {
|
|
56
|
+
if (hasFocus) {
|
|
57
|
+
var _inputRef$current;
|
|
58
|
+
(_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
59
|
+
}
|
|
60
|
+
}, [hasFocus]);
|
|
61
|
+
if (!isSingleSelectColDef(colDef)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
55
64
|
var valueOptions;
|
|
56
|
-
if (typeof colDef.valueOptions === 'function') {
|
|
57
|
-
valueOptions = colDef.valueOptions({
|
|
65
|
+
if (typeof (colDef == null ? void 0 : colDef.valueOptions) === 'function') {
|
|
66
|
+
valueOptions = colDef == null ? void 0 : colDef.valueOptions({
|
|
58
67
|
id: id,
|
|
59
68
|
row: row,
|
|
60
69
|
field: field
|
|
61
70
|
});
|
|
62
71
|
} else {
|
|
63
|
-
valueOptions = colDef.valueOptions;
|
|
72
|
+
valueOptions = colDef == null ? void 0 : colDef.valueOptions;
|
|
73
|
+
}
|
|
74
|
+
if (!valueOptions) {
|
|
75
|
+
return null;
|
|
64
76
|
}
|
|
65
77
|
var handleChange = /*#__PURE__*/function () {
|
|
66
78
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
|
|
@@ -115,11 +127,6 @@ function GridEditSingleSelectCell(props) {
|
|
|
115
127
|
}
|
|
116
128
|
setOpen(true);
|
|
117
129
|
};
|
|
118
|
-
useEnhancedEffect(function () {
|
|
119
|
-
if (hasFocus) {
|
|
120
|
-
inputRef.current.focus();
|
|
121
|
-
}
|
|
122
|
-
}, [hasFocus]);
|
|
123
130
|
var OptionComponent = isSelectNative ? 'option' : MenuItem;
|
|
124
131
|
return /*#__PURE__*/_jsx(rootProps.components.BaseSelect, _extends({
|
|
125
132
|
ref: ref,
|
|
@@ -220,6 +220,7 @@ process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
|
|
|
220
220
|
disableHideAllButton: PropTypes.bool,
|
|
221
221
|
disableShowAllButton: PropTypes.bool,
|
|
222
222
|
searchPredicate: PropTypes.func,
|
|
223
|
+
slotProps: PropTypes.object,
|
|
223
224
|
sort: PropTypes.oneOf(['asc', 'desc'])
|
|
224
225
|
} : void 0;
|
|
225
226
|
export { GridColumnsPanel };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["className"];
|
|
3
|
+
var _excluded = ["className", "slotProps"];
|
|
4
4
|
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
5
6
|
import clsx from 'clsx';
|
|
6
7
|
import TrapFocus from '@mui/material/Unstable_TrapFocus';
|
|
7
8
|
import { styled } from '@mui/material/styles';
|
|
@@ -35,21 +36,31 @@ var isEnabled = function isEnabled() {
|
|
|
35
36
|
};
|
|
36
37
|
var GridPanelWrapper = /*#__PURE__*/React.forwardRef(function GridPanelWrapper(props, ref) {
|
|
37
38
|
var className = props.className,
|
|
39
|
+
_props$slotProps = props.slotProps,
|
|
40
|
+
slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
|
|
38
41
|
other = _objectWithoutProperties(props, _excluded);
|
|
39
42
|
var rootProps = useGridRootProps();
|
|
40
43
|
var ownerState = {
|
|
41
44
|
classes: rootProps.classes
|
|
42
45
|
};
|
|
43
46
|
var classes = useUtilityClasses(ownerState);
|
|
44
|
-
return /*#__PURE__*/_jsx(TrapFocus, {
|
|
47
|
+
return /*#__PURE__*/_jsx(TrapFocus, _extends({
|
|
45
48
|
open: true,
|
|
46
49
|
disableEnforceFocus: true,
|
|
47
|
-
isEnabled: isEnabled
|
|
50
|
+
isEnabled: isEnabled
|
|
51
|
+
}, slotProps.TrapFocus, {
|
|
48
52
|
children: /*#__PURE__*/_jsx(GridPanelWrapperRoot, _extends({
|
|
49
53
|
ref: ref,
|
|
50
54
|
tabIndex: -1,
|
|
51
55
|
className: clsx(className, classes.root)
|
|
52
56
|
}, other))
|
|
53
|
-
});
|
|
57
|
+
}));
|
|
54
58
|
});
|
|
59
|
+
process.env.NODE_ENV !== "production" ? GridPanelWrapper.propTypes = {
|
|
60
|
+
// ----------------------------- Warning --------------------------------
|
|
61
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
62
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
63
|
+
// ----------------------------------------------------------------------
|
|
64
|
+
slotProps: PropTypes.object
|
|
65
|
+
} : void 0;
|
|
55
66
|
export { GridPanelWrapper };
|
|
@@ -7,7 +7,7 @@ import PropTypes from 'prop-types';
|
|
|
7
7
|
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
|
|
8
8
|
import Chip from '@mui/material/Chip';
|
|
9
9
|
import { unstable_useId as useId } from '@mui/utils';
|
|
10
|
-
import { getLabelFromValueOption, getValueFromOption } from './filterPanelUtils';
|
|
10
|
+
import { getLabelFromValueOption, getValueFromOption, isSingleSelectColDef } from './filterPanelUtils';
|
|
11
11
|
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
var isOptionEqualToValue = function isOptionEqualToValue(option, value) {
|
|
@@ -38,9 +38,16 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
38
38
|
};
|
|
39
39
|
var id = useId();
|
|
40
40
|
var rootProps = useGridRootProps();
|
|
41
|
-
var resolvedColumn =
|
|
41
|
+
var resolvedColumn = null;
|
|
42
|
+
if (item.field) {
|
|
43
|
+
var column = apiRef.current.getColumn(item.field);
|
|
44
|
+
if (isSingleSelectColDef(column)) {
|
|
45
|
+
resolvedColumn = column;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
42
48
|
var resolvedValueOptions = React.useMemo(function () {
|
|
43
|
-
|
|
49
|
+
var _resolvedColumn;
|
|
50
|
+
if (!((_resolvedColumn = resolvedColumn) != null && _resolvedColumn.valueOptions)) {
|
|
44
51
|
return [];
|
|
45
52
|
}
|
|
46
53
|
if (typeof resolvedColumn.valueOptions === 'function') {
|
|
@@ -56,7 +63,7 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
56
63
|
|
|
57
64
|
// The value is computed from the item.value and used directly
|
|
58
65
|
// If it was done by a useEffect/useState, the Autocomplete could receive incoherent value and options
|
|
59
|
-
var
|
|
66
|
+
var filteredValues = React.useMemo(function () {
|
|
60
67
|
if (!Array.isArray(item.value)) {
|
|
61
68
|
return [];
|
|
62
69
|
}
|
|
@@ -78,13 +85,13 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
78
85
|
return item.value;
|
|
79
86
|
}, [item.value, resolvedValueOptions, resolvedFormattedValueOptions]);
|
|
80
87
|
React.useEffect(function () {
|
|
81
|
-
if (!Array.isArray(item.value) ||
|
|
82
|
-
//
|
|
88
|
+
if (!Array.isArray(item.value) || filteredValues.length !== item.value.length) {
|
|
89
|
+
// Updates the state if the filter value has been cleaned by the component
|
|
83
90
|
applyValue(_extends({}, item, {
|
|
84
|
-
value:
|
|
91
|
+
value: filteredValues.map(getValueFromOption)
|
|
85
92
|
}));
|
|
86
93
|
}
|
|
87
|
-
}, [item,
|
|
94
|
+
}, [item, filteredValues, applyValue]);
|
|
88
95
|
var handleChange = React.useCallback(function (event, value) {
|
|
89
96
|
applyValue(_extends({}, item, {
|
|
90
97
|
value: _toConsumableArray(value.map(getValueFromOption))
|
|
@@ -96,7 +103,7 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
96
103
|
isOptionEqualToValue: isOptionEqualToValue,
|
|
97
104
|
filterOptions: filter,
|
|
98
105
|
id: id,
|
|
99
|
-
value:
|
|
106
|
+
value: filteredValues,
|
|
100
107
|
onChange: handleChange,
|
|
101
108
|
getOptionLabel: getOptionLabel,
|
|
102
109
|
renderTags: function renderTags(value, getTagProps) {
|
|
@@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
|
|
|
9
9
|
import { unstable_useId as useId } from '@mui/utils';
|
|
10
10
|
import MenuItem from '@mui/material/MenuItem';
|
|
11
11
|
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
|
|
12
|
-
import { getLabelFromValueOption, getValueFromValueOptions } from './filterPanelUtils';
|
|
12
|
+
import { getLabelFromValueOption, getValueFromValueOptions, isSingleSelectColDef } from './filterPanelUtils';
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
var renderSingleSelectOptions = function renderSingleSelectOptions(_ref, OptionComponent, getOptionLabel) {
|
|
15
15
|
var valueOptions = _ref.valueOptions,
|
|
@@ -45,15 +45,21 @@ function GridFilterInputSingleSelect(props) {
|
|
|
45
45
|
var rootProps = useGridRootProps();
|
|
46
46
|
var baseSelectProps = ((_rootProps$components = rootProps.componentsProps) == null ? void 0 : _rootProps$components.baseSelect) || {};
|
|
47
47
|
var isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : true;
|
|
48
|
-
var
|
|
48
|
+
var resolvedColumn = null;
|
|
49
|
+
if (item.field) {
|
|
50
|
+
var column = apiRef.current.getColumn(item.field);
|
|
51
|
+
if (isSingleSelectColDef(column)) {
|
|
52
|
+
resolvedColumn = column;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
49
55
|
var currentValueOptions = React.useMemo(function () {
|
|
50
|
-
if (
|
|
56
|
+
if (!resolvedColumn) {
|
|
51
57
|
return undefined;
|
|
52
58
|
}
|
|
53
|
-
return typeof
|
|
54
|
-
field:
|
|
55
|
-
}) :
|
|
56
|
-
}, [
|
|
59
|
+
return typeof resolvedColumn.valueOptions === 'function' ? resolvedColumn.valueOptions({
|
|
60
|
+
field: resolvedColumn.field
|
|
61
|
+
}) : resolvedColumn.valueOptions;
|
|
62
|
+
}, [resolvedColumn]);
|
|
57
63
|
var onFilterChange = React.useCallback(function (event) {
|
|
58
64
|
var value = event.target.value;
|
|
59
65
|
|
|
@@ -82,6 +88,9 @@ function GridFilterInputSingleSelect(props) {
|
|
|
82
88
|
itemValue = (_itemValue = itemValue) != null ? _itemValue : '';
|
|
83
89
|
setFilterValueState(String(itemValue));
|
|
84
90
|
}, [item, currentValueOptions, applyValue]);
|
|
91
|
+
if (!isSingleSelectColDef(resolvedColumn)) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
85
94
|
return /*#__PURE__*/_jsx(rootProps.components.BaseTextField, _extends({
|
|
86
95
|
id: id,
|
|
87
96
|
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
|
|
@@ -99,7 +108,7 @@ function GridFilterInputSingleSelect(props) {
|
|
|
99
108
|
native: isSelectNative
|
|
100
109
|
}, (_rootProps$components2 = rootProps.componentsProps) == null ? void 0 : _rootProps$components2.baseSelect)
|
|
101
110
|
}, others, (_rootProps$components3 = rootProps.componentsProps) == null ? void 0 : _rootProps$components3.baseTextField, {
|
|
102
|
-
children: renderSingleSelectOptions(
|
|
111
|
+
children: renderSingleSelectOptions(resolvedColumn, isSelectNative ? 'option' : MenuItem, getOptionLabel)
|
|
103
112
|
}));
|
|
104
113
|
}
|
|
105
114
|
process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes = {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
export function isSingleSelectColDef(colDef) {
|
|
3
|
+
return (colDef == null ? void 0 : colDef.type) === 'singleSelect';
|
|
4
|
+
}
|
|
2
5
|
export function getValueFromOption(option) {
|
|
3
6
|
if (_typeof(option) === 'object' && option !== null) {
|
|
4
7
|
return option.value;
|
|
@@ -53,6 +53,12 @@ export var getRenderableIndexes = function getRenderableIndexes(_ref) {
|
|
|
53
53
|
maxLastIndex = _ref.maxLastIndex;
|
|
54
54
|
return [clamp(firstIndex - buffer, minFirstIndex, maxLastIndex), clamp(lastIndex + buffer, minFirstIndex, maxLastIndex)];
|
|
55
55
|
};
|
|
56
|
+
var areRenderContextsEqual = function areRenderContextsEqual(context1, context2) {
|
|
57
|
+
if (context1 === context2) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
|
|
61
|
+
};
|
|
56
62
|
export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
57
63
|
var _currentPage$range3, _currentPage$range4;
|
|
58
64
|
var apiRef = useGridPrivateApiContext();
|
|
@@ -222,6 +228,10 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
|
222
228
|
}
|
|
223
229
|
}, [apiRef, currentPage.rows, onRenderZonePositioning, renderZoneMinColumnIndex, renderZoneMaxColumnIndex, rootProps.columnBuffer, rootProps.rowBuffer, theme.direction]);
|
|
224
230
|
var updateRenderContext = React.useCallback(function (nextRenderContext) {
|
|
231
|
+
if (prevRenderContext.current && areRenderContextsEqual(nextRenderContext, prevRenderContext.current)) {
|
|
232
|
+
updateRenderZonePosition(nextRenderContext);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
225
235
|
setRenderContext(nextRenderContext);
|
|
226
236
|
updateRenderZonePosition(nextRenderContext);
|
|
227
237
|
var _getRenderableIndexes7 = getRenderableIndexes({
|
package/legacy/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { useGridCsvExport } from '../hooks/features/export/useGridCsvExport';
|
|
|
18
18
|
export { useGridPrintExport } from '../hooks/features/export/useGridPrintExport';
|
|
19
19
|
export { useGridFilter, filterStateInitializer } from '../hooks/features/filter/useGridFilter';
|
|
20
20
|
export { passFilterLogic } from '../hooks/features/filter/gridFilterUtils';
|
|
21
|
+
export { isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
|
|
21
22
|
export { useGridFocus, focusStateInitializer } from '../hooks/features/focus/useGridFocus';
|
|
22
23
|
export { useGridKeyboardNavigation } from '../hooks/features/keyboardNavigation/useGridKeyboardNavigation';
|
|
23
24
|
export { useGridPagination, paginationStateInitializer } from '../hooks/features/pagination/useGridPagination';
|
|
@@ -106,10 +106,6 @@ export interface GridBaseColDef<R extends GridValidRowModel = GridValidRowModel,
|
|
|
106
106
|
* @default 'string'
|
|
107
107
|
*/
|
|
108
108
|
type?: GridColType;
|
|
109
|
-
/**
|
|
110
|
-
* To be used in combination with `type: 'singleSelect'`. This is an array (or a function returning an array) of the possible cell values and labels.
|
|
111
|
-
*/
|
|
112
|
-
valueOptions?: Array<ValueOptions> | ((params: GridValueOptionsParams<R>) => Array<ValueOptions>);
|
|
113
109
|
/**
|
|
114
110
|
* Allows to align the column values in cells.
|
|
115
111
|
*/
|
|
@@ -227,6 +223,9 @@ export interface GridBaseColDef<R extends GridValidRowModel = GridValidRowModel,
|
|
|
227
223
|
*/
|
|
228
224
|
colSpan?: number | ((params: GridCellParams<R, V, F>) => number | undefined);
|
|
229
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Column Definition interface used for columns with the `actions` type.
|
|
228
|
+
*/
|
|
230
229
|
export interface GridActionsColDef<R extends GridValidRowModel = any, V = any, F = V> extends GridBaseColDef<R, V, F> {
|
|
231
230
|
/**
|
|
232
231
|
* Type allows to merge this object with a default definition [[GridColDef]].
|
|
@@ -240,10 +239,24 @@ export interface GridActionsColDef<R extends GridValidRowModel = any, V = any, F
|
|
|
240
239
|
*/
|
|
241
240
|
getActions: (params: GridRowParams<R>) => React.ReactElement<GridActionsCellItemProps>[];
|
|
242
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Column Definition interface used for columns with the `singleSelect` type.
|
|
244
|
+
*/
|
|
245
|
+
export interface GridSingleSelectColDef<R extends GridValidRowModel = any, V = any, F = V> extends GridBaseColDef<R, V, F> {
|
|
246
|
+
/**
|
|
247
|
+
* Type allows to merge this object with a default definition [[GridColDef]].
|
|
248
|
+
* @default 'singleSelect'
|
|
249
|
+
*/
|
|
250
|
+
type: 'singleSelect';
|
|
251
|
+
/**
|
|
252
|
+
* To be used in combination with `type: 'singleSelect'`. This is an array (or a function returning an array) of the possible cell values and labels.
|
|
253
|
+
*/
|
|
254
|
+
valueOptions?: Array<ValueOptions> | ((params: GridValueOptionsParams<R>) => Array<ValueOptions>);
|
|
255
|
+
}
|
|
243
256
|
/**
|
|
244
257
|
* Column Definition interface.
|
|
245
258
|
*/
|
|
246
|
-
export type GridColDef<R extends GridValidRowModel = any, V = any, F = V> = GridBaseColDef<R, V, F> | GridActionsColDef<R, V, F>;
|
|
259
|
+
export type GridColDef<R extends GridValidRowModel = any, V = any, F = V> = GridBaseColDef<R, V, F> | GridActionsColDef<R, V, F> | GridSingleSelectColDef<R, V, F>;
|
|
247
260
|
export type GridColTypeDef<V = any, F = V> = Omit<GridBaseColDef<any, V, F>, 'field'> & {
|
|
248
261
|
extendType?: GridNativeColTypes;
|
|
249
262
|
};
|
package/models/colDef/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { GridAlignment, ValueOptions, GridKeyValue, GridColDef, GridColTypeDef, GridColumnsMeta, } from './gridColDef';
|
|
1
|
+
export type { GridAlignment, ValueOptions, GridKeyValue, GridColDef, GridColTypeDef, GridColumnsMeta, GridSingleSelectColDef, GridActionsColDef, } from './gridColDef';
|
|
2
2
|
export * from './gridColType';
|
|
3
3
|
export * from './gridColumnTypesRecord';
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { GRID_STRING_COL_DEF } from './gridStringColDef';
|
|
3
3
|
import { renderEditSingleSelectCell } from '../components/cell/GridEditSingleSelectCell';
|
|
4
4
|
import { getGridSingleSelectOperators } from './gridSingleSelectOperators';
|
|
5
|
-
import { getLabelFromValueOption } from '../components/panel/filterPanel/filterPanelUtils';
|
|
5
|
+
import { getLabelFromValueOption, isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
|
|
6
6
|
const isArrayOfObjects = options => {
|
|
7
7
|
return typeof options[0] === 'object';
|
|
8
8
|
};
|
|
@@ -16,6 +16,9 @@ export const GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
|
16
16
|
api
|
|
17
17
|
} = params;
|
|
18
18
|
const colDef = params.api.getColumn(field);
|
|
19
|
+
if (!isSingleSelectColDef(colDef)) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
19
22
|
let valueOptions;
|
|
20
23
|
if (typeof colDef.valueOptions === 'function') {
|
|
21
24
|
valueOptions = colDef.valueOptions({
|