@mui/x-data-grid 7.0.0-alpha.5 → 7.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +408 -6
  2. package/DataGrid/DataGrid.js +31 -21
  3. package/DataGrid/useDataGridProps.js +0 -1
  4. package/colDef/gridDateOperators.js +13 -6
  5. package/colDef/gridSingleSelectColDef.js +6 -15
  6. package/components/GridPagination.d.ts +2 -2
  7. package/components/cell/GridEditSingleSelectCell.d.ts +1 -2
  8. package/components/cell/GridEditSingleSelectCell.js +9 -29
  9. package/components/columnSelection/GridHeaderCheckbox.js +3 -1
  10. package/components/panel/filterPanel/GridFilterForm.js +44 -9
  11. package/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  12. package/components/panel/filterPanel/GridFilterInputDate.js +25 -8
  13. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -2
  14. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -48
  15. package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -2
  16. package/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -57
  17. package/components/panel/filterPanel/filterPanelUtils.d.ts +3 -2
  18. package/components/panel/filterPanel/filterPanelUtils.js +10 -5
  19. package/hooks/features/filter/gridFilterUtils.js +21 -24
  20. package/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  21. package/hooks/features/rowSelection/utils.d.ts +2 -0
  22. package/hooks/features/rowSelection/utils.js +8 -0
  23. package/hooks/utils/useGridAriaAttributes.js +2 -1
  24. package/index.js +1 -1
  25. package/legacy/DataGrid/DataGrid.js +31 -21
  26. package/legacy/DataGrid/useDataGridProps.js +0 -1
  27. package/legacy/colDef/gridDateOperators.js +13 -13
  28. package/legacy/colDef/gridSingleSelectColDef.js +6 -15
  29. package/legacy/components/cell/GridEditSingleSelectCell.js +8 -28
  30. package/legacy/components/columnSelection/GridHeaderCheckbox.js +3 -1
  31. package/legacy/components/panel/filterPanel/GridFilterForm.js +51 -19
  32. package/legacy/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  33. package/legacy/components/panel/filterPanel/GridFilterInputDate.js +27 -8
  34. package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -53
  35. package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -59
  36. package/legacy/components/panel/filterPanel/filterPanelUtils.js +10 -6
  37. package/legacy/hooks/features/filter/gridFilterUtils.js +20 -17
  38. package/legacy/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  39. package/legacy/hooks/features/rowSelection/utils.js +8 -0
  40. package/legacy/hooks/utils/useGridAriaAttributes.js +2 -1
  41. package/legacy/index.js +1 -1
  42. package/legacy/locales/csCZ.js +2 -2
  43. package/locales/csCZ.js +2 -2
  44. package/models/props/DataGridProps.d.ts +26 -26
  45. package/modern/DataGrid/DataGrid.js +31 -21
  46. package/modern/DataGrid/useDataGridProps.js +0 -1
  47. package/modern/colDef/gridDateOperators.js +13 -6
  48. package/modern/colDef/gridSingleSelectColDef.js +6 -15
  49. package/modern/components/cell/GridEditSingleSelectCell.js +9 -29
  50. package/modern/components/columnSelection/GridHeaderCheckbox.js +3 -1
  51. package/modern/components/panel/filterPanel/GridFilterForm.js +44 -9
  52. package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  53. package/modern/components/panel/filterPanel/GridFilterInputDate.js +24 -6
  54. package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -47
  55. package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -56
  56. package/modern/components/panel/filterPanel/filterPanelUtils.js +10 -5
  57. package/modern/hooks/features/filter/gridFilterUtils.js +21 -24
  58. package/modern/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  59. package/modern/hooks/features/rowSelection/utils.js +8 -0
  60. package/modern/hooks/utils/useGridAriaAttributes.js +2 -1
  61. package/modern/index.js +1 -1
  62. package/modern/locales/csCZ.js +2 -2
  63. package/node/DataGrid/DataGrid.js +31 -21
  64. package/node/DataGrid/useDataGridProps.js +0 -1
  65. package/node/colDef/gridDateOperators.js +13 -6
  66. package/node/colDef/gridSingleSelectColDef.js +5 -14
  67. package/node/components/cell/GridEditSingleSelectCell.js +8 -28
  68. package/node/components/columnSelection/GridHeaderCheckbox.js +3 -1
  69. package/node/components/panel/filterPanel/GridFilterForm.js +44 -9
  70. package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  71. package/node/components/panel/filterPanel/GridFilterInputDate.js +24 -6
  72. package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -46
  73. package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -55
  74. package/node/components/panel/filterPanel/filterPanelUtils.js +12 -7
  75. package/node/hooks/features/filter/gridFilterUtils.js +21 -23
  76. package/node/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  77. package/node/hooks/features/rowSelection/utils.js +14 -0
  78. package/node/hooks/utils/useGridAriaAttributes.js +2 -1
  79. package/node/index.js +1 -1
  80. package/node/locales/csCZ.js +2 -2
  81. package/package.json +4 -4
@@ -14,6 +14,7 @@ import { GridLogicOperator } from '../../../models/gridFilterItem';
14
14
  import { useGridApiContext } from '../../../hooks/utils/useGridApiContext';
