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

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 (72) hide show
  1. package/CHANGELOG.md +226 -6
  2. package/DataGrid/DataGrid.js +25 -19
  3. package/DataGrid/useDataGridProps.js +0 -1
  4. package/colDef/gridDateOperators.js +13 -6
  5. package/colDef/gridSingleSelectColDef.js +6 -15
  6. package/components/cell/GridEditSingleSelectCell.d.ts +1 -2
  7. package/components/cell/GridEditSingleSelectCell.js +9 -29
  8. package/components/columnSelection/GridHeaderCheckbox.js +3 -1
  9. package/components/panel/filterPanel/GridFilterForm.js +44 -9
  10. package/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  11. package/components/panel/filterPanel/GridFilterInputDate.js +25 -8
  12. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -2
  13. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -48
  14. package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -2
  15. package/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -57
  16. package/components/panel/filterPanel/filterPanelUtils.d.ts +3 -2
  17. package/components/panel/filterPanel/filterPanelUtils.js +10 -5
  18. package/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  19. package/hooks/features/rowSelection/utils.d.ts +2 -0
  20. package/hooks/features/rowSelection/utils.js +8 -0
  21. package/hooks/utils/useGridAriaAttributes.js +2 -1
  22. package/index.js +1 -1
  23. package/legacy/DataGrid/DataGrid.js +25 -19
  24. package/legacy/DataGrid/useDataGridProps.js +0 -1
  25. package/legacy/colDef/gridDateOperators.js +13 -13
  26. package/legacy/colDef/gridSingleSelectColDef.js +6 -15
  27. package/legacy/components/cell/GridEditSingleSelectCell.js +8 -28
  28. package/legacy/components/columnSelection/GridHeaderCheckbox.js +3 -1
  29. package/legacy/components/panel/filterPanel/GridFilterForm.js +51 -19
  30. package/legacy/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  31. package/legacy/components/panel/filterPanel/GridFilterInputDate.js +27 -8
  32. package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -53
  33. package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -59
  34. package/legacy/components/panel/filterPanel/filterPanelUtils.js +10 -6
  35. package/legacy/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  36. package/legacy/hooks/features/rowSelection/utils.js +8 -0
  37. package/legacy/hooks/utils/useGridAriaAttributes.js +2 -1
  38. package/legacy/index.js +1 -1
  39. package/models/props/DataGridProps.d.ts +26 -25
  40. package/modern/DataGrid/DataGrid.js +25 -19
  41. package/modern/DataGrid/useDataGridProps.js +0 -1
  42. package/modern/colDef/gridDateOperators.js +13 -6
  43. package/modern/colDef/gridSingleSelectColDef.js +6 -15
  44. package/modern/components/cell/GridEditSingleSelectCell.js +9 -29
  45. package/modern/components/columnSelection/GridHeaderCheckbox.js +3 -1
  46. package/modern/components/panel/filterPanel/GridFilterForm.js +44 -9
  47. package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  48. package/modern/components/panel/filterPanel/GridFilterInputDate.js +24 -6
  49. package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -47
  50. package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -56
  51. package/modern/components/panel/filterPanel/filterPanelUtils.js +10 -5
  52. package/modern/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  53. package/modern/hooks/features/rowSelection/utils.js +8 -0
  54. package/modern/hooks/utils/useGridAriaAttributes.js +2 -1
  55. package/modern/index.js +1 -1
  56. package/node/DataGrid/DataGrid.js +25 -19
  57. package/node/DataGrid/useDataGridProps.js +0 -1
  58. package/node/colDef/gridDateOperators.js +13 -6
  59. package/node/colDef/gridSingleSelectColDef.js +5 -14
  60. package/node/components/cell/GridEditSingleSelectCell.js +8 -28
  61. package/node/components/columnSelection/GridHeaderCheckbox.js +3 -1
  62. package/node/components/panel/filterPanel/GridFilterForm.js +44 -9
  63. package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  64. package/node/components/panel/filterPanel/GridFilterInputDate.js +24 -6
  65. package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -46
  66. package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -55
  67. package/node/components/panel/filterPanel/filterPanelUtils.js +12 -7
  68. package/node/hooks/features/rowSelection/useGridRowSelection.js +9 -9
  69. package/node/hooks/features/rowSelection/utils.js +14 -0
  70. package/node/hooks/utils/useGridAriaAttributes.js +2 -1
  71. package/node/index.js +1 -1
  72. package/package.json +3 -3
