@mui/x-data-grid 5.17.1 → 5.17.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 +78 -0
- package/colDef/gridNumericOperators.d.ts +1 -1
- package/colDef/gridSingleSelectOperators.d.ts +1 -1
- package/colDef/gridStringOperators.d.ts +1 -1
- package/components/GridRow.js +5 -2
- package/components/cell/GridEditBooleanCell.js +1 -0
- package/components/cell/GridEditDateCell.js +1 -0
- package/components/cell/GridEditInputCell.js +21 -7
- package/components/cell/GridEditSingleSelectCell.js +1 -0
- package/hooks/features/editRows/useGridCellEditing.new.js +14 -5
- package/hooks/features/editRows/useGridEditing.new.js +9 -1
- package/hooks/features/editRows/useGridRowEditing.new.js +14 -5
- package/hooks/utils/useGridInitializeState.d.ts +1 -1
- package/index.js +1 -1
- package/legacy/components/GridRow.js +6 -2
- package/legacy/components/cell/GridEditBooleanCell.js +1 -0
- package/legacy/components/cell/GridEditDateCell.js +1 -0
- package/legacy/components/cell/GridEditInputCell.js +23 -9
- package/legacy/components/cell/GridEditSingleSelectCell.js +1 -0
- package/legacy/hooks/features/editRows/useGridCellEditing.new.js +16 -9
- package/legacy/hooks/features/editRows/useGridEditing.new.js +9 -1
- package/legacy/hooks/features/editRows/useGridRowEditing.new.js +14 -5
- package/legacy/index.js +1 -1
- package/legacy/utils/utils.js +7 -0
- package/models/api/gridEditingApi.d.ts +10 -0
- package/models/gridEditRowModel.d.ts +2 -0
- package/models/gridRows.d.ts +1 -1
- package/models/params/gridEditCellParams.d.ts +7 -3
- package/modern/components/GridRow.js +5 -2
- package/modern/components/cell/GridEditBooleanCell.js +1 -0
- package/modern/components/cell/GridEditDateCell.js +1 -0
- package/modern/components/cell/GridEditInputCell.js +18 -6
- package/modern/components/cell/GridEditSingleSelectCell.js +1 -0
- package/modern/hooks/features/editRows/useGridCellEditing.new.js +14 -5
- package/modern/hooks/features/editRows/useGridEditing.new.js +9 -1
- package/modern/hooks/features/editRows/useGridRowEditing.new.js +14 -5
- package/modern/index.js +1 -1
- package/modern/utils/utils.js +7 -0
- package/node/components/GridRow.js +4 -2
- package/node/components/cell/GridEditBooleanCell.js +1 -0
- package/node/components/cell/GridEditDateCell.js +1 -0
- package/node/components/cell/GridEditInputCell.js +21 -7
- package/node/components/cell/GridEditSingleSelectCell.js +1 -0
- package/node/hooks/features/editRows/useGridCellEditing.new.js +15 -5
- package/node/hooks/features/editRows/useGridEditing.new.js +10 -1
- package/node/hooks/features/editRows/useGridRowEditing.new.js +15 -5
- package/node/index.js +1 -1
- package/node/utils/utils.js +9 -0
- package/package.json +2 -2
- package/utils/utils.d.ts +1 -0
- package/utils/utils.js +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,84 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 5.17.3
|
|
7
|
+
|
|
8
|
+
_Sep 16, 2022_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 6 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 📝 Fix lost characters when typing into fields in the DataGrid (#5646) @m4theushw
|
|
13
|
+
- 🌏 New locale and improvements for pickers
|
|
14
|
+
- 🎁 Improve support to theme augmentation for pickers
|
|
15
|
+
|
|
16
|
+
### `@mui/x-data-grid@v5.17.3` / `@mui/x-data-grid-pro@v5.17.3` / `@mui/x-data-grid-premium@v5.17.3`
|
|
17
|
+
|
|
18
|
+
#### Changes
|
|
19
|
+
|
|
20
|
+
- [DataGrid] Only update input with value prop if debounce is off (#5646) @m4theushw
|
|
21
|
+
|
|
22
|
+
### `@mui/x-date-pickers@v5.0.2` / `@mui/x-date-pickers-pro@v5.0.2`
|
|
23
|
+
|
|
24
|
+
#### Changes
|
|
25
|
+
|
|
26
|
+
- [pickers] Add Icelandic (is-IS) locale (#6137) @elvatli
|
|
27
|
+
- [pickers] Fix `@mui/x-date-pickers` theme augmentation and style overriding (#6156) @LukasTy
|
|
28
|
+
- [pickers] Fix `@mui/x-date-pickers-pro` theme augmentation (#6096) @LukasTy
|
|
29
|
+
- [pickers] Improve German (de-DE) locale (#6138) @alexfauquette
|
|
30
|
+
|
|
31
|
+
### Docs
|
|
32
|
+
|
|
33
|
+
- [docs] Improve main demo to show new functionalities (#5292) @joserodolfofreitas
|
|
34
|
+
|
|
35
|
+
### Core
|
|
36
|
+
|
|
37
|
+
- [core] Update to typescript 4.8.3 (#6136) @flaviendelangle
|
|
38
|
+
- [core] Update RFC template (#6100) @bytasv
|
|
39
|
+
|
|
40
|
+
## 5.17.2
|
|
41
|
+
|
|
42
|
+
_Sep 9, 2022_
|
|
43
|
+
|
|
44
|
+
This release will the last regular release for our `v5` packages.
|
|
45
|
+
From now on, we'll be focusing on developing MUI X v6.
|
|
46
|
+
You can check the [roadmap](https://github.com/mui/mui-x/projects/1) for more details on what's coming next.
|
|
47
|
+
|
|
48
|
+
And if you'd like to help, please consider volunteering to give us a [user interview](https://forms.gle/vsBv6CLPz9h57xg8A).
|
|
49
|
+
We'd love to know more about your use cases, pain points and expectations for the future.
|
|
50
|
+
|
|
51
|
+
The `v5` packages will only get new versions to patch critical bug fixes.
|
|
52
|
+
|
|
53
|
+
We'd like to offer a big thanks to the 6 contributors who made this release possible. Here are some highlights ✨:
|
|
54
|
+
|
|
55
|
+
- 📃 Add support for column grouping when exporting to Excel (#5895) @alexfauquette
|
|
56
|
+
- 🐞 Bugfixes
|
|
57
|
+
|
|
58
|
+
### `@mui/x-data-grid@v5.17.2` / `@mui/x-data-grid-pro@v5.17.2` / `@mui/x-data-grid-premium@v5.17.2`
|
|
59
|
+
|
|
60
|
+
#### Changes
|
|
61
|
+
|
|
62
|
+
- [DataGrid] Revert mode if cell/row couldn't be saved due to validation error (#5897) @m4theushw
|
|
63
|
+
- [DataGridPremium] Export column grouping in Excel (#5895) @alexfauquette
|
|
64
|
+
|
|
65
|
+
### `@mui/x-date-pickers@v5.0.1` / `@mui/x-date-pickers-pro@v5.0.1`
|
|
66
|
+
|
|
67
|
+
#### Changes
|
|
68
|
+
|
|
69
|
+
- [DateTimePicker] Remove circular import (#6087) @flaviendelangle
|
|
70
|
+
- [pickers] Add `sx` prop to the equality check of `PickersDay` (#6030) @TheUnlocked
|
|
71
|
+
- [pickers] Add warning when `openTo` is invalid based on available `views` (#6042) @LukasTy
|
|
72
|
+
- [pickers] Allow keyboard navigation to ignore disabled date for left / right arrow (#6082) @alexfauquette
|
|
73
|
+
- [pickers] Fix mobile picker not opening on label click (#6074) @LukasTy
|
|
74
|
+
|
|
75
|
+
### Docs
|
|
76
|
+
|
|
77
|
+
- [docs] Add Recipes section
|
|
78
|
+
|
|
79
|
+
### Core
|
|
80
|
+
|
|
81
|
+
- [core] Add `yarn release:tag` script (#5169) @DanailH
|
|
82
|
+
- [core] Upgrade monorepo (#6072) @m4theushw
|
|
83
|
+
|
|
6
84
|
## 5.17.1
|
|
7
85
|
|
|
8
86
|
_Sep 5, 2022_
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GridFilterOperator } from '../models/gridFilterOperator';
|
|
2
2
|
import { GridCellParams } from '../models';
|
|
3
|
-
export declare const getGridNumericQuickFilterFn: (value: any) => (({ value
|
|
3
|
+
export declare const getGridNumericQuickFilterFn: (value: any) => (({ value }: GridCellParams) => boolean) | null;
|
|
4
4
|
export declare const getGridNumericOperators: () => GridFilterOperator<any, number | string | null, any>[];
|
|
5
5
|
/**
|
|
6
6
|
* @deprecated Use `getGridNumericOperators` instead.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GridFilterOperator } from '../models/gridFilterOperator';
|
|
2
2
|
import { GridCellParams, GridColDef } from '../models';
|
|
3
3
|
import { GridApiCommunity } from '../models/api/gridApiCommunity';
|
|
4
|
-
export declare const getGridSingleSelectQuickFilterFn: (value: any, column: GridColDef, apiRef: React.MutableRefObject<GridApiCommunity>) => (({ value
|
|
4
|
+
export declare const getGridSingleSelectQuickFilterFn: (value: any, column: GridColDef, apiRef: React.MutableRefObject<GridApiCommunity>) => (({ value }: GridCellParams) => boolean) | null;
|
|
5
5
|
export declare const getGridSingleSelectOperators: () => GridFilterOperator[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GridFilterOperator } from '../models/gridFilterOperator';
|
|
2
2
|
import { GridCellParams } from '../models';
|
|
3
|
-
export declare const getGridStringQuickFilterFn: (value: any) => (({ value
|
|
3
|
+
export declare const getGridStringQuickFilterFn: (value: any) => (({ value }: GridCellParams) => boolean) | null;
|
|
4
4
|
export declare const getGridStringOperators: (disableTrim?: boolean) => GridFilterOperator<any, number | string | null, any>[];
|
package/components/GridRow.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"]
|
|
3
|
+
const _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"],
|
|
4
|
+
_excluded2 = ["changeReason"];
|
|
4
5
|
import * as React from 'react';
|
|
5
6
|
import PropTypes from 'prop-types';
|
|
6
7
|
import clsx from 'clsx';
|
|
@@ -231,9 +232,11 @@ function GridRow(props) {
|
|
|
231
232
|
updatedRow = apiRef.current.unstable_getRowWithUpdatedValues(rowId, column.field);
|
|
232
233
|
}
|
|
233
234
|
|
|
235
|
+
const editCellStateRest = _objectWithoutPropertiesLoose(editCellState, _excluded2);
|
|
236
|
+
|
|
234
237
|
const params = _extends({}, cellParams, {
|
|
235
238
|
row: updatedRow
|
|
236
|
-
},
|
|
239
|
+
}, editCellStateRest, {
|
|
237
240
|
api: apiRef.current
|
|
238
241
|
});
|
|
239
242
|
|
|
@@ -95,6 +95,7 @@ process.env.NODE_ENV !== "production" ? GridEditBooleanCell.propTypes = {
|
|
|
95
95
|
* The mode of the cell.
|
|
96
96
|
*/
|
|
97
97
|
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
|
|
98
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
101
|
* The column of the row that the current cell belongs to.
|
|
@@ -149,6 +149,7 @@ process.env.NODE_ENV !== "production" ? GridEditDateCell.propTypes = {
|
|
|
149
149
|
* The mode of the cell.
|
|
150
150
|
*/
|
|
151
151
|
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
|
|
152
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
152
153
|
|
|
153
154
|
/**
|
|
154
155
|
* The column of the row that the current cell belongs to.
|
|
@@ -38,7 +38,7 @@ const GridEditInputCellRoot = styled(InputBase, {
|
|
|
38
38
|
}
|
|
39
39
|
}));
|
|
40
40
|
const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
41
|
-
var _rootProps$experiment;
|
|
41
|
+
var _rootProps$experiment, _rootProps$experiment3;
|
|
42
42
|
|
|
43
43
|
const rootProps = useGridRootProps();
|
|
44
44
|
|
|
@@ -62,23 +62,36 @@ const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
62
62
|
};
|
|
63
63
|
const classes = useUtilityClasses(ownerState);
|
|
64
64
|
const handleChange = React.useCallback(async event => {
|
|
65
|
+
var _rootProps$experiment2;
|
|
66
|
+
|
|
65
67
|
const newValue = event.target.value;
|
|
66
68
|
|
|
67
69
|
if (onValueChange) {
|
|
68
70
|
await onValueChange(event, newValue);
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
const column = apiRef.current.getColumn(field);
|
|
74
|
+
let parsedValue = newValue;
|
|
75
|
+
|
|
76
|
+
if (column.valueParser && (_rootProps$experiment2 = rootProps.experimentalFeatures) != null && _rootProps$experiment2.newEditingApi) {
|
|
77
|
+
parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setValueState(parsedValue);
|
|
72
81
|
apiRef.current.setEditCellValue({
|
|
73
82
|
id,
|
|
74
83
|
field,
|
|
75
|
-
value:
|
|
76
|
-
debounceMs
|
|
84
|
+
value: parsedValue,
|
|
85
|
+
debounceMs,
|
|
86
|
+
unstable_skipValueParser: true
|
|
77
87
|
}, event);
|
|
78
|
-
}, [apiRef, debounceMs, field, id, onValueChange]);
|
|
88
|
+
}, [apiRef, debounceMs, field, id, onValueChange, (_rootProps$experiment3 = rootProps.experimentalFeatures) == null ? void 0 : _rootProps$experiment3.newEditingApi]);
|
|
89
|
+
const meta = apiRef.current.unstable_getEditCellMeta ? apiRef.current.unstable_getEditCellMeta(id, field) : {};
|
|
79
90
|
React.useEffect(() => {
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
if (meta.changeReason !== 'debouncedSetEditCellValue') {
|
|
92
|
+
setValueState(value);
|
|
93
|
+
}
|
|
94
|
+
}, [meta.changeReason, value]);
|
|
82
95
|
useEnhancedEffect(() => {
|
|
83
96
|
if (hasFocus) {
|
|
84
97
|
inputRef.current.focus();
|
|
@@ -111,6 +124,7 @@ process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
|
|
|
111
124
|
* The mode of the cell.
|
|
112
125
|
*/
|
|
113
126
|
cellMode: PropTypes.oneOf(['edit', 'view']),
|
|
127
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
114
128
|
|
|
115
129
|
/**
|
|
116
130
|
* The column of the row that the current cell belongs to.
|
|
@@ -193,6 +193,7 @@ process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes = {
|
|
|
193
193
|
* The mode of the cell.
|
|
194
194
|
*/
|
|
195
195
|
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
|
|
196
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
196
197
|
|
|
197
198
|
/**
|
|
198
199
|
* The column of the row that the current cell belongs to.
|
|
@@ -11,6 +11,7 @@ import { gridEditRowsStateSelector } from './gridEditRowsSelector';
|
|
|
11
11
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
12
12
|
import { buildWarning } from '../../../utils/warning';
|
|
13
13
|
import { gridRowsIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
14
|
+
import { deepClone } from '../../../utils/utils';
|
|
14
15
|
import { GridCellEditStartReasons, GridCellEditStopReasons } from '../../../models/params/gridEditCellParams';
|
|
15
16
|
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, e.g. `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see http://mui.com/components/data-grid/editing/#persistence.'], 'error');
|
|
16
17
|
export const useGridCellEditing = (apiRef, props) => {
|
|
@@ -319,7 +320,11 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
319
320
|
if (error || isProcessingProps) {
|
|
320
321
|
// Attempt to change cell mode to "view" was not successful
|
|
321
322
|
// Update previous mode to allow another attempt
|
|
322
|
-
prevCellModesModel.current[id][field].mode = GridCellModes.Edit;
|
|
323
|
+
prevCellModesModel.current[id][field].mode = GridCellModes.Edit; // Revert the mode in the cellModesModel prop back to "edit"
|
|
324
|
+
|
|
325
|
+
updateFieldInCellModesModel(id, field, {
|
|
326
|
+
mode: GridCellModes.Edit
|
|
327
|
+
});
|
|
323
328
|
return;
|
|
324
329
|
}
|
|
325
330
|
|
|
@@ -356,7 +361,9 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
356
361
|
const {
|
|
357
362
|
id,
|
|
358
363
|
field,
|
|
359
|
-
value
|
|
364
|
+
value,
|
|
365
|
+
debounceMs,
|
|
366
|
+
unstable_skipValueParser: skipValueParser
|
|
360
367
|
} = params;
|
|
361
368
|
throwIfNotEditable(id, field);
|
|
362
369
|
throwIfNotInMode(id, field, GridCellModes.Edit);
|
|
@@ -364,14 +371,15 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
364
371
|
const row = apiRef.current.getRow(id);
|
|
365
372
|
let parsedValue = value;
|
|
366
373
|
|
|
367
|
-
if (column.valueParser) {
|
|
374
|
+
if (column.valueParser && !skipValueParser) {
|
|
368
375
|
parsedValue = column.valueParser(value, apiRef.current.getCellParams(id, field));
|
|
369
376
|
}
|
|
370
377
|
|
|
371
378
|
let editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
372
379
|
|
|
373
380
|
let newProps = _extends({}, editingState[id][field], {
|
|
374
|
-
value: parsedValue
|
|
381
|
+
value: parsedValue,
|
|
382
|
+
changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue'
|
|
375
383
|
});
|
|
376
384
|
|
|
377
385
|
if (column.preProcessEditCellProps) {
|
|
@@ -437,7 +445,8 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
437
445
|
const idToIdLookup = gridRowsIdToIdLookupSelector(apiRef); // Update the ref here because updateStateToStopCellEditMode may change it later
|
|
438
446
|
|
|
439
447
|
const copyOfPrevCellModes = prevCellModesModel.current;
|
|
440
|
-
prevCellModesModel.current = cellModesModel;
|
|
448
|
+
prevCellModesModel.current = deepClone(cellModesModel); // Do a deep-clone because the attributes might be changed later
|
|
449
|
+
|
|
441
450
|
Object.entries(cellModesModel).forEach(([id, fields]) => {
|
|
442
451
|
Object.entries(fields).forEach(([field, params]) => {
|
|
443
452
|
var _copyOfPrevCellModes$, _copyOfPrevCellModes$2, _idToIdLookup$id;
|
|
@@ -4,6 +4,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
4
4
|
import { useGridCellEditing } from './useGridCellEditing.new';
|
|
5
5
|
import { GridCellModes, GridEditModes } from '../../../models/gridEditRowModel';
|
|
6
6
|
import { useGridRowEditing } from './useGridRowEditing.new';
|
|
7
|
+
import { gridEditRowsStateSelector } from './gridEditRowsSelector';
|
|
7
8
|
export const editingStateInitializer = state => _extends({}, state, {
|
|
8
9
|
editRows: {}
|
|
9
10
|
});
|
|
@@ -116,11 +117,18 @@ export const useGridEditing = (apiRef, props) => {
|
|
|
116
117
|
const getRowWithUpdatedValues = React.useCallback((id, field) => {
|
|
117
118
|
return props.editMode === GridEditModes.Cell ? apiRef.current.unstable_getRowWithUpdatedValuesFromCellEditing(id, field) : apiRef.current.unstable_getRowWithUpdatedValuesFromRowEditing(id);
|
|
118
119
|
}, [apiRef, props.editMode]);
|
|
120
|
+
const getEditCellMeta = React.useCallback((id, field) => {
|
|
121
|
+
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
122
|
+
return {
|
|
123
|
+
changeReason: editingState[id][field].changeReason
|
|
124
|
+
};
|
|
125
|
+
}, [apiRef]);
|
|
119
126
|
const editingSharedApi = {
|
|
120
127
|
isCellEditable,
|
|
121
128
|
setEditCellValue,
|
|
122
129
|
unstable_runPendingEditCellValueMutation: runPendingEditCellValueMutation,
|
|
123
|
-
unstable_getRowWithUpdatedValues: getRowWithUpdatedValues
|
|
130
|
+
unstable_getRowWithUpdatedValues: getRowWithUpdatedValues,
|
|
131
|
+
unstable_getEditCellMeta: getEditCellMeta
|
|
124
132
|
};
|
|
125
133
|
useGridApiMethod(apiRef, editingSharedApi, 'EditingApi');
|
|
126
134
|
};
|
|
@@ -12,6 +12,7 @@ import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
|
12
12
|
import { gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
13
13
|
import { buildWarning } from '../../../utils/warning';
|
|
14
14
|
import { gridRowsIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
15
|
+
import { deepClone } from '../../../utils/utils';
|
|
15
16
|
import { GridRowEditStopReasons, GridRowEditStartReasons } from '../../../models/params/gridRowParams';
|
|
16
17
|
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, e.g. `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see http://mui.com/components/data-grid/editing/#persistence.'], 'error');
|
|
17
18
|
export const useGridRowEditing = (apiRef, props) => {
|
|
@@ -403,7 +404,11 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
403
404
|
const hasSomeFieldWithError = Object.values(editingState[id]).some(fieldProps => fieldProps.error);
|
|
404
405
|
|
|
405
406
|
if (hasSomeFieldWithError) {
|
|
406
|
-
prevRowModesModel.current[id].mode = GridRowModes.Edit;
|
|
407
|
+
prevRowModesModel.current[id].mode = GridRowModes.Edit; // Revert the mode in the rowModesModel prop back to "edit"
|
|
408
|
+
|
|
409
|
+
updateRowInRowModesModel(id, {
|
|
410
|
+
mode: GridRowModes.Edit
|
|
411
|
+
});
|
|
407
412
|
return;
|
|
408
413
|
}
|
|
409
414
|
|
|
@@ -437,21 +442,24 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
437
442
|
const {
|
|
438
443
|
id,
|
|
439
444
|
field,
|
|
440
|
-
value
|
|
445
|
+
value,
|
|
446
|
+
debounceMs,
|
|
447
|
+
unstable_skipValueParser: skipValueParser
|
|
441
448
|
} = params;
|
|
442
449
|
throwIfNotEditable(id, field);
|
|
443
450
|
const column = apiRef.current.getColumn(field);
|
|
444
451
|
const row = apiRef.current.getRow(id);
|
|
445
452
|
let parsedValue = value;
|
|
446
453
|
|
|
447
|
-
if (column.valueParser) {
|
|
454
|
+
if (column.valueParser && !skipValueParser) {
|
|
448
455
|
parsedValue = column.valueParser(value, apiRef.current.getCellParams(id, field));
|
|
449
456
|
}
|
|
450
457
|
|
|
451
458
|
let editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
452
459
|
|
|
453
460
|
let newProps = _extends({}, editingState[id][field], {
|
|
454
|
-
value: parsedValue
|
|
461
|
+
value: parsedValue,
|
|
462
|
+
changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue'
|
|
455
463
|
});
|
|
456
464
|
|
|
457
465
|
if (!column.preProcessEditCellProps) {
|
|
@@ -586,7 +594,8 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
586
594
|
const idToIdLookup = gridRowsIdToIdLookupSelector(apiRef); // Update the ref here because updateStateToStopRowEditMode may change it later
|
|
587
595
|
|
|
588
596
|
const copyOfPrevRowModesModel = prevRowModesModel.current;
|
|
589
|
-
prevRowModesModel.current = rowModesModel;
|
|
597
|
+
prevRowModesModel.current = deepClone(rowModesModel); // Do a deep-clone because the attributes might be changed later
|
|
598
|
+
|
|
590
599
|
Object.entries(rowModesModel).forEach(([id, params]) => {
|
|
591
600
|
var _copyOfPrevRowModesMo, _idToIdLookup$id;
|
|
592
601
|
|
|
@@ -6,5 +6,5 @@ declare type DeepPartial<T> = {
|
|
|
6
6
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
7
7
|
};
|
|
8
8
|
export declare type GridStateInitializer<P extends Partial<DataGridProcessedProps> = DataGridProcessedProps, Api extends GridApiCommon = GridApiCommunity> = (state: DeepPartial<Api['state']>, props: P, apiRef: React.MutableRefObject<Api>) => DeepPartial<Api['state']>;
|
|
9
|
-
export declare const useGridInitializeState: <P
|
|
9
|
+
export declare const useGridInitializeState: <P extends Partial<DataGridProcessedProps<any>>, Api extends GridApiCommon = GridApiCommunity>(initializer: GridStateInitializer<P, Api>, apiRef: React.MutableRefObject<Api>, props: P) => void;
|
|
10
10
|
export {};
|
package/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"]
|
|
5
|
+
var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"],
|
|
6
|
+
_excluded2 = ["changeReason"];
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import PropTypes from 'prop-types';
|
|
8
9
|
import clsx from 'clsx';
|
|
@@ -237,9 +238,12 @@ function GridRow(props) {
|
|
|
237
238
|
updatedRow = apiRef.current.unstable_getRowWithUpdatedValues(rowId, column.field);
|
|
238
239
|
}
|
|
239
240
|
|
|
241
|
+
var changeReason = editCellState.changeReason,
|
|
242
|
+
editCellStateRest = _objectWithoutProperties(editCellState, _excluded2);
|
|
243
|
+
|
|
240
244
|
var params = _extends({}, cellParams, {
|
|
241
245
|
row: updatedRow
|
|
242
|
-
},
|
|
246
|
+
}, editCellStateRest, {
|
|
243
247
|
api: apiRef.current
|
|
244
248
|
});
|
|
245
249
|
|
|
@@ -135,6 +135,7 @@ process.env.NODE_ENV !== "production" ? GridEditBooleanCell.propTypes = {
|
|
|
135
135
|
* The mode of the cell.
|
|
136
136
|
*/
|
|
137
137
|
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
|
|
138
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
138
139
|
|
|
139
140
|
/**
|
|
140
141
|
* The column of the row that the current cell belongs to.
|
|
@@ -186,6 +186,7 @@ process.env.NODE_ENV !== "production" ? GridEditDateCell.propTypes = {
|
|
|
186
186
|
* The mode of the cell.
|
|
187
187
|
*/
|
|
188
188
|
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
|
|
189
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
189
190
|
|
|
190
191
|
/**
|
|
191
192
|
* The column of the row that the current cell belongs to.
|
|
@@ -42,7 +42,7 @@ var GridEditInputCellRoot = styled(InputBase, {
|
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
44
|
var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
45
|
-
var _rootProps$experiment;
|
|
45
|
+
var _rootProps$experiment, _rootProps$experiment3;
|
|
46
46
|
|
|
47
47
|
var rootProps = useGridRootProps();
|
|
48
48
|
|
|
@@ -80,7 +80,9 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
80
80
|
var classes = useUtilityClasses(ownerState);
|
|
81
81
|
var handleChange = React.useCallback( /*#__PURE__*/function () {
|
|
82
82
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
|
|
83
|
-
var
|
|
83
|
+
var _rootProps$experiment2;
|
|
84
|
+
|
|
85
|
+
var newValue, column, parsedValue;
|
|
84
86
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
85
87
|
while (1) {
|
|
86
88
|
switch (_context.prev = _context.next) {
|
|
@@ -96,15 +98,23 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
96
98
|
return onValueChange(event, newValue);
|
|
97
99
|
|
|
98
100
|
case 4:
|
|
99
|
-
|
|
101
|
+
column = apiRef.current.getColumn(field);
|
|
102
|
+
parsedValue = newValue;
|
|
103
|
+
|
|
104
|
+
if (column.valueParser && (_rootProps$experiment2 = rootProps.experimentalFeatures) != null && _rootProps$experiment2.newEditingApi) {
|
|
105
|
+
parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setValueState(parsedValue);
|
|
100
109
|
apiRef.current.setEditCellValue({
|
|
101
110
|
id: id,
|
|
102
111
|
field: field,
|
|
103
|
-
value:
|
|
104
|
-
debounceMs: debounceMs
|
|
112
|
+
value: parsedValue,
|
|
113
|
+
debounceMs: debounceMs,
|
|
114
|
+
unstable_skipValueParser: true
|
|
105
115
|
}, event);
|
|
106
116
|
|
|
107
|
-
case
|
|
117
|
+
case 9:
|
|
108
118
|
case "end":
|
|
109
119
|
return _context.stop();
|
|
110
120
|
}
|
|
@@ -115,10 +125,13 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
115
125
|
return function (_x) {
|
|
116
126
|
return _ref2.apply(this, arguments);
|
|
117
127
|
};
|
|
118
|
-
}(), [apiRef, debounceMs, field, id, onValueChange]);
|
|
128
|
+
}(), [apiRef, debounceMs, field, id, onValueChange, (_rootProps$experiment3 = rootProps.experimentalFeatures) == null ? void 0 : _rootProps$experiment3.newEditingApi]);
|
|
129
|
+
var meta = apiRef.current.unstable_getEditCellMeta ? apiRef.current.unstable_getEditCellMeta(id, field) : {};
|
|
119
130
|
React.useEffect(function () {
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
if (meta.changeReason !== 'debouncedSetEditCellValue') {
|
|
132
|
+
setValueState(value);
|
|
133
|
+
}
|
|
134
|
+
}, [meta.changeReason, value]);
|
|
122
135
|
useEnhancedEffect(function () {
|
|
123
136
|
if (hasFocus) {
|
|
124
137
|
inputRef.current.focus();
|
|
@@ -151,6 +164,7 @@ process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
|
|
|
151
164
|
* The mode of the cell.
|
|
152
165
|
*/
|
|
153
166
|
cellMode: PropTypes.oneOf(['edit', 'view']),
|
|
167
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
154
168
|
|
|
155
169
|
/**
|
|
156
170
|
* The column of the row that the current cell belongs to.
|
|
@@ -250,6 +250,7 @@ process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes = {
|
|
|
250
250
|
* The mode of the cell.
|
|
251
251
|
*/
|
|
252
252
|
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
|
|
253
|
+
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
253
254
|
|
|
254
255
|
/**
|
|
255
256
|
* The column of the row that the current cell belongs to.
|
|
@@ -15,6 +15,7 @@ import { gridEditRowsStateSelector } from './gridEditRowsSelector';
|
|
|
15
15
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
16
16
|
import { buildWarning } from '../../../utils/warning';
|
|
17
17
|
import { gridRowsIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
18
|
+
import { deepClone } from '../../../utils/utils';
|
|
18
19
|
import { GridCellEditStartReasons, GridCellEditStopReasons } from '../../../models/params/gridEditCellParams';
|
|
19
20
|
var missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, e.g. `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see http://mui.com/components/data-grid/editing/#persistence.'], 'error');
|
|
20
21
|
export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
@@ -315,16 +316,20 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
315
316
|
_editingState$id$fiel = editingState[id][field], error = _editingState$id$fiel.error, isProcessingProps = _editingState$id$fiel.isProcessingProps;
|
|
316
317
|
|
|
317
318
|
if (!(error || isProcessingProps)) {
|
|
318
|
-
_context.next =
|
|
319
|
+
_context.next = 13;
|
|
319
320
|
break;
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
// Attempt to change cell mode to "view" was not successful
|
|
323
324
|
// Update previous mode to allow another attempt
|
|
324
|
-
prevCellModesModel.current[id][field].mode = GridCellModes.Edit;
|
|
325
|
+
prevCellModesModel.current[id][field].mode = GridCellModes.Edit; // Revert the mode in the cellModesModel prop back to "edit"
|
|
326
|
+
|
|
327
|
+
updateFieldInCellModesModel(id, field, {
|
|
328
|
+
mode: GridCellModes.Edit
|
|
329
|
+
});
|
|
325
330
|
return _context.abrupt("return");
|
|
326
331
|
|
|
327
|
-
case
|
|
332
|
+
case 13:
|
|
328
333
|
rowUpdate = apiRef.current.unstable_getRowWithUpdatedValuesFromCellEditing(id, field);
|
|
329
334
|
|
|
330
335
|
if (processRowUpdate) {
|
|
@@ -352,7 +357,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
352
357
|
finishCellEditMode();
|
|
353
358
|
}
|
|
354
359
|
|
|
355
|
-
case
|
|
360
|
+
case 15:
|
|
356
361
|
case "end":
|
|
357
362
|
return _context.stop();
|
|
358
363
|
}
|
|
@@ -368,25 +373,26 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
368
373
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
|
|
369
374
|
var _editingState$id, _editingState$id$fiel2;
|
|
370
375
|
|
|
371
|
-
var id, field, value, column, row, parsedValue, editingState, newProps, hasChanged;
|
|
376
|
+
var id, field, value, debounceMs, skipValueParser, column, row, parsedValue, editingState, newProps, hasChanged;
|
|
372
377
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
373
378
|
while (1) {
|
|
374
379
|
switch (_context2.prev = _context2.next) {
|
|
375
380
|
case 0:
|
|
376
|
-
id = params.id, field = params.field, value = params.value;
|
|
381
|
+
id = params.id, field = params.field, value = params.value, debounceMs = params.debounceMs, skipValueParser = params.unstable_skipValueParser;
|
|
377
382
|
throwIfNotEditable(id, field);
|
|
378
383
|
throwIfNotInMode(id, field, GridCellModes.Edit);
|
|
379
384
|
column = apiRef.current.getColumn(field);
|
|
380
385
|
row = apiRef.current.getRow(id);
|
|
381
386
|
parsedValue = value;
|
|
382
387
|
|
|
383
|
-
if (column.valueParser) {
|
|
388
|
+
if (column.valueParser && !skipValueParser) {
|
|
384
389
|
parsedValue = column.valueParser(value, apiRef.current.getCellParams(id, field));
|
|
385
390
|
}
|
|
386
391
|
|
|
387
392
|
editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
388
393
|
newProps = _extends({}, editingState[id][field], {
|
|
389
|
-
value: parsedValue
|
|
394
|
+
value: parsedValue,
|
|
395
|
+
changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue'
|
|
390
396
|
});
|
|
391
397
|
|
|
392
398
|
if (!column.preProcessEditCellProps) {
|
|
@@ -470,7 +476,8 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
470
476
|
var idToIdLookup = gridRowsIdToIdLookupSelector(apiRef); // Update the ref here because updateStateToStopCellEditMode may change it later
|
|
471
477
|
|
|
472
478
|
var copyOfPrevCellModes = prevCellModesModel.current;
|
|
473
|
-
prevCellModesModel.current = cellModesModel;
|
|
479
|
+
prevCellModesModel.current = deepClone(cellModesModel); // Do a deep-clone because the attributes might be changed later
|
|
480
|
+
|
|
474
481
|
Object.entries(cellModesModel).forEach(function (_ref3) {
|
|
475
482
|
var _ref4 = _slicedToArray(_ref3, 2),
|
|
476
483
|
id = _ref4[0],
|
|
@@ -7,6 +7,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
7
7
|
import { useGridCellEditing } from './useGridCellEditing.new';
|
|
8
8
|
import { GridCellModes, GridEditModes } from '../../../models/gridEditRowModel';
|
|
9
9
|
import { useGridRowEditing } from './useGridRowEditing.new';
|
|
10
|
+
import { gridEditRowsStateSelector } from './gridEditRowsSelector';
|
|
10
11
|
export var editingStateInitializer = function editingStateInitializer(state) {
|
|
11
12
|
return _extends({}, state, {
|
|
12
13
|
editRows: {}
|
|
@@ -150,11 +151,18 @@ export var useGridEditing = function useGridEditing(apiRef, props) {
|
|
|
150
151
|
var getRowWithUpdatedValues = React.useCallback(function (id, field) {
|
|
151
152
|
return props.editMode === GridEditModes.Cell ? apiRef.current.unstable_getRowWithUpdatedValuesFromCellEditing(id, field) : apiRef.current.unstable_getRowWithUpdatedValuesFromRowEditing(id);
|
|
152
153
|
}, [apiRef, props.editMode]);
|
|
154
|
+
var getEditCellMeta = React.useCallback(function (id, field) {
|
|
155
|
+
var editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
156
|
+
return {
|
|
157
|
+
changeReason: editingState[id][field].changeReason
|
|
158
|
+
};
|
|
159
|
+
}, [apiRef]);
|
|
153
160
|
var editingSharedApi = {
|
|
154
161
|
isCellEditable: isCellEditable,
|
|
155
162
|
setEditCellValue: setEditCellValue,
|
|
156
163
|
unstable_runPendingEditCellValueMutation: runPendingEditCellValueMutation,
|
|
157
|
-
unstable_getRowWithUpdatedValues: getRowWithUpdatedValues
|
|
164
|
+
unstable_getRowWithUpdatedValues: getRowWithUpdatedValues,
|
|
165
|
+
unstable_getEditCellMeta: getEditCellMeta
|
|
158
166
|
};
|
|
159
167
|
useGridApiMethod(apiRef, editingSharedApi, 'EditingApi');
|
|
160
168
|
};
|