15
15
  import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
16
16
  import { getDataGridUtilityClass } from '../../../constants/gridClasses';
17
+ import { getValueFromValueOptions, getValueOptions } from './filterPanelUtils';
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
18
19
  import { createElement as _createElement } from "react";
19
20
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -150,24 +151,37 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
150
151
  var hasLogicOperatorColumn = hasMultipleFilters && logicOperators.length > 0;
151
152
  var baseFormControlProps = ((_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseFormControl) || {};
152
153
  var baseSelectProps = ((_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseSelect) || {};
153
- var isBaseSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : true;
154
+ var isBaseSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : false;
154
155
  var baseInputLabelProps = ((_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseInputLabel) || {};
155
156
  var baseSelectOptionProps = ((_rootProps$slotProps4 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps4.baseSelectOption) || {};
156
157
  var InputComponentProps = valueInputProps.InputComponentProps,
157
158
  valueInputPropsOther = _objectWithoutProperties(valueInputProps, _excluded2);
158
- var filteredColumns = React.useMemo(function () {
159
- if (filterColumns === undefined || typeof filterColumns !== 'function') {
160
- return filterableColumns;
161
- }
162
- var filteredFields = filterColumns({
163
- field: item.field,
164
- columns: filterableColumns,
165
- currentFilters: (filterModel == null ? void 0 : filterModel.items) || []
166
- });
167
- return filterableColumns.filter(function (column) {
168
- return filteredFields.includes(column.field);
169
- });
170
- }, [filterColumns, filterModel == null ? void 0 : filterModel.items, filterableColumns, item.field]);
159
+ var _React$useMemo = React.useMemo(function () {
160
+ var itemField = item.field;
161
+ if (filterColumns === undefined || typeof filterColumns !== 'function') {
162
+ return {
163
+ filteredColumns: filterableColumns,
164
+ selectedField: itemField
165
+ };
166
+ }
167
+ var filteredFields = filterColumns({
168
+ field: item.field,
169
+ columns: filterableColumns,
170
+ currentFilters: (filterModel == null ? void 0 : filterModel.items) || []
171
+ });
172
+ return {
173
+ filteredColumns: filterableColumns.filter(function (column) {
174
+ var isFieldIncluded = filteredFields.includes(column.field);
175
+ if (column.field === item.field && !isFieldIncluded) {
176
+ itemField = undefined;
177
+ }
178
+ return isFieldIncluded;
179
+ }),
180
+ selectedField: itemField
181
+ };
182
+ }, [filterColumns, filterModel == null ? void 0 : filterModel.items, filterableColumns, item.field]),
183
+ filteredColumns = _React$useMemo.filteredColumns,
184
+ selectedField = _React$useMemo.selectedField;
171
185
  var sortedFilteredColumns = React.useMemo(function () {
172
186
  switch (columnsSort) {
173
187
  case 'asc':
@@ -206,11 +220,29 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
206
220
  }) || column.filterOperators[0];
207
221
 
208
222
  // Erase filter value if the input component or filtered column type is modified
209
- var eraseItemValue = !newOperator.InputComponent || newOperator.InputComponent !== (currentOperator == null ? void 0 : currentOperator.InputComponent) || column.type !== currentColumn.type;
223
+ var eraseFilterValue = !newOperator.InputComponent || newOperator.InputComponent !== (currentOperator == null ? void 0 : currentOperator.InputComponent) || column.type !== currentColumn.type;
224
+ var filterValue = eraseFilterValue ? undefined : item.value;
225
+
226
+ // Check filter value against the new valueOptions
227
+ if (column.type === 'singleSelect' && filterValue !== undefined) {
228
+ var colDef = column;
229
+ var valueOptions = getValueOptions(colDef);
230
+ if (Array.isArray(filterValue)) {
231
+ filterValue = filterValue.filter(function (val) {
232
+ return (
233
+ // Only keep values that are in the new value options
234
+ getValueFromValueOptions(val, valueOptions, colDef == null ? void 0 : colDef.getOptionValue) !== undefined
235
+ );
236
+ });
237
+ } else if (getValueFromValueOptions(item.value, valueOptions, colDef == null ? void 0 : colDef.getOptionValue) === undefined) {
238
+ // Reset the filter value if it is not in the new value options
239
+ filterValue = undefined;
240
+ }
241
+ }
210
242
  applyFilterChanges(_extends({}, item, {
211
243
  field: field,
212
244
  operator: newOperator.value,
213
- value: eraseItemValue ? undefined : item.value
245
+ value: filterValue
214
246
  }));
215
247
  }, [apiRef, applyFilterChanges, item, currentColumn, currentOperator]);
216
248
  var changeOperator = React.useCallback(function (event) {
@@ -290,7 +322,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
290
322
  inputProps: {
291
323
  'aria-label': apiRef.current.getLocaleText('filterPanelLogicOperator')
292
324
  },
293
- value: multiFilterOperator,
325
+ value: multiFilterOperator != null ? multiFilterOperator : '',
294
326
  onChange: changeLogicOperator,
295
327
  disabled: !!disableMultiFilterOperator || logicOperators.length === 1,
296
328
  native: isBaseSelectNative
@@ -317,7 +349,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
317
349
  labelId: columnSelectLabelId,
318
350
  id: columnSelectId,
319
351
  label: apiRef.current.getLocaleText('filterPanelColumns'),
320
- value: item.field || '',
352
+ value: selectedField != null ? selectedField : '',
321
353
  onChange: changeColumn,
322
354
  native: isBaseSelectNative
323
355
  }, (_rootProps$slotProps7 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps7.baseSelect, {
@@ -367,7 +399,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
367
399
  item: item,
368
400
  applyValue: applyFilterChanges,
369
401
  focusElementRef: valueRef
370
- }, currentOperator.InputComponentProps, InputComponentProps)) : null
402
+ }, currentOperator.InputComponentProps, InputComponentProps), item.field) : null
371
403
  }))]