@@ -41,21 +41,21 @@ DataGridRaw.propTypes = {
41
41
  // | To update them edit the TypeScript types and run "yarn proptypes" |
42
42
  // ----------------------------------------------------------------------
43
43
  /**
44
- * The ref object that allows grid manipulation. Can be instantiated with `useGridApiRef()`.
44
+ * The ref object that allows Data Grid manipulation. Can be instantiated with `useGridApiRef()`.
45
45
  */
46
46
  apiRef: PropTypes.shape({
47
47
  current: PropTypes.object.isRequired
48
48
  }),
49
49
  /**
50
- * The label of the grid.
50
+ * The label of the Data Grid.
51
51
  */
52
52
  'aria-label': PropTypes.string,
53
53
  /**
54
- * The id of the element containing a label for the grid.
54
+ * The id of the element containing a label for the Data Grid.
55
55
  */
56
56
  'aria-labelledby': PropTypes.string,
57
57
  /**
58
- * If `true`, the grid height is dynamic and follow the number of rows in the grid.
58
+ * If `true`, the Data Grid height is dynamic and follow the number of rows in the Data Grid.
59
59
  * @default false
60
60
  */
61
61
  autoHeight: PropTypes.bool,
@@ -69,7 +69,7 @@ DataGridRaw.propTypes = {
69
69
  */
70
70
  cellModesModel: PropTypes.object,
71
71
  /**
72
- * If `true`, the grid get a first column with a checkbox that allows to select rows.
72
+ * If `true`, the Data Grid will display an extra column with checkboxes for selecting rows.
73
73
  * @default false
74
74
  */
75
75
  checkboxSelection: PropTypes.bool,
@@ -89,7 +89,7 @@ DataGridRaw.propTypes = {
89
89
  columnBuffer: PropTypes.number,
90
90
  columnGroupingModel: PropTypes.arrayOf(PropTypes.object),
91
91
  /**
92
- * Sets the height in pixel of the column headers in the grid.
92
+ * Sets the height in pixel of the column headers in the Data Grid.
93
93
  * @default 56
94
94
  */
95
95
  columnHeaderHeight: PropTypes.number,
@@ -111,12 +111,12 @@ DataGridRaw.propTypes = {
111
111
  */
112
112
  columnThreshold: PropTypes.number,
113
113
  /**
114
- * Set the column visibility model of the grid.
115
- * If defined, the grid will ignore the `hide` property in [[GridColDef]].
114
+ * Set the column visibility model of the Data Grid.
115
+ * If defined, the Data Grid will ignore the `hide` property in [[GridColDef]].
116
116
  */
117
117
  columnVisibilityModel: PropTypes.object,
118
118
  /**
119
- * Set the density of the grid.
119
+ * Set the density of the Data Grid.
120
120
  * @default "standard"
121
121
  */
122
122
  density: PropTypes.oneOf(['comfortable', 'compact', 'standard']),
@@ -146,6 +146,12 @@ DataGridRaw.propTypes = {
146
146
  * @ignore - do not document
147
147
  */
148
148
  disableEval: PropTypes.bool,
149
+ /**
150
+ * If `true`, multiple selection using the Ctrl/CMD or Shift key is disabled.
151
+ * The MIT DataGrid will ignore this prop, unless `checkboxSelection` is enabled.
152
+ * @default false (`!props.checkboxSelection` for MIT Data Grid)
153
+ */
154
+ disableMultipleRowSelection: PropTypes.bool,
149
155
  /**
150
156
  * If `true`, the selection on click on a row or cell is disabled.
151
157
  * @default false
@@ -182,7 +188,7 @@ DataGridRaw.propTypes = {
182
188
  */
183
189
  filterMode: PropTypes.oneOf(['client', 'server']),
184
190
  /**
185
- * Set the filter model of the grid.
191
+ * Set the filter model of the Data Grid.
186
192
  */
187
193
  filterModel: PropTypes.shape({
188
194
  items: PropTypes.arrayOf(PropTypes.shape({
@@ -197,7 +203,7 @@ DataGridRaw.propTypes = {
197
203
  quickFilterValues: PropTypes.array
198
204
  }),
199
205
  /**
200
- * Forwarded props for the grid root element.
206
+ * Forwarded props for the Data Grid root element.
201
207
  * @ignore - do not document.
202
208
  */
203
209
  forwardedProps: PropTypes.object,
@@ -265,7 +271,7 @@ DataGridRaw.propTypes = {
265
271
  */
266
272
  ignoreDiacritics: PropTypes.bool,
267
273
  /**
268
- * If `true`, the grid will not use `valueFormatter` when exporting to CSV or copying to clipboard.
274
+ * If `true`, the Data Grid will not use `valueFormatter` when exporting to CSV or copying to clipboard.
269
275
  * If an object is provided, you can choose to ignore the `valueFormatter` for CSV export or clipboard export.
270
276
  * @default false
271
277
  */
@@ -303,7 +309,7 @@ DataGridRaw.propTypes = {
303
309
  */
304
310
  loading: PropTypes.bool,
305
311
  /**
306
- * Set the locale text of the grid.
312
+ * Set the locale text of the Data Grid.
307
313
  * You can find all the translation keys supported in [the source](https://github.com/mui/mui-x/blob/HEAD/packages/grid/x-data-grid/src/constants/localeTextConstants.ts) in the GitHub repository.
308
314
  */
309
315
  localeText: PropTypes.object,
@@ -471,7 +477,7 @@ DataGridRaw.propTypes = {
471
477
  */
472
478
  onProcessRowUpdateError: PropTypes.func,
473
479
  /**
474
- * Callback fired when the grid is resized.
480
+ * Callback fired when the Data Grid is resized.
475
481
  * @param {ElementSize} containerSize With all properties from [[ElementSize]].
476
482
  * @param {MuiEvent<{}>} event The event object.
477
483
  * @param {GridCallbackDetails} details Additional details for this callback.
@@ -529,7 +535,7 @@ DataGridRaw.propTypes = {
529
535
  */
530
536
  onSortModelChange: PropTypes.func,
531
537
  /**
532
- * Callback fired when the state of the grid is updated.
538
+ * Callback fired when the state of the Data Grid is updated.
533
539
  * @param {GridState} state The new state.
534
540
  * @param {MuiEvent<{}>} event The event object.
535
541
  * @param {GridCallbackDetails} details Additional details for this callback.
@@ -583,7 +589,7 @@ DataGridRaw.propTypes = {
583
589
  */
584
590
  rowCount: PropTypes.number,
585
591
  /**
586
- * Sets the height in pixel of a row in the grid.
592
+ * Sets the height in pixel of a row in the Data Grid.
587
593
  * @default 52
588
594
  */
589
595
  rowHeight: PropTypes.number,
@@ -608,7 +614,7 @@ DataGridRaw.propTypes = {
608
614
  */
609
615
  rowSelection: PropTypes.bool,
610
616
  /**
611
- * Sets the row selection model of the grid.
617
+ * Sets the row selection model of the Data Grid.
612
618
  */
613
619
  rowSelectionModel: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired), PropTypes.number, PropTypes.string]),
614
620
  /**
@@ -622,7 +628,7 @@ DataGridRaw.propTypes = {
622
628
  */
623
629
  rowThreshold: PropTypes.number,
624
630
  /**
625
- * Override the height/width of the grid inner scrollbar.
631
+ * Override the height/width of the Data Grid inner scrollbar.
626
632
  */
627
633
  scrollbarSize: PropTypes.number,
628
634
  /**
@@ -656,7 +662,7 @@ DataGridRaw.propTypes = {
656
662
  */
657
663
  sortingOrder: PropTypes.arrayOf(PropTypes.oneOf(['asc', 'desc'])),
658
664
  /**
659
- * Set the sort model of the grid.
665
+ * Set the sort model of the Data Grid.
660
666
  */
661
667
  sortModel: PropTypes.arrayOf(PropTypes.shape({
662
668
  field: PropTypes.string.isRequired,
@@ -8,7 +8,6 @@ import { computeSlots, useProps } from '../internals/utils';
8
8
  var DATA_GRID_FORCED_PROPS = {
9
9
  disableMultipleColumnsFiltering: true,
10
10
  disableMultipleColumnsSorting: true,
11
- disableMultipleRowSelection: true,
12
11
  throttleRowsMs: undefined,
13
12
  hideFooterRowCount: false,
14
13
  pagination: true,
@@ -1,19 +1,15 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
1
  import { GridFilterInputDate } from '../components/panel/filterPanel/GridFilterInputDate';
3
- var dateRegex = /(\d+)-(\d+)-(\d+)/;
4
- var dateTimeRegex = /(\d+)-(\d+)-(\d+)T(\d+):(\d+)/;
5
2
  function buildApplyFilterFn(filterItem, compareFn, showTime, keepHours) {
6
3
  if (!filterItem.value) {
7
4
  return null;
8
5
  }
9
- var _slice$map = filterItem.value.match(showTime ? dateTimeRegex : dateRegex).slice(1).map(Number),
10
- _slice$map2 = _slicedToArray(_slice$map, 5),
11
- year = _slice$map2[0],
12
- month = _slice$map2[1],
13
- day = _slice$map2[2],
14
- hour = _slice$map2[3],
15
- minute = _slice$map2[4];
16
- var time = new Date(year, month - 1, day, hour || 0, minute || 0).getTime();
6
+ var date = new Date(filterItem.value);
7
+ if (showTime) {
8
+ date.setSeconds(0, 0);
9
+ } else {
10
+ date.setHours(0, 0, 0, 0);
11
+ }
12
+ var time = date.getTime();
17
13
  return function (value) {
18
14
  if (!value) {
19
15
  return false;
@@ -24,8 +20,12 @@ function buildApplyFilterFn(filterItem, compareFn, showTime, keepHours) {
24
20
 
25
21
  // Make a copy of the date to not reset the hours in the original object
26
22
  var dateCopy = new Date(value);
27
- var timeToCompare = dateCopy.setHours(showTime ? value.getHours() : 0, showTime ? value.getMinutes() : 0, 0, 0);
28
- return compareFn(timeToCompare, time);
23
+ if (showTime) {
24
+ dateCopy.setSeconds(0, 0);
25
+ } else {
26
+ dateCopy.setHours(0, 0, 0, 0);
27
+ }
28
+ return compareFn(dateCopy.getTime(), time);
29
29
  };
30
30
  }
31
31
  export var getGridDateOperators = function getGridDateOperators(showTime) {
@@ -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 { isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
6
+ import { getValueOptions, isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
7
7
  import { isObject } from '../utils/utils';
8
8
  var isArrayOfObjects = function isArrayOfObjects(options) {
9
9
  return _typeof(options[0]) === 'object';
@@ -27,16 +27,10 @@ export var GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
27
27
  if (!isSingleSelectColDef(colDef)) {
28
28
  return '';
29
29
  }
30
- var valueOptions;
31
- if (typeof colDef.valueOptions === 'function') {
32
- valueOptions = colDef.valueOptions({
33
- id: id,
34
- row: id ? api.getRow(id) : null,
35
- field: field
36
- });
37
- } else {
38
- valueOptions = colDef.valueOptions;
39
- }
30
+ var valueOptions = getValueOptions(colDef, {
31
+ id: id,
32
+ row: id ? api.getRow(id) : null
33
+ });
40
34
  if (value == null) {
41
35
  return '';
42
36
  }
@@ -56,10 +50,7 @@ export var GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
56
50
  // @ts-ignore
57
51
  pastedValueParser: function pastedValueParser(value, params) {
58
52
  var colDef = params.colDef;
59
- var colDefValueOptions = colDef.valueOptions;
60
- var valueOptions = typeof colDefValueOptions === 'function' ? colDefValueOptions({
61
- field: colDef.field
62
- }) : colDefValueOptions || [];
53
+ var valueOptions = getValueOptions(colDef) || [];
63
54
  var getOptionValue = colDef.getOptionValue;
64
55
  var valueOption = valueOptions.find(function (option) {
65
56
  if (getOptionValue(option) === value) {
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange", "initialOpen", "getOptionLabel", "getOptionValue"],
5
+ var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange", "initialOpen"],
6
6
  _excluded2 = ["MenuProps"];
7
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
8
  import * as React from 'react';
@@ -12,7 +12,7 @@ import { GridCellEditStopReasons } from '../../models/params/gridEditCellParams'
12
12
  import { isEscapeKey } from '../../utils/keyboardUtils';
13
13
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
14
14
  import { GridEditModes } from '../../models/gridEditRowModel';
15
- import { getValueFromValueOptions, isSingleSelectColDef } from '../panel/filterPanel/filterPanelUtils';
15
+ import { getValueFromValueOptions, getValueOptions, isSingleSelectColDef } from '../panel/filterPanel/filterPanelUtils';
16
16
  import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
17
17
  import { createElement as _createElement } from "react";
18
18
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -41,8 +41,6 @@ function GridEditSingleSelectCell(props) {
41
41
  onValueChange = props.onValueChange,
42
42
  _props$initialOpen = props.initialOpen,
43
43
  initialOpen = _props$initialOpen === void 0 ? rootProps.editMode === GridEditModes.Cell : _props$initialOpen,
44
- getOptionLabelProp = props.getOptionLabel,
45
- getOptionValueProp = props.getOptionValue,
46
44
  other = _objectWithoutProperties(props, _excluded);
47
45
  var apiRef = useGridApiContext();
48
46
  var ref = React.useRef();
@@ -65,21 +63,15 @@ function GridEditSingleSelectCell(props) {
65
63
  if (!isSingleSelectColDef(colDef)) {
66
64
  return null;
67
65
  }
68
- var valueOptions;
69
- if (typeof (colDef == null ? void 0 : colDef.valueOptions) === 'function') {
70
- valueOptions = colDef == null ? void 0 : colDef.valueOptions({
71
- id: id,
72
- row: row,
73
- field: field
74
- });
75
- } else {
76
- valueOptions = colDef == null ? void 0 : colDef.valueOptions;
77
- }
66
+ var valueOptions = getValueOptions(colDef, {
67
+ id: id,
68
+ row: row
69
+ });
78
70
  if (!valueOptions) {
79
71
  return null;
80
72
  }
81
- var getOptionValue = getOptionValueProp || colDef.getOptionValue;
82
- var getOptionLabel = getOptionLabelProp || colDef.getOptionLabel;
73
+ var getOptionValue = colDef.getOptionValue;
74
+ var getOptionLabel = colDef.getOptionLabel;
83
75
  var handleChange = /*#__PURE__*/function () {
84
76
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
85
77
  var target, formattedTargetValue;
@@ -190,18 +182,6 @@ process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes = {
190
182
  * The cell value formatted with the column valueFormatter.
191
183
  */
192
184
  formattedValue: PropTypes.any,
193
- /**
194
- * Used to determine the label displayed for a given value option.
195
- * @param {ValueOptions} value The current value option.
196
- * @returns {string} The text to be displayed.
197
- */
198
- getOptionLabel: PropTypes.func,
199
- /**
200
- * Used to determine the value used for a value option.
201
- * @param {ValueOptions} value The current value option.
202
- * @returns {string} The value to be used.
203
- */
204
- getOptionValue: PropTypes.func,
205
185
  /**
206
186
  * If true, the cell is the active element.
207
187
  */
@@ -5,6 +5,7 @@ var _excluded = ["field", "colDef"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
8
+ import { isMultipleRowSelectionEnabled } from '../../hooks/features/rowSelection/utils';
8
9
  import { useGridSelector } from '../../hooks/utils/useGridSelector';
9
10
  import { gridTabIndexColumnHeaderSelector } from '../../hooks/features/focus/gridFocusStateSelector';
10
11
  import { gridRowSelectionStateSelector } from '../../hooks/features/rowSelection/gridRowSelectionSelector';
@@ -112,7 +113,8 @@ var GridHeaderCheckbox = /*#__PURE__*/React.forwardRef(function GridHeaderCheckb
112
113
  'aria-label': label
113
114
  },
114
115
  tabIndex: tabIndex,
115
- onKeyDown: handleKeyDown
116
+ onKeyDown: handleKeyDown,
117
+ disabled: !isMultipleRowSelectionEnabled(rootProps)
116
118
  }, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseCheckbox, other));
117
119
  });
118
120
  process.env.NODE_ENV !== "production" ? GridHeaderCheckbox.propTypes = {
@@ -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]),