@mui/x-data-grid 6.0.0-alpha.2 → 6.0.0-alpha.3
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 +231 -12
- package/DataGrid/DataGrid.js +0 -20
- package/DataGrid/useDataGridComponent.js +2 -6
- package/colDef/gridNumericOperators.d.ts +1 -1
- package/colDef/gridSingleSelectOperators.d.ts +1 -1
- package/colDef/gridStringOperators.d.ts +1 -1
- package/components/cell/GridEditInputCell.js +3 -8
- package/components/cell/GridEditSingleSelectCell.js +6 -38
- package/components/panel/filterPanel/GridFilterForm.d.ts +12 -0
- package/components/panel/filterPanel/GridFilterForm.js +29 -7
- package/components/panel/filterPanel/GridFilterPanel.d.ts +12 -0
- package/components/panel/filterPanel/GridFilterPanel.js +64 -19
- package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.d.ts +1 -1
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +1 -1
- package/hooks/core/strategyProcessing/useGridRegisterStrategyProcessor.d.ts +1 -1
- package/hooks/core/useGridInitialization.d.ts +1 -1
- package/hooks/core/useGridStateInitialization.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/hooks/features/{editRows/gridEditRowsSelector.d.ts → editing/gridEditingSelectors.d.ts} +0 -0
- package/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/hooks/features/editing/index.d.ts +1 -0
- package/hooks/features/editing/index.js +1 -0
- package/hooks/features/{editRows/useGridCellEditing.new.d.ts → editing/useGridCellEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/hooks/features/{editRows/useGridEditing.new.d.ts → editing/useGridEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/hooks/features/{editRows/useGridRowEditing.new.d.ts → editing/useGridRowEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/hooks/features/index.d.ts +1 -1
- package/hooks/features/index.js +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
- package/hooks/utils/useGridApi.d.ts +1 -1
- package/hooks/utils/useGridApiEventHandler.d.ts +2 -2
- package/hooks/utils/useGridApiRef.d.ts +1 -1
- package/hooks/utils/useGridInitializeState.d.ts +1 -1
- package/hooks/utils/useGridNativeEventListener.d.ts +1 -1
- package/hooks/utils/useGridSelector.d.ts +1 -1
- package/hooks/utils/useGridState.d.ts +1 -1
- package/hooks/utils/useGridVisibleRows.d.ts +2 -2
- package/index.js +1 -1
- package/internals/index.d.ts +1 -2
- package/internals/index.js +1 -2
- package/legacy/DataGrid/DataGrid.js +0 -20
- package/legacy/DataGrid/useDataGridComponent.js +2 -6
- package/legacy/components/cell/GridEditInputCell.js +3 -8
- package/legacy/components/cell/GridEditSingleSelectCell.js +6 -52
- package/legacy/components/panel/filterPanel/GridFilterForm.js +31 -7
- package/legacy/components/panel/filterPanel/GridFilterPanel.js +67 -18
- package/legacy/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/legacy/hooks/features/editing/index.js +1 -0
- package/legacy/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/legacy/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/legacy/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/legacy/hooks/features/index.js +1 -1
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +1 -2
- package/legacy/models/params/gridEditCellParams.js +0 -4
- package/models/api/gridApiCommon.d.ts +2 -5
- package/models/api/gridApiCommunity.d.ts +1 -7
- package/models/api/gridEditingApi.d.ts +36 -121
- package/models/api/index.d.ts +1 -1
- package/models/events/gridEventLookup.d.ts +1 -15
- package/models/params/gridEditCellParams.d.ts +4 -17
- package/models/params/gridEditCellParams.js +0 -4
- package/models/params/gridRowParams.d.ts +4 -4
- package/models/props/DataGridProps.d.ts +0 -24
- package/modern/DataGrid/DataGrid.js +0 -20
- package/modern/DataGrid/useDataGridComponent.js +2 -4
- package/modern/components/cell/GridEditInputCell.js +3 -4
- package/modern/components/cell/GridEditSingleSelectCell.js +6 -34
- package/modern/components/panel/filterPanel/GridFilterForm.js +29 -7
- package/modern/components/panel/filterPanel/GridFilterPanel.js +62 -17
- package/modern/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/modern/hooks/features/editing/index.js +1 -0
- package/modern/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/modern/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/modern/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/modern/hooks/features/index.js +1 -1
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -2
- package/modern/models/params/gridEditCellParams.js +0 -4
- package/node/DataGrid/DataGrid.js +0 -20
- package/node/DataGrid/useDataGridComponent.js +3 -8
- package/node/components/cell/GridEditInputCell.js +3 -9
- package/node/components/cell/GridEditSingleSelectCell.js +6 -38
- package/node/components/panel/filterPanel/GridFilterForm.js +30 -7
- package/node/components/panel/filterPanel/GridFilterPanel.js +63 -19
- package/node/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/node/hooks/features/{editRows → editing}/index.js +4 -4
- package/node/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +28 -13
- package/node/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +4 -4
- package/node/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +28 -14
- package/node/hooks/features/index.js +4 -4
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +2 -2
- package/node/index.js +1 -1
- package/node/internals/index.js +3 -17
- package/node/models/params/gridEditCellParams.js +0 -3
- package/package.json +2 -2
- package/hooks/features/editRows/index.d.ts +0 -1
- package/hooks/features/editRows/index.js +0 -1
- package/hooks/features/editRows/useGridCellEditing.old.d.ts +0 -4
- package/hooks/features/editRows/useGridCellEditing.old.js +0 -359
- package/hooks/features/editRows/useGridEditing.old.d.ts +0 -11
- package/hooks/features/editRows/useGridEditing.old.js +0 -167
- package/hooks/features/editRows/useGridRowEditing.old.d.ts +0 -4
- package/hooks/features/editRows/useGridRowEditing.old.js +0 -334
- package/legacy/hooks/features/editRows/index.js +0 -1
- package/legacy/hooks/features/editRows/useGridCellEditing.old.js +0 -411
- package/legacy/hooks/features/editRows/useGridEditing.old.js +0 -184
- package/legacy/hooks/features/editRows/useGridRowEditing.old.js +0 -505
- package/modern/hooks/features/editRows/index.js +0 -1
- package/modern/hooks/features/editRows/useGridCellEditing.old.js +0 -355
- package/modern/hooks/features/editRows/useGridEditing.old.js +0 -163
- package/modern/hooks/features/editRows/useGridRowEditing.old.js +0 -326
- package/node/hooks/features/editRows/useGridCellEditing.old.js +0 -380
- package/node/hooks/features/editRows/useGridEditing.old.js +0 -193
- package/node/hooks/features/editRows/useGridRowEditing.old.js +0 -358
|
@@ -13,7 +13,6 @@ import InputBase from '@mui/material/InputBase';
|
|
|
13
13
|
import { getDataGridUtilityClass } from '../../constants/gridClasses';
|
|
14
14
|
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
15
15
|
import { GridLoadIcon } from '../icons/index';
|
|
16
|
-
import { SUBMIT_FILTER_STROKE_TIME } from '../panel/filterPanel/GridFilterInputValue';
|
|
17
16
|
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
|
|
18
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
18
|
|
|
@@ -42,8 +41,6 @@ var GridEditInputCellRoot = styled(InputBase, {
|
|
|
42
41
|
});
|
|
43
42
|
});
|
|
44
43
|
var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
45
|
-
var _rootProps$experiment, _rootProps$experiment3;
|
|
46
|
-
|
|
47
44
|
var rootProps = useGridRootProps();
|
|
48
45
|
|
|
49
46
|
var id = props.id,
|
|
@@ -61,7 +58,7 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
61
58
|
getValue = props.getValue,
|
|
62
59
|
isValidating = props.isValidating,
|
|
63
60
|
_props$debounceMs = props.debounceMs,
|
|
64
|
-
debounceMs = _props$debounceMs === void 0 ?
|
|
61
|
+
debounceMs = _props$debounceMs === void 0 ? 200 : _props$debounceMs,
|
|
65
62
|
isProcessingProps = props.isProcessingProps,
|
|
66
63
|
onValueChange = props.onValueChange,
|
|
67
64
|
other = _objectWithoutProperties(props, _excluded);
|
|
@@ -80,8 +77,6 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
80
77
|
var classes = useUtilityClasses(ownerState);
|
|
81
78
|
var handleChange = React.useCallback( /*#__PURE__*/function () {
|
|
82
79
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
|
|
83
|
-
var _rootProps$experiment2;
|
|
84
|
-
|
|
85
80
|
var newValue, column, parsedValue;
|
|
86
81
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
87
82
|
while (1) {
|
|
@@ -101,7 +96,7 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
101
96
|
column = apiRef.current.getColumn(field);
|
|
102
97
|
parsedValue = newValue;
|
|
103
98
|
|
|
104
|
-
if (column.valueParser
|
|
99
|
+
if (column.valueParser) {
|
|
105
100
|
parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
|
|
106
101
|
}
|
|
107
102
|
|
|
@@ -125,7 +120,7 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
125
120
|
return function (_x) {
|
|
126
121
|
return _ref2.apply(this, arguments);
|
|
127
122
|
};
|
|
128
|
-
}(), [apiRef, debounceMs, field, id, onValueChange
|
|
123
|
+
}(), [apiRef, debounceMs, field, id, onValueChange]);
|
|
129
124
|
var meta = apiRef.current.unstable_getEditCellMeta ? apiRef.current.unstable_getEditCellMeta(id, field) : {};
|
|
130
125
|
React.useEffect(function () {
|
|
131
126
|
if (meta.changeReason !== 'debouncedSetEditCellValue') {
|
|
@@ -101,9 +101,7 @@ function GridEditSingleSelectCell(props) {
|
|
|
101
101
|
|
|
102
102
|
var handleChange = /*#__PURE__*/function () {
|
|
103
103
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
var target, formattedTargetValue, isValid, canCommit, params;
|
|
104
|
+
var target, formattedTargetValue;
|
|
107
105
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
108
106
|
while (1) {
|
|
109
107
|
switch (_context.prev = _context.next) {
|
|
@@ -130,44 +128,6 @@ function GridEditSingleSelectCell(props) {
|
|
|
130
128
|
}, event);
|
|
131
129
|
|
|
132
130
|
case 8:
|
|
133
|
-
isValid = _context.sent;
|
|
134
|
-
|
|
135
|
-
if (!((_rootProps$experiment = rootProps.experimentalFeatures) != null && _rootProps$experiment.newEditingApi)) {
|
|
136
|
-
_context.next = 11;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return _context.abrupt("return");
|
|
141
|
-
|
|
142
|
-
case 11:
|
|
143
|
-
if (!(rootProps.editMode === GridEditModes.Row || isValid === false)) {
|
|
144
|
-
_context.next = 13;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return _context.abrupt("return");
|
|
149
|
-
|
|
150
|
-
case 13:
|
|
151
|
-
_context.next = 15;
|
|
152
|
-
return Promise.resolve(apiRef.current.commitCellChange({
|
|
153
|
-
id: id,
|
|
154
|
-
field: field
|
|
155
|
-
}, event));
|
|
156
|
-
|
|
157
|
-
case 15:
|
|
158
|
-
canCommit = _context.sent;
|
|
159
|
-
|
|
160
|
-
if (canCommit) {
|
|
161
|
-
apiRef.current.setCellMode(id, field, 'view');
|
|
162
|
-
|
|
163
|
-
if (event.key) {
|
|
164
|
-
// TODO v6: remove once we stop ignoring events fired from portals
|
|
165
|
-
params = apiRef.current.getCellParams(id, field);
|
|
166
|
-
apiRef.current.publishEvent('cellNavigationKeyDown', params, event);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
case 17:
|
|
171
131
|
case "end":
|
|
172
132
|
return _context.stop();
|
|
173
133
|
}
|
|
@@ -187,17 +147,11 @@ function GridEditSingleSelectCell(props) {
|
|
|
187
147
|
}
|
|
188
148
|
|
|
189
149
|
if (reason === 'backdropClick' || isEscapeKey(event.key)) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
field: field,
|
|
196
|
-
ignoreModifications: true
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
apiRef.current.setCellMode(id, field, 'view');
|
|
200
|
-
}
|
|
150
|
+
apiRef.current.stopCellEditMode({
|
|
151
|
+
id: id,
|
|
152
|
+
field: field,
|
|
153
|
+
ignoreModifications: true
|
|
154
|
+
});
|
|
201
155
|
}
|
|
202
156
|
};
|
|
203
157
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "multiFilterOperator", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "linkOperators", "columnsSort", "deleteIconProps", "linkOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "children"],
|
|
3
|
+
var _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "multiFilterOperator", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "linkOperators", "columnsSort", "filterColumns", "deleteIconProps", "linkOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "children"],
|
|
4
4
|
_excluded2 = ["InputComponentProps"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
@@ -13,6 +13,7 @@ import { capitalize, unstable_useId as useId } from '@mui/material/utils';
|
|
|
13
13
|
import { styled } from '@mui/material/styles';
|
|
14
14
|
import clsx from 'clsx';
|
|
15
15
|
import { gridFilterableColumnDefinitionsSelector } from '../../../hooks/features/columns/gridColumnsSelector';
|
|
16
|
+
import { gridFilterModelSelector } from '../../../hooks/features/filter/gridFilterSelector';
|
|
16
17
|
import { useGridSelector } from '../../../hooks/utils/useGridSelector';
|
|
17
18
|
import { GridLinkOperator } from '../../../models/gridFilterItem';
|
|
18
19
|
import { useGridApiContext } from '../../../hooks/utils/useGridApiContext';
|
|
@@ -134,6 +135,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
|
|
|
134
135
|
_props$linkOperators = props.linkOperators,
|
|
135
136
|
linkOperators = _props$linkOperators === void 0 ? [GridLinkOperator.And, GridLinkOperator.Or] : _props$linkOperators,
|
|
136
137
|
columnsSort = props.columnsSort,
|
|
138
|
+
filterColumns = props.filterColumns,
|
|
137
139
|
_props$deleteIconProp = props.deleteIconProps,
|
|
138
140
|
deleteIconProps = _props$deleteIconProp === void 0 ? {} : _props$deleteIconProp,
|
|
139
141
|
_props$linkOperatorIn = props.linkOperatorInputProps,
|
|
@@ -149,6 +151,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
|
|
|
149
151
|
|
|
150
152
|
var apiRef = useGridApiContext();
|
|
151
153
|
var filterableColumns = useGridSelector(apiRef, gridFilterableColumnDefinitionsSelector);
|
|
154
|
+
var filterModel = useGridSelector(apiRef, gridFilterModelSelector);
|
|
152
155
|
var columnSelectId = useId();
|
|
153
156
|
var columnSelectLabelId = useId();
|
|
154
157
|
var operatorSelectId = useId();
|
|
@@ -169,22 +172,36 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
|
|
|
169
172
|
var InputComponentProps = valueInputProps.InputComponentProps,
|
|
170
173
|
valueInputPropsOther = _objectWithoutProperties(valueInputProps, _excluded2);
|
|
171
174
|
|
|
172
|
-
var
|
|
175
|
+
var filteredColumns = React.useMemo(function () {
|
|
176
|
+
if (filterColumns === undefined || typeof filterColumns !== 'function') {
|
|
177
|
+
return filterableColumns;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
var filteredFields = filterColumns({
|
|
181
|
+
field: item.columnField,
|
|
182
|
+
columns: filterableColumns,
|
|
183
|
+
currentFilters: (filterModel == null ? void 0 : filterModel.items) || []
|
|
184
|
+
});
|
|
185
|
+
return filterableColumns.filter(function (column) {
|
|
186
|
+
return filteredFields.includes(column.field);
|
|
187
|
+
});
|
|
188
|
+
}, [filterColumns, filterModel == null ? void 0 : filterModel.items, filterableColumns, item.columnField]);
|
|
189
|
+
var sortedFilteredColumns = React.useMemo(function () {
|
|
173
190
|
switch (columnsSort) {
|
|
174
191
|
case 'asc':
|
|
175
|
-
return
|
|
192
|
+
return filteredColumns.sort(function (a, b) {
|
|
176
193
|
return collator.compare(getColumnLabel(a), getColumnLabel(b));
|
|
177
194
|
});
|
|
178
195
|
|
|
179
196
|
case 'desc':
|
|
180
|
-
return
|
|
197
|
+
return filteredColumns.sort(function (a, b) {
|
|
181
198
|
return -collator.compare(getColumnLabel(a), getColumnLabel(b));
|
|
182
199
|
});
|
|
183
200
|
|
|
184
201
|
default:
|
|
185
|
-
return
|
|
202
|
+
return filteredColumns;
|
|
186
203
|
}
|
|
187
|
-
}, [
|
|
204
|
+
}, [filteredColumns, columnsSort]);
|
|
188
205
|
var currentColumn = item.columnField ? apiRef.current.getColumn(item.columnField) : null;
|
|
189
206
|
var currentOperator = React.useMemo(function () {
|
|
190
207
|
var _currentColumn$filter;
|
|
@@ -323,7 +340,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
|
|
|
323
340
|
onChange: changeColumn,
|
|
324
341
|
native: isBaseSelectNative
|
|
325
342
|
}, (_rootProps$components4 = rootProps.componentsProps) == null ? void 0 : _rootProps$components4.baseSelect, {
|
|
326
|
-
children:
|
|
343
|
+
children: sortedFilteredColumns.map(function (col) {
|
|
327
344
|
return /*#__PURE__*/_jsx(OptionComponent, {
|
|
328
345
|
value: col.field,
|
|
329
346
|
children: getColumnLabel(col)
|
|
@@ -421,6 +438,13 @@ process.env.NODE_ENV !== "production" ? GridFilterForm.propTypes = {
|
|
|
421
438
|
*/
|
|
422
439
|
disableMultiFilterOperator: PropTypes.bool,
|
|
423
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Allows to filter the columns displayed in the filter form.
|
|
443
|
+
* @param {FilterColumnsArgs} args The columns of the grid and name of field.
|
|
444
|
+
* @returns {GridColDef['field'][]} The filtered fields array.
|
|
445
|
+
*/
|
|
446
|
+
filterColumns: PropTypes.func,
|
|
447
|
+
|
|
424
448
|
/**
|
|
425
449
|
* A ref allowing to set imperative focus.
|
|
426
450
|
* It can be passed to the el
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["linkOperators", "columnsSort", "filterFormProps", "children"];
|
|
4
|
+
var _excluded = ["linkOperators", "columnsSort", "filterFormProps", "getColumnForNewFilter", "children"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { GridLinkOperator } from '../../../models/gridFilterItem';
|
|
@@ -17,6 +17,15 @@ import { gridFilterModelSelector } from '../../../hooks/features/filter/gridFilt
|
|
|
17
17
|
import { gridFilterableColumnDefinitionsSelector } from '../../../hooks/features/columns/gridColumnsSelector';
|
|
18
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
|
|
21
|
+
var getGridFilter = function getGridFilter(col) {
|
|
22
|
+
return {
|
|
23
|
+
columnField: col.field,
|
|
24
|
+
operatorValue: col.filterOperators[0].value,
|
|
25
|
+
id: Math.round(Math.random() * 1e5)
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
20
29
|
var GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(props, ref) {
|
|
21
30
|
var _rootProps$components;
|
|
22
31
|
|
|
@@ -30,6 +39,7 @@ var GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(pro
|
|
|
30
39
|
linkOperators = _props$linkOperators === void 0 ? [GridLinkOperator.And, GridLinkOperator.Or] : _props$linkOperators,
|
|
31
40
|
columnsSort = props.columnsSort,
|
|
32
41
|
filterFormProps = props.filterFormProps,
|
|
42
|
+
getColumnForNewFilter = props.getColumnForNewFilter,
|
|
33
43
|
children = props.children,
|
|
34
44
|
other = _objectWithoutProperties(props, _excluded);
|
|
35
45
|
|
|
@@ -39,41 +49,73 @@ var GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(pro
|
|
|
39
49
|
var applyFilterLinkOperator = React.useCallback(function (operator) {
|
|
40
50
|
apiRef.current.setFilterLinkOperator(operator);
|
|
41
51
|
}, [apiRef]);
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
|
|
52
|
+
var getDefaultFilter = React.useCallback(function () {
|
|
53
|
+
var nextColumnWithOperator;
|
|
54
|
+
|
|
55
|
+
if (getColumnForNewFilter && typeof getColumnForNewFilter === 'function') {
|
|
56
|
+
// To allow override the column for default (first) filter
|
|
57
|
+
var nextColumnFieldName = getColumnForNewFilter({
|
|
58
|
+
currentFilters: (filterModel == null ? void 0 : filterModel.items) || [],
|
|
59
|
+
columns: filterableColumns
|
|
60
|
+
});
|
|
61
|
+
nextColumnWithOperator = filterableColumns.find(function (_ref) {
|
|
62
|
+
var field = _ref.field;
|
|
63
|
+
return field === nextColumnFieldName;
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
nextColumnWithOperator = filterableColumns.find(function (colDef) {
|
|
67
|
+
var _colDef$filterOperato;
|
|
68
|
+
|
|
69
|
+
return (_colDef$filterOperato = colDef.filterOperators) == null ? void 0 : _colDef$filterOperato.length;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!nextColumnWithOperator) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
45
76
|
|
|
46
|
-
|
|
77
|
+
return getGridFilter(nextColumnWithOperator);
|
|
78
|
+
}, [filterModel == null ? void 0 : filterModel.items, filterableColumns, getColumnForNewFilter]);
|
|
79
|
+
var getNewFilter = React.useCallback(function () {
|
|
80
|
+
if (getColumnForNewFilter === undefined || typeof getColumnForNewFilter !== 'function') {
|
|
81
|
+
return getDefaultFilter();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var currentFilters = filterModel.items.length ? filterModel.items : [getDefaultFilter()].filter(Boolean); // If no items are there in filterModel, we have to pass defaultFilter
|
|
85
|
+
|
|
86
|
+
var nextColumnFieldName = getColumnForNewFilter({
|
|
87
|
+
currentFilters: currentFilters,
|
|
88
|
+
columns: filterableColumns
|
|
89
|
+
});
|
|
90
|
+
var nextColumnWithOperator = filterableColumns.find(function (_ref2) {
|
|
91
|
+
var field = _ref2.field;
|
|
92
|
+
return field === nextColumnFieldName;
|
|
47
93
|
});
|
|
48
94
|
|
|
49
|
-
if (!
|
|
95
|
+
if (!nextColumnWithOperator) {
|
|
50
96
|
return null;
|
|
51
97
|
}
|
|
52
98
|
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
operatorValue: firstColumnWithOperator.filterOperators[0].value,
|
|
56
|
-
id: Math.round(Math.random() * 1e5)
|
|
57
|
-
};
|
|
58
|
-
}, [filterableColumns]);
|
|
99
|
+
return getGridFilter(nextColumnWithOperator);
|
|
100
|
+
}, [filterModel.items, filterableColumns, getColumnForNewFilter, getDefaultFilter]);
|
|
59
101
|
var items = React.useMemo(function () {
|
|
60
102
|
if (filterModel.items.length) {
|
|
61
103
|
return filterModel.items;
|
|
62
104
|
}
|
|
63
105
|
|
|
64
|
-
var
|
|
65
|
-
return
|
|
66
|
-
}, [filterModel.items,
|
|
106
|
+
var defaultFilter = getDefaultFilter();
|
|
107
|
+
return defaultFilter ? [defaultFilter] : [];
|
|
108
|
+
}, [filterModel.items, getDefaultFilter]);
|
|
67
109
|
var hasMultipleFilters = items.length > 1;
|
|
68
110
|
|
|
69
111
|
var addNewFilter = function addNewFilter() {
|
|
70
|
-
var
|
|
112
|
+
var newFilter = getNewFilter();
|
|
71
113
|
|
|
72
|
-
if (!
|
|
114
|
+
if (!newFilter) {
|
|
73
115
|
return;
|
|
74
116
|
}
|
|
75
117
|
|
|
76
|
-
apiRef.current.upsertFilterItems([].concat(_toConsumableArray(items), [
|
|
118
|
+
apiRef.current.upsertFilterItems([].concat(_toConsumableArray(items), [newFilter]));
|
|
77
119
|
};
|
|
78
120
|
|
|
79
121
|
var deleteFilter = React.useCallback(function (item) {
|
|
@@ -152,6 +194,13 @@ process.env.NODE_ENV !== "production" ? GridFilterPanel.propTypes = {
|
|
|
152
194
|
valueInputProps: PropTypes.any
|
|
153
195
|
}),
|
|
154
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Function that returns the next filter item to be picked as default filter.
|
|
199
|
+
* @param {GetColumnForNewFilterArgs} args Currently configured filters and columns.
|
|
200
|
+
* @returns {GridColDef['field']} The field to be used for the next filter.
|
|
201
|
+
*/
|
|
202
|
+
getColumnForNewFilter: PropTypes.func,
|
|
203
|
+
|
|
155
204
|
/**
|
|
156
205
|
* Sets the available logic operators.
|
|
157
206
|
* @default [GridLinkOperator.And, GridLinkOperator.Or]
|
package/legacy/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js}
RENAMED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './gridEditingSelectors';
|
package/legacy/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js}
RENAMED
|
@@ -12,7 +12,7 @@ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
|
12
12
|
import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
|
|
13
13
|
import { GridEditModes, GridCellModes } from '../../../models/gridEditRowModel';
|
|
14
14
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
15
|
-
import { gridEditRowsStateSelector } from './
|
|
15
|
+
import { gridEditRowsStateSelector } from './gridEditingSelectors';
|
|
16
16
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
17
17
|
import { buildWarning } from '../../../utils/warning';
|
|
18
18
|
import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
@@ -129,7 +129,8 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
129
129
|
|
|
130
130
|
if (_reason) {
|
|
131
131
|
var _newParams = _extends({}, params, {
|
|
132
|
-
reason: _reason
|
|
132
|
+
reason: _reason,
|
|
133
|
+
key: event.key
|
|
133
134
|
});
|
|
134
135
|
|
|
135
136
|
apiRef.current.publishEvent('cellEditStart', _newParams, event);
|
|
@@ -139,13 +140,20 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
139
140
|
var handleCellEditStart = React.useCallback(function (params) {
|
|
140
141
|
var id = params.id,
|
|
141
142
|
field = params.field,
|
|
142
|
-
reason = params.reason
|
|
143
|
+
reason = params.reason,
|
|
144
|
+
key = params.key;
|
|
143
145
|
var startCellEditModeParams = {
|
|
144
146
|
id: id,
|
|
145
147
|
field: field
|
|
146
148
|
};
|
|
147
149
|
|
|
148
|
-
if (reason === GridCellEditStartReasons.
|
|
150
|
+
if (reason === GridCellEditStartReasons.printableKeyDown) {
|
|
151
|
+
if (React.version.startsWith('18')) {
|
|
152
|
+
startCellEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
|
|
153
|
+
} else {
|
|
154
|
+
startCellEditModeParams.deleteValue = true;
|
|
155
|
+
}
|
|
156
|
+
} else if (reason === GridCellEditStartReasons.deleteKeyDown) {
|
|
149
157
|
startCellEditModeParams.deleteValue = true;
|
|
150
158
|
}
|
|
151
159
|
|
|
@@ -268,9 +276,16 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
268
276
|
var updateStateToStartCellEditMode = useEventCallback(function (params) {
|
|
269
277
|
var id = params.id,
|
|
270
278
|
field = params.field,
|
|
271
|
-
deleteValue = params.deleteValue
|
|
279
|
+
deleteValue = params.deleteValue,
|
|
280
|
+
initialValue = params.initialValue;
|
|
281
|
+
var newValue = apiRef.current.getCellValue(id, field);
|
|
282
|
+
|
|
283
|
+
if (deleteValue || initialValue) {
|
|
284
|
+
newValue = deleteValue ? '' : initialValue;
|
|
285
|
+
}
|
|
286
|
+
|
|
272
287
|
var newProps = {
|
|
273
|
-
value:
|
|
288
|
+
value: newValue,
|
|
274
289
|
error: false,
|
|
275
290
|
isProcessingProps: false
|
|
276
291
|
};
|
|
@@ -4,10 +4,10 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
7
|
-
import { useGridCellEditing } from './useGridCellEditing
|
|
7
|
+
import { useGridCellEditing } from './useGridCellEditing';
|
|
8
8
|
import { GridCellModes, GridEditModes } from '../../../models/gridEditRowModel';
|
|
9
|
-
import { useGridRowEditing } from './useGridRowEditing
|
|
10
|
-
import { gridEditRowsStateSelector } from './
|
|
9
|
+
import { useGridRowEditing } from './useGridRowEditing';
|
|
10
|
+
import { gridEditRowsStateSelector } from './gridEditingSelectors';
|
|
11
11
|
import { isAutoGeneratedRow } from '../rows/gridRowsUtils';
|
|
12
12
|
export var editingStateInitializer = function editingStateInitializer(state) {
|
|
13
13
|
return _extends({}, state, {
|
package/legacy/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js}
RENAMED
|
@@ -10,7 +10,7 @@ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
|
10
10
|
import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
|
|
11
11
|
import { GridEditModes, GridRowModes } from '../../../models/gridEditRowModel';
|
|
12
12
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
13
|
-
import { gridEditRowsStateSelector } from './
|
|
13
|
+
import { gridEditRowsStateSelector } from './gridEditingSelectors';
|
|
14
14
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
15
15
|
import { gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
16
16
|
import { buildWarning } from '../../../utils/warning';
|
|
@@ -189,6 +189,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
|
|
|
189
189
|
|
|
190
190
|
var _newParams = _extends({}, _rowParams, {
|
|
191
191
|
field: params.field,
|
|
192
|
+
key: event.key,
|
|
192
193
|
reason: _reason
|
|
193
194
|
});
|
|
194
195
|
|
|
@@ -199,13 +200,20 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
|
|
|
199
200
|
var handleRowEditStart = React.useCallback(function (params) {
|
|
200
201
|
var id = params.id,
|
|
201
202
|
field = params.field,
|
|
202
|
-
reason = params.reason
|
|
203
|
+
reason = params.reason,
|
|
204
|
+
key = params.key;
|
|
203
205
|
var startRowEditModeParams = {
|
|
204
206
|
id: id,
|
|
205
207
|
fieldToFocus: field
|
|
206
208
|
};
|
|
207
209
|
|
|
208
|
-
if (reason === GridRowEditStartReasons.
|
|
210
|
+
if (reason === GridRowEditStartReasons.printableKeyDown) {
|
|
211
|
+
if (React.version.startsWith('18')) {
|
|
212
|
+
startRowEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
|
|
213
|
+
} else {
|
|
214
|
+
startRowEditModeParams.deleteValue = !!field;
|
|
215
|
+
}
|
|
216
|
+
} else if (reason === GridRowEditStartReasons.deleteKeyDown) {
|
|
209
217
|
startRowEditModeParams.deleteValue = !!field;
|
|
210
218
|
}
|
|
211
219
|
|
|
@@ -338,7 +346,8 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
|
|
|
338
346
|
var updateStateToStartRowEditMode = useEventCallback(function (params) {
|
|
339
347
|
var id = params.id,
|
|
340
348
|
fieldToFocus = params.fieldToFocus,
|
|
341
|
-
deleteValue = params.deleteValue
|
|
349
|
+
deleteValue = params.deleteValue,
|
|
350
|
+
initialValue = params.initialValue;
|
|
342
351
|
var columnFields = gridColumnFieldsSelector(apiRef);
|
|
343
352
|
var newProps = columnFields.reduce(function (acc, field) {
|
|
344
353
|
var cellParams = apiRef.current.getCellParams(id, field);
|
|
@@ -347,9 +356,14 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
|
|
|
347
356
|
return acc;
|
|
348
357
|
}
|
|
349
358
|
|
|
350
|
-
var
|
|
359
|
+
var newValue = apiRef.current.getCellValue(id, field);
|
|
360
|
+
|
|
361
|
+
if (fieldToFocus === field && (deleteValue || initialValue)) {
|
|
362
|
+
newValue = deleteValue ? '' : initialValue;
|
|
363
|
+
}
|
|
364
|
+
|
|
351
365
|
acc[field] = {
|
|
352
|
-
value:
|
|
366
|
+
value: newValue,
|
|
353
367
|
error: false,
|
|
354
368
|
isProcessingProps: false
|
|
355
369
|
};
|
|
@@ -3,7 +3,7 @@ export * from './columnMenu';
|
|
|
3
3
|
export * from './columns';
|
|
4
4
|
export * from './columnGrouping';
|
|
5
5
|
export * from './density';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './editing';
|
|
7
7
|
export * from './filter';
|
|
8
8
|
export * from './focus';
|
|
9
9
|
export * from './pagination';
|
|
@@ -10,7 +10,7 @@ import { useGridRootProps } from '../../utils/useGridRootProps';
|
|
|
10
10
|
import { useGridSelector } from '../../utils/useGridSelector';
|
|
11
11
|
import { gridVisibleColumnDefinitionsSelector, gridColumnsTotalWidthSelector, gridColumnPositionsSelector } from '../columns/gridColumnsSelector';
|
|
12
12
|
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
|
|
13
|
-
import { gridEditRowsStateSelector } from '../
|
|
13
|
+
import { gridEditRowsStateSelector } from '../editing/gridEditingSelectors';
|
|
14
14
|
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
15
15
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
16
16
|
import { clamp } from '../../../utils/utils';
|
package/legacy/index.js
CHANGED
|
@@ -22,8 +22,7 @@ export { useGridFocus, focusStateInitializer } from '../hooks/features/focus/use
|
|
|
22
22
|
export { useGridKeyboardNavigation } from '../hooks/features/keyboardNavigation/useGridKeyboardNavigation';
|
|
23
23
|
export { useGridPagination, paginationStateInitializer } from '../hooks/features/pagination/useGridPagination';
|
|
24
24
|
export { useGridPreferencesPanel, preferencePanelStateInitializer } from '../hooks/features/preferencesPanel/useGridPreferencesPanel';
|
|
25
|
-
export { useGridEditing
|
|
26
|
-
export { useGridEditing as useGridEditing_old, editingStateInitializer as editingStateInitializer_old } from '../hooks/features/editRows/useGridEditing.old';
|
|
25
|
+
export { useGridEditing, editingStateInitializer } from '../hooks/features/editing/useGridEditing';
|
|
27
26
|
export { useGridRows, rowsStateInitializer } from '../hooks/features/rows/useGridRows';
|
|
28
27
|
export { useGridRowsPreProcessors } from '../hooks/features/rows/useGridRowsPreProcessors';
|
|
29
28
|
export { getTreeNodeDescendants, buildRootGroup } from '../hooks/features/rows/gridRowsUtils';
|
|
@@ -27,9 +27,6 @@ import type { GridDimensionsApi } from '../../hooks/features/dimensions';
|
|
|
27
27
|
import type { GridPaginationApi } from '../../hooks/features/pagination';
|
|
28
28
|
import type { GridStatePersistenceApi } from '../../hooks/features/statePersistence';
|
|
29
29
|
import { GridColumnGroupingApi } from './gridColumnGroupingApi';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
export interface GridApiCommon extends GridCoreApi, GridLoggerApi, GridPipeProcessingApi, GridStrategyProcessingApi, GridDensityApi, GridDimensionsApi, GridRowApi, GridRowsMetaApi, GridEditingApi, GridParamsApi, GridColumnApi, GridSelectionApi, GridSortApi, GridPaginationApi, GridCsvExportApi, GridFocusApi, GridFilterApi, GridColumnMenuApi, GridPreferencesPanelApi, GridPrintExportApi, GridDisableVirtualizationApi, GridVirtualScrollerApi, GridLocaleTextApi, GridClipboardApi, GridScrollApi, GridColumnSpanningApi, GridStateApiUntyped, GridColumnGroupingApi {
|
|
30
|
+
import type { GridInitialStateCommunity, GridStateCommunity } from '../gridStateCommunity';
|
|
31
|
+
export interface GridApiCommon<GridState extends GridStateCommunity = any, GridInitialState extends GridInitialStateCommunity = any> extends GridCoreApi, GridLoggerApi, GridPipeProcessingApi, GridStrategyProcessingApi, GridDensityApi, GridDimensionsApi, GridRowApi, GridRowsMetaApi, GridEditingApi, GridParamsApi, GridColumnApi, GridSelectionApi, GridSortApi, GridPaginationApi, GridCsvExportApi, GridFocusApi, GridFilterApi, GridColumnMenuApi, GridPreferencesPanelApi, GridPrintExportApi, GridDisableVirtualizationApi, GridVirtualScrollerApi, GridLocaleTextApi, GridClipboardApi, GridScrollApi, GridColumnSpanningApi, GridStateApi<GridState>, GridStatePersistenceApi<GridInitialState>, GridColumnGroupingApi {
|
|
34
32
|
}
|
|
35
|
-
export {};
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type { GridStateApi } from './gridStateApi';
|
|
2
1
|
import type { GridInitialStateCommunity, GridStateCommunity } from '../gridStateCommunity';
|
|
3
2
|
import type { GridApiCommon } from './gridApiCommon';
|
|
4
|
-
import type { GridStatePersistenceApi } from '../../hooks/features/statePersistence';
|
|
5
|
-
declare type GridStateApiUntyped = {
|
|
6
|
-
[key in keyof (GridStateApi<any> & GridStatePersistenceApi<any>)]: any;
|
|
7
|
-
};
|
|
8
3
|
/**
|
|
9
4
|
* The api of `DataGrid`.
|
|
10
5
|
*/
|
|
11
|
-
export interface GridApiCommunity extends
|
|
6
|
+
export interface GridApiCommunity extends GridApiCommon<GridStateCommunity, GridInitialStateCommunity> {
|
|
12
7
|
}
|
|
13
|
-
export {};
|