372
404
  }));
373
405
  });
@@ -37,7 +37,7 @@ function GridFilterInputBoolean(props) {
37
37
  var labelId = useId();
38
38
  var selectId = useId();
39
39
  var baseSelectProps = ((_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseSelect) || {};
40
- var isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : true;
40
+ var isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : false;
41
41
  var baseSelectOptionProps = ((_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseSelectOption) || {};
42
42
  var onFilterChange = React.useCallback(function (event) {
43
43
  var value = event.target.value;
@@ -8,8 +8,25 @@ import { unstable_useId as useId } from '@mui/utils';
8
8
  import { useTimeout } from '../../../hooks/utils/useTimeout';
9
9
  import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
+ function convertFilterItemValueToInputValue(itemValue, inputType) {
12
+ if (itemValue == null) {
13
+ return '';
14
+ }
15
+ var dateCopy = new Date(itemValue);
16
+ // The date picker expects the date to be in the local timezone.
17
+ // But .toISOString() converts it to UTC with zero offset.
18
+ // So we need to subtract the timezone offset.
19
+ dateCopy.setMinutes(dateCopy.getMinutes() - dateCopy.getTimezoneOffset());
20
+ if (inputType === 'date') {
21
+ return dateCopy.toISOString().substring(0, 10);
22
+ }
23
+ if (inputType === 'datetime-local') {
24
+ return dateCopy.toISOString().substring(0, 19);
25
+ }
26
+ return dateCopy.toISOString().substring(0, 10);
27
+ }
11
28
  function GridFilterInputDate(props) {
12
- var _item$value, _rootProps$slotProps;
29
+ var _rootProps$slotProps;
13
30
  var item = props.item,
14
31
  applyValue = props.applyValue,
15
32
  type = props.type,
@@ -22,7 +39,9 @@ function GridFilterInputDate(props) {
22
39
  disabled = props.disabled,
23
40
  other = _objectWithoutProperties(props, _excluded);
24
41
  var filterTimeout = useTimeout();
25
- var _React$useState = React.useState((_item$value = item.value) != null ? _item$value : ''),
42
+ var _React$useState = React.useState(function () {
43
+ return convertFilterItemValueToInputValue(item.value, type);
44
+ }),
26
45
  _React$useState2 = _slicedToArray(_React$useState, 2),
27
46
  filterValueState = _React$useState2[0],
28
47
  setFilterValueState = _React$useState2[1];
@@ -33,21 +52,21 @@ function GridFilterInputDate(props) {
33
52
  var id = useId();
34
53
  var rootProps = useGridRootProps();
35
54
  var onFilterChange = React.useCallback(function (event) {
55
+ filterTimeout.clear();
36
56
  var value = event.target.value;
37
- setFilterValueState(String(value));
57
+ setFilterValueState(value);
38
58
  setIsApplying(true);
39
59
  filterTimeout.start(rootProps.filterDebounceMs, function () {
40
60
  applyValue(_extends({}, item, {
41
- value: value
61
+ value: new Date(value)
42
62
  }));
43
63
  setIsApplying(false);
44
64
  });
45
65
  }, [applyValue, item, rootProps.filterDebounceMs, filterTimeout]);
46
66
  React.useEffect(function () {
47
- var _item$value2;
48
- var itemValue = (_item$value2 = item.value) != null ? _item$value2 : '';
49
- setFilterValueState(String(itemValue));
50
- }, [item.value]);
67
+ var value = convertFilterItemValueToInputValue(item.value, type);
68
+ setFilterValueState(value);
69
+ }, [item.value, type]);
51
70
  return /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
52
71
  fullWidth: true,
53
72
  id: id,
@@ -1,11 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "color", "error", "helperText", "size", "variant", "getOptionLabel", "getOptionValue"];
3
+ var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "color", "error", "helperText", "size", "variant"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
7
7
  import { unstable_useId as useId } from '@mui/utils';
8
- import { isSingleSelectColDef } from './filterPanelUtils';
8
+ import { getValueOptions, isSingleSelectColDef } from './filterPanelUtils';
9
9
  import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  var filter = createFilterOptions();
@@ -22,8 +22,6 @@ function GridFilterInputMultipleSingleSelect(props) {
22
22
  size = props.size,
23
23
  _props$variant = props.variant,
24
24
  variant = _props$variant === void 0 ? 'standard' : _props$variant,
25
- getOptionLabelProp = props.getOptionLabel,
26
- getOptionValueProp = props.getOptionValue,
27
25
  other = _objectWithoutProperties(props, _excluded);
28
26
  var TextFieldProps = {
29
27
  color: color,
@@ -41,26 +39,14 @@ function GridFilterInputMultipleSingleSelect(props) {
41
39
  resolvedColumn = column;
42
40
  }
43
41
  }
44
- var getOptionValue = getOptionValueProp || ((_resolvedColumn = resolvedColumn) == null ? void 0 : _resolvedColumn.getOptionValue);
45
- var getOptionLabel = getOptionLabelProp || ((_resolvedColumn2 = resolvedColumn) == null ? void 0 : _resolvedColumn2.getOptionLabel);
42
+ var getOptionValue = (_resolvedColumn = resolvedColumn) == null ? void 0 : _resolvedColumn.getOptionValue;
43
+ var getOptionLabel = (_resolvedColumn2 = resolvedColumn) == null ? void 0 : _resolvedColumn2.getOptionLabel;
46
44
  var isOptionEqualToValue = React.useCallback(function (option, value) {
47
45
  return getOptionValue(option) === getOptionValue(value);
48
46
  }, [getOptionValue]);
49
47
  var resolvedValueOptions = React.useMemo(function () {
50
- var _resolvedColumn3;
51
- if (!((_resolvedColumn3 = resolvedColumn) != null && _resolvedColumn3.valueOptions)) {
52
- return [];
53
- }
54
- if (typeof resolvedColumn.valueOptions === 'function') {
55
- return resolvedColumn.valueOptions({
56
- field: resolvedColumn.field
57
- });
58
- }
59
- return resolvedColumn.valueOptions;
48
+ return getValueOptions(resolvedColumn) || [];
60
49
  }, [resolvedColumn]);
61
- var resolvedFormattedValueOptions = React.useMemo(function () {
62
- return resolvedValueOptions == null ? void 0 : resolvedValueOptions.map(getOptionValue);
63
- }, [resolvedValueOptions, getOptionValue]);
64
50
 
65
51
  // The value is computed from the item.value and used directly
66
52
  // If it was done by a useEffect/useState, the Autocomplete could receive incoherent value and options
@@ -68,29 +54,8 @@ function GridFilterInputMultipleSingleSelect(props) {
68
54
  if (!Array.isArray(item.value)) {
69
55
  return [];
70
56
  }
71
- if (resolvedValueOptions !== undefined) {
72
- var itemValueIndexes = item.value.map(function (element) {
73
- // Gets the index matching between values and valueOptions
74
- return resolvedFormattedValueOptions == null ? void 0 : resolvedFormattedValueOptions.findIndex(function (formattedOption) {
75
- return formattedOption === element;
76
- });
77
- });
78
- return itemValueIndexes.filter(function (index) {
79
- return index >= 0;
80
- }).map(function (index) {
81
- return resolvedValueOptions[index];
82
- });
83
- }
84
57
  return item.value;
85
- }, [item.value, resolvedValueOptions, resolvedFormattedValueOptions]);
86
- React.useEffect(function () {
87
- if (!Array.isArray(item.value) || filteredValues.length !== item.value.length) {
88
- // Updates the state if the filter value has been cleaned by the component
89
- applyValue(_extends({}, item, {
90
- value: filteredValues.map(getOptionValue)
91
- }));
92
- }
93
- }, [item, filteredValues, applyValue, getOptionValue]);
58
+ }, [item.value]);
94
59
  var handleChange = React.useCallback(function (event, value) {
95
60
  applyValue(_extends({}, item, {
96
61
  value: value.map(getOptionValue)
@@ -140,18 +105,6 @@ process.env.NODE_ENV !== "production" ? GridFilterInputMultipleSingleSelect.prop
140
105
  }).isRequired,
141
106
  applyValue: PropTypes.func.isRequired,
142
107
  focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
143
- /**
144
- * Used to determine the label displayed for a given value option.
145
- * @param {ValueOptions} value The current value option.
146
- * @returns {string} The text to be displayed.
147
- */
148
- getOptionLabel: PropTypes.func,
149
- /**
150
- * Used to determine the value used for a value option.
151
- * @param {ValueOptions} value The current value option.
152
- * @returns {string} The value to be used.
153
- */
154
- getOptionValue: PropTypes.func,
155
108
  item: PropTypes.shape({
156
109
  field: PropTypes.string.isRequired,
157
110
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -1,33 +1,31 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
3
  import _extends from "@babel/runtime/helpers/esm/extends";
5
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
6
- var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "getOptionLabel", "getOptionValue", "placeholder", "tabIndex", "label", "isFilterActive", "clearButton", "InputLabelProps"];
5
+ var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "placeholder", "tabIndex", "label", "isFilterActive", "clearButton", "InputLabelProps"];
7
6
  import * as React from 'react';
8
7
  import PropTypes from 'prop-types';
9
8
  import { unstable_useId as useId } from '@mui/utils';
10
9
  import { styled } from '@mui/material/styles';
11
10
  import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
12
- import { getValueFromValueOptions, isSingleSelectColDef } from './filterPanelUtils';
11
+ import { getValueFromValueOptions, getValueOptions, isSingleSelectColDef } from './filterPanelUtils';
13
12
  import { createElement as _createElement } from "react";
14
13
  import { jsx as _jsx } from "react/jsx-runtime";
15
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
15
  var renderSingleSelectOptions = function renderSingleSelectOptions(_ref) {
17
- var _ref$column = _ref.column,
18
- valueOptions = _ref$column.valueOptions,
19
- field = _ref$column.field,
16
+ var column = _ref.column,
20
17
  OptionComponent = _ref.OptionComponent,
21
18
  getOptionLabel = _ref.getOptionLabel,
22
19
  getOptionValue = _ref.getOptionValue,
23
20
  isSelectNative = _ref.isSelectNative,
24
21
  baseSelectOptionProps = _ref.baseSelectOptionProps;
25
- var iterableColumnValues = typeof valueOptions === 'function' ? [''].concat(_toConsumableArray(valueOptions({
26
- field: field
27
- }))) : [''].concat(_toConsumableArray(valueOptions || []));
22
+ var iterableColumnValues = [''].concat(_toConsumableArray(getValueOptions(column) || []));
28
23
  return iterableColumnValues.map(function (option) {
29
24
  var value = getOptionValue(option);
30
25
  var label = getOptionLabel(option);
26
+ if (label === '') {
27
+ label = ' '; // To force the height of the empty option
28
+ }
31
29
  return /*#__PURE__*/_createElement(OptionComponent, _extends({}, baseSelectOptionProps, {
32
30
  native: isSelectNative,
33
31
  key: value,
@@ -49,8 +47,6 @@ function GridFilterInputSingleSelect(props) {
49
47
  type = props.type,
50
48
  apiRef = props.apiRef,
51
49
  focusElementRef = props.focusElementRef,
52
- getOptionLabelProp = props.getOptionLabel,
53
- getOptionValueProp = props.getOptionValue,
54
50
  placeholder = props.placeholder,
55
51
  tabIndex = props.tabIndex,
56
52
  labelProp = props.label,
@@ -58,14 +54,11 @@ function GridFilterInputSingleSelect(props) {
58
54
  clearButton = props.clearButton,
59
55
  InputLabelProps = props.InputLabelProps,
60
56
  others = _objectWithoutProperties(props, _excluded);
61
- var _React$useState = React.useState((_item$value = item.value) != null ? _item$value : ''),
62
- _React$useState2 = _slicedToArray(_React$useState, 2),
63
- filterValueState = _React$useState2[0],
64
- setFilterValueState = _React$useState2[1];
57
+ var filterValue = (_item$value = item.value) != null ? _item$value : '';
65
58
  var id = useId();
66
59
  var labelId = useId();
67
60
  var rootProps = useGridRootProps();
68
- var isSelectNative = (_rootProps$slotProps$ = (_rootProps$slotProps = rootProps.slotProps) == null || (_rootProps$slotProps = _rootProps$slotProps.baseSelect) == null ? void 0 : _rootProps$slotProps.native) != null ? _rootProps$slotProps$ : true;
61
+ var isSelectNative = (_rootProps$slotProps$ = (_rootProps$slotProps = rootProps.slotProps) == null || (_rootProps$slotProps = _rootProps$slotProps.baseSelect) == null ? void 0 : _rootProps$slotProps.native) != null ? _rootProps$slotProps$ : false;
69
62
  var resolvedColumn = null;
70
63
  if (item.field) {
71
64
  var column = apiRef.current.getColumn(item.field);
@@ -73,53 +66,27 @@ function GridFilterInputSingleSelect(props) {
73
66
  resolvedColumn = column;
74
67
  }
75
68
  }
76
- var getOptionValue = getOptionValueProp || ((_resolvedColumn = resolvedColumn) == null ? void 0 : _resolvedColumn.getOptionValue);
77
- var getOptionLabel = getOptionLabelProp || ((_resolvedColumn2 = resolvedColumn) == null ? void 0 : _resolvedColumn2.getOptionLabel);
69
+ var getOptionValue = (_resolvedColumn = resolvedColumn) == null ? void 0 : _resolvedColumn.getOptionValue;
70
+ var getOptionLabel = (_resolvedColumn2 = resolvedColumn) == null ? void 0 : _resolvedColumn2.getOptionLabel;
78
71
  var currentValueOptions = React.useMemo(function () {
79
- if (!resolvedColumn) {
80
- return undefined;
81
- }
82
- return typeof resolvedColumn.valueOptions === 'function' ? resolvedColumn.valueOptions({
83
- field: resolvedColumn.field
84
- }) : resolvedColumn.valueOptions;
72
+ return getValueOptions(resolvedColumn);
85
73
  }, [resolvedColumn]);
86
74
  var onFilterChange = React.useCallback(function (event) {
87
75
  var value = event.target.value;
88
76
 
89
77
  // NativeSelect casts the value to a string.
90
78
  value = getValueFromValueOptions(value, currentValueOptions, getOptionValue);
91
- setFilterValueState(String(value));
92
79
  applyValue(_extends({}, item, {
93
80
  value: value
94
81
  }));
95
82
  }, [currentValueOptions, getOptionValue, applyValue, item]);
96
- React.useEffect(function () {
97
- var _itemValue;
98
- var itemValue;
99
- if (currentValueOptions !== undefined) {
100
- // sanitize if valueOptions are provided
101
- itemValue = getValueFromValueOptions(item.value, currentValueOptions, getOptionValue);
102
- if (itemValue !== item.value) {
103
- applyValue(_extends({}, item, {
104
- value: itemValue
105
- }));
106
- return;
107
- }
108
- } else {
109
- itemValue = item.value;
110
- }
111
- itemValue = (_itemValue = itemValue) != null ? _itemValue : '';
112
- setFilterValueState(String(itemValue));
113
- }, [item, currentValueOptions, applyValue, getOptionValue]);
114
- if (!isSingleSelectColDef(resolvedColumn)) {
115
- return null;
116
- }
117
83
  if (!isSingleSelectColDef(resolvedColumn)) {
118
84
  return null;
119
85
  }
120
86
  var label = labelProp != null ? labelProp : apiRef.current.getLocaleText('filterPanelInputLabel');
121
87
  return /*#__PURE__*/_jsxs(SingleSelectOperatorContainer, {
122
88
  children: [/*#__PURE__*/_jsxs(rootProps.slots.baseFormControl, {
89
+ fullWidth: true,
123
90
  children: [/*#__PURE__*/_jsx(rootProps.slots.baseInputLabel, _extends({}, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseInputLabel, {
124
91
  id: labelId,
125
92
  htmlFor: id,
@@ -130,7 +97,7 @@ function GridFilterInputSingleSelect(props) {
130
97
  id: id,
131
98
  label: label,
132
99
  labelId: labelId,
133
- value: filterValueState,
100
+ value: filterValue,
134
101
  onChange: onFilterChange,
135
102
  variant: "standard",
136
103
  type: type || 'text',
@@ -164,18 +131,6 @@ process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes =
164
131
  applyValue: PropTypes.func.isRequired,
165
132
  clearButton: PropTypes.node,
166
133
  focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
167
- /**
168
- * Used to determine the label displayed for a given value option.
169
- * @param {ValueOptions} value The current value option.
170
- * @returns {string} The text to be displayed.
171
- */
172
- getOptionLabel: PropTypes.func,
173
- /**
174
- * Used to determine the value used for a value option.
175
- * @param {ValueOptions} value The current value option.
176
- * @returns {string} The value to be used.
177
- */
178
- getOptionValue: PropTypes.func,
179
134
  /**
180
135
  * It is `true` if the filter either has a value or an operator with no value
181
136
  * required is selected (e.g. `isEmpty`)
@@ -1,7 +1,15 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  export function isSingleSelectColDef(colDef) {
3
3
  return (colDef == null ? void 0 : colDef.type) === 'singleSelect';
4
4
  }
5
+ export function getValueOptions(column, additionalParams) {
6
+ if (!column) {
7
+ return undefined;
8
+ }
9
+ return typeof column.valueOptions === 'function' ? column.valueOptions(_extends({
10
+ field: column.field
11
+ }, additionalParams)) : column.valueOptions;
12
+ }
5
13
  export function getValueFromValueOptions(value, valueOptions, getOptionValue) {
6
14
  if (valueOptions === undefined) {
7
15
  return undefined;
@@ -11,8 +19,4 @@ export function getValueFromValueOptions(value, valueOptions, getOptionValue) {
11
19
  return String(optionValue) === String(value);
12
20
  });
13
21
  return getOptionValue(result);
14
- }
15
- export var getLabelFromValueOption = function getLabelFromValueOption(valueOption) {
16
- var label = _typeof(valueOption) === 'object' ? valueOption.label : valueOption;
17
- return label != null ? String(label) : '';
18
- };
22
+ }
@@ -4,15 +4,17 @@ import { getDefaultGridFilterModel } from './gridFilterState';
4
4
  import { buildWarning } from '../../../utils/warning';
5
5
  import { getPublicApiRef } from '../../../utils/getPublicApiRef';
6
6
  import { gridColumnFieldsSelector, gridColumnLookupSelector, gridVisibleColumnFieldsSelector } from '../columns';
7
-
8
- // Fixes https://github.com/mui/mui-x/issues/10056
9
- var globalScope = typeof window === 'undefined' ? globalThis : window;
10
- var evalCode = globalScope[atob('ZXZhbA==')];
11
7
  var hasEval;
12
- try {
13
- hasEval = evalCode('true');
14
- } catch (_) {
15
- hasEval = false;
8
+ function getHasEval() {
9
+ if (hasEval !== undefined) {
10
+ return hasEval;
11
+ }
12
+ try {
13
+ hasEval = new Function('return true')();
14
+ } catch (_) {
15
+ hasEval = false;
16
+ }
17
+ return hasEval;
16
18
  }
17
19
  /**
18
20
  * Adds default values to the optional fields of a filter items.
@@ -154,7 +156,7 @@ var buildAggregatedFilterItemsApplier = function buildAggregatedFilterItemsAppli
154
156
  if (appliers.length === 0) {
155
157
  return null;
156
158
  }
157
- if (!hasEval || disableEval) {
159
+ if (disableEval || !getHasEval()) {
158
160
  // This is the original logic, which is used if `eval()` is not supported (aka prevented by CSP).
159
161
  return function (row, shouldApplyFilter) {
160
162
  var resultPerItemId = {};
@@ -168,18 +170,19 @@ var buildAggregatedFilterItemsApplier = function buildAggregatedFilterItemsAppli
168
170
  };
169
171
  }
170
172
 
171
- // We generate a new function with `eval()` to avoid expensive patterns for JS engines
173
+ // We generate a new function with `new Function()` to avoid expensive patterns for JS engines
172
174
  // such as a dynamic object assignment, e.g. `{ [dynamicKey]: value }`.
173
- var filterItemTemplate = "(function filterItem$$(getRowId, appliers, row, shouldApplyFilter) {\n ".concat(appliers.map(function (applier, i) {
175
+ var filterItemCore = new Function('appliers', 'row', 'shouldApplyFilter', "\"use strict\";\n".concat(appliers.map(function (applier, i) {
174
176
  return "const shouldApply".concat(i, " = !shouldApplyFilter || shouldApplyFilter(").concat(JSON.stringify(applier.item.field), ");");
175
- }).join('\n'), "\n\n const result$$ = {\n ").concat(appliers.map(function (applier, i) {
176
- return "".concat(JSON.stringify(String(applier.item.id)), ":\n !shouldApply").concat(i, " ?\n false :\n appliers[").concat(i, "].fn(row),\n ");
177
- }).join('\n'), "};\n\n return result$$;\n })");
178
- var filterItemCore = evalCode(filterItemTemplate.replaceAll('$$', String(filterItemsApplierId)));
177
+ }).join('\n'), "\n\nconst result$$ = {\n").concat(appliers.map(function (applier, i) {
178
+ return " ".concat(JSON.stringify(String(applier.item.id)), ": !shouldApply").concat(i, " ? false : appliers[").concat(i, "].fn(row),");
179
+ }).join('\n'), "\n};\n\nreturn result$$;").replaceAll('$$', String(filterItemsApplierId)));
180
+ filterItemsApplierId += 1;
181
+
182
+ // Assign to the arrow function a name to help debugging
179
183
  var filterItem = function filterItem(row, shouldApplyItem) {
180
- return filterItemCore(apiRef.current.getRowId, appliers, row, shouldApplyItem);
184
+ return filterItemCore(appliers, row, shouldApplyItem);
181
185
  };
182
- filterItemsApplierId += 1;
183
186
  return filterItem;
184
187
  };
185
188
  export var shouldQuickFilterExcludeHiddenColumns = function shouldQuickFilterExcludeHiddenColumns(filterModel) {
@@ -16,6 +16,7 @@ import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
16
16
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from '../../../constants/gridDetailPanelToggleField';
17
17
  import { gridClasses } from '../../../constants/gridClasses';
18
18
  import { isEventTargetInPortal } from '../../../utils/domUtils';
19
+ import { isMultipleRowSelectionEnabled } from './utils';
19
20
  var getSelectionModelPropValue = function getSelectionModelPropValue(selectionModelProp, prevSelectionModel) {
20
21
  if (selectionModelProp == null) {
21
22
  return selectionModelProp;
@@ -62,10 +63,9 @@ export var useGridRowSelection = function useGridRowSelection(apiRef, props) {
62
63
  changeEvent: 'rowSelectionChange'
63
64
  });
64
65
  var checkboxSelection = props.checkboxSelection,
65
- disableMultipleRowSelection = props.disableMultipleRowSelection,
66
66
  disableRowSelectionOnClick = props.disableRowSelectionOnClick,
67
67
  propIsRowSelectable = props.isRowSelectable;
68
- var canHaveMultipleSelection = !disableMultipleRowSelection || checkboxSelection;
68
+ var canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
69
69
  var visibleRows = useGridVisibleRows(apiRef, props);
70
70
  var expandMouseRowRangeSelection = React.useCallback(function (id) {
71
71
  var _lastRowToggled$curre;
@@ -100,7 +100,7 @@ export var useGridRowSelection = function useGridRowSelection(apiRef, props) {
100
100
  * API METHODS
101
101
  */
102
102
  var setRowSelectionModel = React.useCallback(function (model) {
103
- if (props.signature === GridSignature.DataGrid && !props.checkboxSelection && Array.isArray(model) && model.length > 1) {
103
+ if (props.signature === GridSignature.DataGrid && !canHaveMultipleSelection && Array.isArray(model) && model.length > 1) {
104
104
  throw new Error(['MUI: `rowSelectionModel` can only contain 1 item in DataGrid.', 'You need to upgrade to DataGridPro or DataGridPremium component to unlock multiple selection.'].join('\n'));
105
105
  }
106
106
  var currentModel = gridRowSelectionStateSelector(apiRef.current.state);
@@ -113,7 +113,7 @@ export var useGridRowSelection = function useGridRowSelection(apiRef, props) {
113
113
  });
114
114
  apiRef.current.forceUpdate();
115
115
  }
116
- }, [apiRef, logger, props.rowSelection, props.signature, props.checkboxSelection]);
116
+ }, [apiRef, logger, props.rowSelection, props.signature, canHaveMultipleSelection]);
117
117
  var isRowSelected = React.useCallback(function (id) {
118
118
  return gridRowSelectionStateSelector(apiRef.current.state).includes(id);
119
119
  }, [apiRef]);
@@ -281,12 +281,12 @@ export var useGridRowSelection = function useGridRowSelection(apiRef, props) {
281
281
  if (rowNode.type === 'pinnedRow') {
282
282
  return;
283
283
  }
284
- if (event.shiftKey && (canHaveMultipleSelection || checkboxSelection)) {
284
+ if (event.shiftKey && canHaveMultipleSelection) {
285
285
  expandMouseRowRangeSelection(params.id);
286
286
  } else {
287
287
  handleSingleRowSelection(params.id, event);
288
288
  }
289
- }, [disableRowSelectionOnClick, canHaveMultipleSelection, checkboxSelection, apiRef, expandMouseRowRangeSelection, handleSingleRowSelection]);
289
+ }, [disableRowSelectionOnClick, canHaveMultipleSelection, apiRef, expandMouseRowRangeSelection, handleSingleRowSelection]);
290
290
  var preventSelectionOnShift = React.useCallback(function (params, event) {
291
291
  if (canHaveMultipleSelection && event.shiftKey) {
292
292
  var _window$getSelection;
@@ -294,12 +294,12 @@ export var useGridRowSelection = function useGridRowSelection(apiRef, props) {
294
294
  }
295
295
  }, [canHaveMultipleSelection]);
296
296
  var handleRowSelectionCheckboxChange = React.useCallback(function (params, event) {
297
- if (event.nativeEvent.shiftKey) {
297
+ if (canHaveMultipleSelection && event.nativeEvent.shiftKey) {
298
298
  expandMouseRowRangeSelection(params.id);
299
299
  } else {
300
- apiRef.current.selectRow(params.id, params.value);
300
+ apiRef.current.selectRow(params.id, params.value, !canHaveMultipleSelection);
301
301
  }
302
- }, [apiRef, expandMouseRowRangeSelection]);
302
+ }, [apiRef, expandMouseRowRangeSelection, canHaveMultipleSelection]);
303
303
  var handleHeaderSelectionCheckboxChange = React.useCallback(function (params) {
304
304
  var shouldLimitSelectionToCurrentPage = props.checkboxSelectionVisibleOnly && props.pagination;
305
305
  var rowsToBeSelected = shouldLimitSelectionToCurrentPage ? gridPaginatedVisibleSortedGridRowIdsSelector(apiRef) : gridExpandedSortedRowIdsSelector(apiRef);
@@ -0,0 +1,8 @@
1
+ import { GridSignature } from '../../utils/useGridApiEventHandler';
2
+ export function isMultipleRowSelectionEnabled(props) {
3
+ if (props.signature === GridSignature.DataGrid) {
4
+ // DataGrid Community has multiple row selection enabled only if checkbox selection is enabled.
5
+ return props.checkboxSelection && props.disableMultipleRowSelection !== true;
6
+ }
7
+ return !props.disableMultipleRowSelection;
8
+ }
@@ -4,6 +4,7 @@ import { useGridRootProps } from './useGridRootProps';
4
4
  import { gridColumnGroupsHeaderMaxDepthSelector } from '../features/columnGrouping/gridColumnGroupsSelector';
5
5
  import { gridPinnedRowsCountSelector, gridRowCountSelector } from '../features/rows/gridRowsSelector';
6
6
  import { useGridPrivateApiContext } from './useGridPrivateApiContext';
7
+ import { isMultipleRowSelectionEnabled } from '../features/rowSelection/utils';
7
8
  export var useGridAriaAttributes = function useGridAriaAttributes() {
8
9
  var _rootProps$experiment;
9
10
  var apiRef = useGridPrivateApiContext();
@@ -20,6 +21,6 @@ export var useGridAriaAttributes = function useGridAriaAttributes() {
20
21
  role: role,
21
22
  'aria-colcount': visibleColumns.length,
22
23
  'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + totalRowCount,
23
- 'aria-multiselectable': !rootProps.disableMultipleRowSelection
24
+ 'aria-multiselectable': isMultipleRowSelectionEnabled(rootProps)
24
25
  };
25
26
  };
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.0.0-alpha.5
2
+ * @mui/x-data-grid v7.0.0-alpha.7
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the