@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["linkOperators", "columnsSort", "filterFormProps", "children"];
|
|
3
|
+
const _excluded = ["linkOperators", "columnsSort", "filterFormProps", "getColumnForNewFilter", "children"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { GridLinkOperator } from '../../../models/gridFilterItem';
|
|
@@ -16,6 +16,13 @@ import { gridFilterModelSelector } from '../../../hooks/features/filter/gridFilt
|
|
|
16
16
|
import { gridFilterableColumnDefinitionsSelector } from '../../../hooks/features/columns/gridColumnsSelector';
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
|
|
20
|
+
const getGridFilter = col => ({
|
|
21
|
+
columnField: col.field,
|
|
22
|
+
operatorValue: col.filterOperators[0].value,
|
|
23
|
+
id: Math.round(Math.random() * 1e5)
|
|
24
|
+
});
|
|
25
|
+
|
|
19
26
|
const GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(props, ref) {
|
|
20
27
|
const apiRef = useGridApiContext();
|
|
21
28
|
const rootProps = useGridRootProps();
|
|
@@ -26,7 +33,8 @@ const GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(p
|
|
|
26
33
|
const {
|
|
27
34
|
linkOperators = [GridLinkOperator.And, GridLinkOperator.Or],
|
|
28
35
|
columnsSort,
|
|
29
|
-
filterFormProps
|
|
36
|
+
filterFormProps,
|
|
37
|
+
getColumnForNewFilter
|
|
30
38
|
} = props,
|
|
31
39
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
32
40
|
|
|
@@ -36,37 +44,67 @@ const GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(p
|
|
|
36
44
|
const applyFilterLinkOperator = React.useCallback(operator => {
|
|
37
45
|
apiRef.current.setFilterLinkOperator(operator);
|
|
38
46
|
}, [apiRef]);
|
|
39
|
-
const
|
|
40
|
-
|
|
47
|
+
const getDefaultFilter = React.useCallback(() => {
|
|
48
|
+
let nextColumnWithOperator;
|
|
49
|
+
|
|
50
|
+
if (getColumnForNewFilter && typeof getColumnForNewFilter === 'function') {
|
|
51
|
+
// To allow override the column for default (first) filter
|
|
52
|
+
const nextColumnFieldName = getColumnForNewFilter({
|
|
53
|
+
currentFilters: filterModel?.items || [],
|
|
54
|
+
columns: filterableColumns
|
|
55
|
+
});
|
|
56
|
+
nextColumnWithOperator = filterableColumns.find(({
|
|
57
|
+
field
|
|
58
|
+
}) => field === nextColumnFieldName);
|
|
59
|
+
} else {
|
|
60
|
+
nextColumnWithOperator = filterableColumns.find(colDef => colDef.filterOperators?.length);
|
|
61
|
+
}
|
|
41
62
|
|
|
42
|
-
if (!
|
|
63
|
+
if (!nextColumnWithOperator) {
|
|
43
64
|
return null;
|
|
44
65
|
}
|
|
45
66
|
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
return getGridFilter(nextColumnWithOperator);
|
|
68
|
+
}, [filterModel?.items, filterableColumns, getColumnForNewFilter]);
|
|
69
|
+
const getNewFilter = React.useCallback(() => {
|
|
70
|
+
if (getColumnForNewFilter === undefined || typeof getColumnForNewFilter !== 'function') {
|
|
71
|
+
return getDefaultFilter();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const currentFilters = filterModel.items.length ? filterModel.items : [getDefaultFilter()].filter(Boolean); // If no items are there in filterModel, we have to pass defaultFilter
|
|
75
|
+
|
|
76
|
+
const nextColumnFieldName = getColumnForNewFilter({
|
|
77
|
+
currentFilters: currentFilters,
|
|
78
|
+
columns: filterableColumns
|
|
79
|
+
});
|
|
80
|
+
const nextColumnWithOperator = filterableColumns.find(({
|
|
81
|
+
field
|
|
82
|
+
}) => field === nextColumnFieldName);
|
|
83
|
+
|
|
84
|
+
if (!nextColumnWithOperator) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return getGridFilter(nextColumnWithOperator);
|
|
89
|
+
}, [filterModel.items, filterableColumns, getColumnForNewFilter, getDefaultFilter]);
|
|
52
90
|
const items = React.useMemo(() => {
|
|
53
91
|
if (filterModel.items.length) {
|
|
54
92
|
return filterModel.items;
|
|
55
93
|
}
|
|
56
94
|
|
|
57
|
-
const
|
|
58
|
-
return
|
|
59
|
-
}, [filterModel.items,
|
|
95
|
+
const defaultFilter = getDefaultFilter();
|
|
96
|
+
return defaultFilter ? [defaultFilter] : [];
|
|
97
|
+
}, [filterModel.items, getDefaultFilter]);
|
|
60
98
|
const hasMultipleFilters = items.length > 1;
|
|
61
99
|
|
|
62
100
|
const addNewFilter = () => {
|
|
63
|
-
const
|
|
101
|
+
const newFilter = getNewFilter();
|
|
64
102
|
|
|
65
|
-
if (!
|
|
103
|
+
if (!newFilter) {
|
|
66
104
|
return;
|
|
67
105
|
}
|
|
68
106
|
|
|
69
|
-
apiRef.current.upsertFilterItems([...items,
|
|
107
|
+
apiRef.current.upsertFilterItems([...items, newFilter]);
|
|
70
108
|
};
|
|
71
109
|
|
|
72
110
|
const deleteFilter = React.useCallback(item => {
|
|
@@ -143,6 +181,13 @@ process.env.NODE_ENV !== "production" ? GridFilterPanel.propTypes = {
|
|
|
143
181
|
valueInputProps: PropTypes.any
|
|
144
182
|
}),
|
|
145
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Function that returns the next filter item to be picked as default filter.
|
|
186
|
+
* @param {GetColumnForNewFilterArgs} args Currently configured filters and columns.
|
|
187
|
+
* @returns {GridColDef['field']} The field to be used for the next filter.
|
|
188
|
+
*/
|
|
189
|
+
getColumnForNewFilter: PropTypes.func,
|
|
190
|
+
|
|
146
191
|
/**
|
|
147
192
|
* Sets the available logic operators.
|
|
148
193
|
* @default [GridLinkOperator.And, GridLinkOperator.Or]
|
package/modern/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js}
RENAMED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './gridEditingSelectors';
|
package/modern/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js}
RENAMED
|
@@ -8,7 +8,7 @@ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
|
8
8
|
import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
|
|
9
9
|
import { GridEditModes, GridCellModes } from '../../../models/gridEditRowModel';
|
|
10
10
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
11
|
-
import { gridEditRowsStateSelector } from './
|
|
11
|
+
import { gridEditRowsStateSelector } from './gridEditingSelectors';
|
|
12
12
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
13
13
|
import { buildWarning } from '../../../utils/warning';
|
|
14
14
|
import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
@@ -121,7 +121,8 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
121
121
|
|
|
122
122
|
if (reason) {
|
|
123
123
|
const newParams = _extends({}, params, {
|
|
124
|
-
reason
|
|
124
|
+
reason,
|
|
125
|
+
key: event.key
|
|
125
126
|
});
|
|
126
127
|
|
|
127
128
|
apiRef.current.publishEvent('cellEditStart', newParams, event);
|
|
@@ -132,14 +133,21 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
132
133
|
const {
|
|
133
134
|
id,
|
|
134
135
|
field,
|
|
135
|
-
reason
|
|
136
|
+
reason,
|
|
137
|
+
key
|
|
136
138
|
} = params;
|
|
137
139
|
const startCellEditModeParams = {
|
|
138
140
|
id,
|
|
139
141
|
field
|
|
140
142
|
};
|
|
141
143
|
|
|
142
|
-
if (reason === GridCellEditStartReasons.
|
|
144
|
+
if (reason === GridCellEditStartReasons.printableKeyDown) {
|
|
145
|
+
if (React.version.startsWith('18')) {
|
|
146
|
+
startCellEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
|
|
147
|
+
} else {
|
|
148
|
+
startCellEditModeParams.deleteValue = true;
|
|
149
|
+
}
|
|
150
|
+
} else if (reason === GridCellEditStartReasons.deleteKeyDown) {
|
|
143
151
|
startCellEditModeParams.deleteValue = true;
|
|
144
152
|
}
|
|
145
153
|
|
|
@@ -270,10 +278,17 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
270
278
|
const {
|
|
271
279
|
id,
|
|
272
280
|
field,
|
|
273
|
-
deleteValue
|
|
281
|
+
deleteValue,
|
|
282
|
+
initialValue
|
|
274
283
|
} = params;
|
|
284
|
+
let newValue = apiRef.current.getCellValue(id, field);
|
|
285
|
+
|
|
286
|
+
if (deleteValue || initialValue) {
|
|
287
|
+
newValue = deleteValue ? '' : initialValue;
|
|
288
|
+
}
|
|
289
|
+
|
|
275
290
|
const newProps = {
|
|
276
|
-
value:
|
|
291
|
+
value: newValue,
|
|
277
292
|
error: false,
|
|
278
293
|
isProcessingProps: false
|
|
279
294
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
|
-
import { useGridCellEditing } from './useGridCellEditing
|
|
4
|
+
import { useGridCellEditing } from './useGridCellEditing';
|
|
5
5
|
import { GridCellModes, GridEditModes } from '../../../models/gridEditRowModel';
|
|
6
|
-
import { useGridRowEditing } from './useGridRowEditing
|
|
7
|
-
import { gridEditRowsStateSelector } from './
|
|
6
|
+
import { useGridRowEditing } from './useGridRowEditing';
|
|
7
|
+
import { gridEditRowsStateSelector } from './gridEditingSelectors';
|
|
8
8
|
import { isAutoGeneratedRow } from '../rows/gridRowsUtils';
|
|
9
9
|
export const editingStateInitializer = state => _extends({}, state, {
|
|
10
10
|
editRows: {}
|
package/modern/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js}
RENAMED
|
@@ -8,7 +8,7 @@ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
|
8
8
|
import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
|
|
9
9
|
import { GridEditModes, GridRowModes } from '../../../models/gridEditRowModel';
|
|
10
10
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
11
|
-
import { gridEditRowsStateSelector } from './
|
|
11
|
+
import { gridEditRowsStateSelector } from './gridEditingSelectors';
|
|
12
12
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
13
13
|
import { gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
14
14
|
import { buildWarning } from '../../../utils/warning';
|
|
@@ -179,6 +179,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
179
179
|
|
|
180
180
|
const newParams = _extends({}, rowParams, {
|
|
181
181
|
field: params.field,
|
|
182
|
+
key: event.key,
|
|
182
183
|
reason
|
|
183
184
|
});
|
|
184
185
|
|
|
@@ -190,14 +191,21 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
190
191
|
const {
|
|
191
192
|
id,
|
|
192
193
|
field,
|
|
193
|
-
reason
|
|
194
|
+
reason,
|
|
195
|
+
key
|
|
194
196
|
} = params;
|
|
195
197
|
const startRowEditModeParams = {
|
|
196
198
|
id,
|
|
197
199
|
fieldToFocus: field
|
|
198
200
|
};
|
|
199
201
|
|
|
200
|
-
if (reason === GridRowEditStartReasons.
|
|
202
|
+
if (reason === GridRowEditStartReasons.printableKeyDown) {
|
|
203
|
+
if (React.version.startsWith('18')) {
|
|
204
|
+
startRowEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
|
|
205
|
+
} else {
|
|
206
|
+
startRowEditModeParams.deleteValue = !!field;
|
|
207
|
+
}
|
|
208
|
+
} else if (reason === GridRowEditStartReasons.deleteKeyDown) {
|
|
201
209
|
startRowEditModeParams.deleteValue = !!field;
|
|
202
210
|
}
|
|
203
211
|
|
|
@@ -337,7 +345,8 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
337
345
|
const {
|
|
338
346
|
id,
|
|
339
347
|
fieldToFocus,
|
|
340
|
-
deleteValue
|
|
348
|
+
deleteValue,
|
|
349
|
+
initialValue
|
|
341
350
|
} = params;
|
|
342
351
|
const columnFields = gridColumnFieldsSelector(apiRef);
|
|
343
352
|
const newProps = columnFields.reduce((acc, field) => {
|
|
@@ -347,9 +356,14 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
347
356
|
return acc;
|
|
348
357
|
}
|
|
349
358
|
|
|
350
|
-
|
|
359
|
+
let 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';
|
|
@@ -9,7 +9,7 @@ import { useGridRootProps } from '../../utils/useGridRootProps';
|
|
|
9
9
|
import { useGridSelector } from '../../utils/useGridSelector';
|
|
10
10
|
import { gridVisibleColumnDefinitionsSelector, gridColumnsTotalWidthSelector, gridColumnPositionsSelector } from '../columns/gridColumnsSelector';
|
|
11
11
|
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
|
|
12
|
-
import { gridEditRowsStateSelector } from '../
|
|
12
|
+
import { gridEditRowsStateSelector } from '../editing/gridEditingSelectors';
|
|
13
13
|
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
14
14
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
15
15
|
import { clamp } from '../../../utils/utils';
|
package/modern/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';
|
|
@@ -219,8 +219,6 @@ DataGridRaw.propTypes = {
|
|
|
219
219
|
*/
|
|
220
220
|
experimentalFeatures: _propTypes.default.shape({
|
|
221
221
|
columnGrouping: _propTypes.default.bool,
|
|
222
|
-
newEditingApi: _propTypes.default.bool,
|
|
223
|
-
preventCommitWhileValidating: _propTypes.default.bool,
|
|
224
222
|
warnIfFocusStateIsNotSynced: _propTypes.default.bool
|
|
225
223
|
}),
|
|
226
224
|
|
|
@@ -397,14 +395,6 @@ DataGridRaw.propTypes = {
|
|
|
397
395
|
*/
|
|
398
396
|
onCellDoubleClick: _propTypes.default.func,
|
|
399
397
|
|
|
400
|
-
/**
|
|
401
|
-
* Callback fired when the cell changes are committed.
|
|
402
|
-
* @param {GridCellEditCommitParams} params With all properties from [[GridCellEditCommitParams]].
|
|
403
|
-
* @param {MuiEvent<MuiBaseEvent>} event The event that caused this prop to be called.
|
|
404
|
-
* @param {GridCallbackDetails} details Additional details for this callback.
|
|
405
|
-
*/
|
|
406
|
-
onCellEditCommit: _propTypes.default.func,
|
|
407
|
-
|
|
408
398
|
/**
|
|
409
399
|
* Callback fired when the cell turns to edit mode.
|
|
410
400
|
* @param {GridCellParams} params With all properties from [[GridCellParams]].
|
|
@@ -505,15 +495,6 @@ DataGridRaw.propTypes = {
|
|
|
505
495
|
*/
|
|
506
496
|
onColumnVisibilityModelChange: _propTypes.default.func,
|
|
507
497
|
|
|
508
|
-
/**
|
|
509
|
-
* Callback fired when the edit cell value changes.
|
|
510
|
-
* @param {GridEditCellPropsParams} params With all properties from [[GridEditCellPropsParams]].
|
|
511
|
-
* @param {MuiEvent<React.SyntheticEvent>} event The event that caused this prop to be called.
|
|
512
|
-
* @param {GridCallbackDetails} details Additional details for this callback.
|
|
513
|
-
* @deprecated use `preProcessEditCellProps` from the [`GridColDef`](/x/api/data-grid/grid-col-def/)
|
|
514
|
-
*/
|
|
515
|
-
onEditCellPropsChange: _propTypes.default.func,
|
|
516
|
-
|
|
517
498
|
/**
|
|
518
499
|
* Callback fired when the `editRowsModel` changes.
|
|
519
500
|
* @param {GridEditRowsModel} editRowsModel With all properties from [[GridEditRowsModel]].
|
|
@@ -700,7 +681,6 @@ DataGridRaw.propTypes = {
|
|
|
700
681
|
|
|
701
682
|
/**
|
|
702
683
|
* Callback called before updating a row with new values in the row and cell editing.
|
|
703
|
-
* Only applied if `props.experimentalFeatures.newEditingApi: true`.
|
|
704
684
|
* @template R
|
|
705
685
|
* @param {R} newRow Row object with the new values.
|
|
706
686
|
* @param {R} oldRow Row object with the old values.
|
|
@@ -31,9 +31,7 @@ var _useGridPagination = require("../hooks/features/pagination/useGridPagination
|
|
|
31
31
|
|
|
32
32
|
var _useGridPreferencesPanel = require("../hooks/features/preferencesPanel/useGridPreferencesPanel");
|
|
33
33
|
|
|
34
|
-
var _useGridEditing = require("../hooks/features/
|
|
35
|
-
|
|
36
|
-
var _useGridEditing2 = require("../hooks/features/editRows/useGridEditing.new");
|
|
34
|
+
var _useGridEditing = require("../hooks/features/editing/useGridEditing");
|
|
37
35
|
|
|
38
36
|
var _useGridRows = require("../hooks/features/rows/useGridRows");
|
|
39
37
|
|
|
@@ -64,8 +62,6 @@ var _useGridColumnGrouping = require("../hooks/features/columnGrouping/useGridCo
|
|
|
64
62
|
var _useGridColumnGroupingPreProcessors = require("../hooks/features/columnGrouping/useGridColumnGroupingPreProcessors");
|
|
65
63
|
|
|
66
64
|
const useDataGridComponent = props => {
|
|
67
|
-
var _props$experimentalFe, _props$experimentalFe2;
|
|
68
|
-
|
|
69
65
|
const apiRef = (0, _useGridInitialization.useGridInitialization)(undefined, props);
|
|
70
66
|
/**
|
|
71
67
|
* Register all pre-processors called during state initialization here.
|
|
@@ -82,7 +78,7 @@ const useDataGridComponent = props => {
|
|
|
82
78
|
(0, _useGridInitializeState.useGridInitializeState)(_useGridColumns.columnsStateInitializer, apiRef, props);
|
|
83
79
|
(0, _useGridInitializeState.useGridInitializeState)(_useGridColumnGrouping.columnGroupsStateInitializer, apiRef, props);
|
|
84
80
|
(0, _useGridInitializeState.useGridInitializeState)(_useGridRows.rowsStateInitializer, apiRef, props);
|
|
85
|
-
(0, _useGridInitializeState.useGridInitializeState)(
|
|
81
|
+
(0, _useGridInitializeState.useGridInitializeState)(_useGridEditing.editingStateInitializer, apiRef, props);
|
|
86
82
|
(0, _useGridInitializeState.useGridInitializeState)(_useGridFocus.focusStateInitializer, apiRef, props);
|
|
87
83
|
(0, _useGridInitializeState.useGridInitializeState)(_useGridSorting.sortingStateInitializer, apiRef, props);
|
|
88
84
|
(0, _useGridInitializeState.useGridInitializeState)(_useGridPreferencesPanel.preferencePanelStateInitializer, apiRef, props);
|
|
@@ -98,8 +94,7 @@ const useDataGridComponent = props => {
|
|
|
98
94
|
(0, _useGridParamsApi.useGridParamsApi)(apiRef);
|
|
99
95
|
(0, _useGridColumnSpanning.useGridColumnSpanning)(apiRef);
|
|
100
96
|
(0, _useGridColumnGrouping.useGridColumnGrouping)(apiRef, props);
|
|
101
|
-
|
|
102
|
-
useGridEditing(apiRef, props);
|
|
97
|
+
(0, _useGridEditing.useGridEditing)(apiRef, props);
|
|
103
98
|
(0, _useGridFocus.useGridFocus)(apiRef, props);
|
|
104
99
|
(0, _useGridPreferencesPanel.useGridPreferencesPanel)(apiRef, props);
|
|
105
100
|
(0, _useGridFilter.useGridFilter)(apiRef, props);
|
|
@@ -29,8 +29,6 @@ var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
|
|
|
29
29
|
|
|
30
30
|
var _index = require("../icons/index");
|
|
31
31
|
|
|
32
|
-
var _GridFilterInputValue = require("../panel/filterPanel/GridFilterInputValue");
|
|
33
|
-
|
|
34
32
|
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
|
|
35
33
|
|
|
36
34
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -65,8 +63,6 @@ const GridEditInputCellRoot = (0, _styles.styled)(_InputBase.default, {
|
|
|
65
63
|
}
|
|
66
64
|
}));
|
|
67
65
|
const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
68
|
-
var _rootProps$experiment, _rootProps$experiment3;
|
|
69
|
-
|
|
70
66
|
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
71
67
|
const {
|
|
72
68
|
id,
|
|
@@ -74,7 +70,7 @@ const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
74
70
|
field,
|
|
75
71
|
colDef,
|
|
76
72
|
hasFocus,
|
|
77
|
-
debounceMs =
|
|
73
|
+
debounceMs = 200,
|
|
78
74
|
isProcessingProps,
|
|
79
75
|
onValueChange
|
|
80
76
|
} = props,
|
|
@@ -87,8 +83,6 @@ const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
87
83
|
};
|
|
88
84
|
const classes = useUtilityClasses(ownerState);
|
|
89
85
|
const handleChange = React.useCallback(async event => {
|
|
90
|
-
var _rootProps$experiment2;
|
|
91
|
-
|
|
92
86
|
const newValue = event.target.value;
|
|
93
87
|
|
|
94
88
|
if (onValueChange) {
|
|
@@ -98,7 +92,7 @@ const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
98
92
|
const column = apiRef.current.getColumn(field);
|
|
99
93
|
let parsedValue = newValue;
|
|
100
94
|
|
|
101
|
-
if (column.valueParser
|
|
95
|
+
if (column.valueParser) {
|
|
102
96
|
parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
|
|
103
97
|
}
|
|
104
98
|
|
|
@@ -110,7 +104,7 @@ const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
110
104
|
debounceMs,
|
|
111
105
|
unstable_skipValueParser: true
|
|
112
106
|
}, event);
|
|
113
|
-
}, [apiRef, debounceMs, field, id, onValueChange
|
|
107
|
+
}, [apiRef, debounceMs, field, id, onValueChange]);
|
|
114
108
|
const meta = apiRef.current.unstable_getEditCellMeta ? apiRef.current.unstable_getEditCellMeta(id, field) : {};
|
|
115
109
|
React.useEffect(() => {
|
|
116
110
|
if (meta.changeReason !== 'debouncedSetEditCellValue') {
|
|
@@ -107,8 +107,6 @@ function GridEditSingleSelectCell(props) {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const handleChange = async event => {
|
|
110
|
-
var _rootProps$experiment;
|
|
111
|
-
|
|
112
110
|
setOpen(false);
|
|
113
111
|
const target = event.target; // NativeSelect casts the value to a string.
|
|
114
112
|
|
|
@@ -118,35 +116,11 @@ function GridEditSingleSelectCell(props) {
|
|
|
118
116
|
await onValueChange(event, formattedTargetValue);
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
|
|
119
|
+
await apiRef.current.setEditCellValue({
|
|
122
120
|
id,
|
|
123
121
|
field,
|
|
124
122
|
value: formattedTargetValue
|
|
125
123
|
}, event);
|
|
126
|
-
|
|
127
|
-
if ((_rootProps$experiment = rootProps.experimentalFeatures) != null && _rootProps$experiment.newEditingApi) {
|
|
128
|
-
return;
|
|
129
|
-
} // We use isValid === false because the default return is undefined which evaluates to true with !isValid
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (rootProps.editMode === _gridEditRowModel.GridEditModes.Row || isValid === false) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const canCommit = await Promise.resolve(apiRef.current.commitCellChange({
|
|
137
|
-
id,
|
|
138
|
-
field
|
|
139
|
-
}, event));
|
|
140
|
-
|
|
141
|
-
if (canCommit) {
|
|
142
|
-
apiRef.current.setCellMode(id, field, 'view');
|
|
143
|
-
|
|
144
|
-
if (event.key) {
|
|
145
|
-
// TODO v6: remove once we stop ignoring events fired from portals
|
|
146
|
-
const params = apiRef.current.getCellParams(id, field);
|
|
147
|
-
apiRef.current.publishEvent('cellNavigationKeyDown', params, event);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
124
|
};
|
|
151
125
|
|
|
152
126
|
const handleClose = (event, reason) => {
|
|
@@ -156,17 +130,11 @@ function GridEditSingleSelectCell(props) {
|
|
|
156
130
|
}
|
|
157
131
|
|
|
158
132
|
if (reason === 'backdropClick' || (0, _keyboardUtils.isEscapeKey)(event.key)) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
field,
|
|
165
|
-
ignoreModifications: true
|
|
166
|
-
});
|
|
167
|
-
} else {
|
|
168
|
-
apiRef.current.setCellMode(id, field, 'view');
|
|
169
|
-
}
|
|
133
|
+
apiRef.current.stopCellEditMode({
|
|
134
|
+
id,
|
|
135
|
+
field,
|
|
136
|
+
ignoreModifications: true
|
|
137
|
+
});
|
|
170
138
|
}
|
|
171
139
|
};
|
|
172
140
|
|
|
@@ -33,6 +33,8 @@ var _clsx = _interopRequireDefault(require("clsx"));
|
|
|
33
33
|
|
|
34
34
|
var _gridColumnsSelector = require("../../../hooks/features/columns/gridColumnsSelector");
|
|
35
35
|
|
|
36
|
+
var _gridFilterSelector = require("../../../hooks/features/filter/gridFilterSelector");
|
|
37
|
+
|
|
36
38
|
var _useGridSelector = require("../../../hooks/utils/useGridSelector");
|
|
37
39
|
|
|
38
40
|
var _gridFilterItem = require("../../../models/gridFilterItem");
|
|
@@ -45,7 +47,7 @@ var _gridClasses = require("../../../constants/gridClasses");
|
|
|
45
47
|
|
|
46
48
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
47
49
|
|
|
48
|
-
const _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "multiFilterOperator", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "linkOperators", "columnsSort", "deleteIconProps", "linkOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "children"],
|
|
50
|
+
const _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "multiFilterOperator", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "linkOperators", "columnsSort", "filterColumns", "deleteIconProps", "linkOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "children"],
|
|
49
51
|
_excluded2 = ["InputComponentProps"];
|
|
50
52
|
|
|
51
53
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -151,6 +153,7 @@ const GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(pro
|
|
|
151
153
|
focusElementRef,
|
|
152
154
|
linkOperators = [_gridFilterItem.GridLinkOperator.And, _gridFilterItem.GridLinkOperator.Or],
|
|
153
155
|
columnsSort,
|
|
156
|
+
filterColumns,
|
|
154
157
|
deleteIconProps = {},
|
|
155
158
|
linkOperatorInputProps = {},
|
|
156
159
|
operatorInputProps = {},
|
|
@@ -160,6 +163,7 @@ const GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(pro
|
|
|
160
163
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
161
164
|
const apiRef = (0, _useGridApiContext.useGridApiContext)();
|
|
162
165
|
const filterableColumns = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridFilterableColumnDefinitionsSelector);
|
|
166
|
+
const filterModel = (0, _useGridSelector.useGridSelector)(apiRef, _gridFilterSelector.gridFilterModelSelector);
|
|
163
167
|
const columnSelectId = (0, _utils.unstable_useId)();
|
|
164
168
|
const columnSelectLabelId = (0, _utils.unstable_useId)();
|
|
165
169
|
const operatorSelectId = (0, _utils.unstable_useId)();
|
|
@@ -180,18 +184,30 @@ const GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(pro
|
|
|
180
184
|
InputComponentProps
|
|
181
185
|
} = valueInputProps,
|
|
182
186
|
valueInputPropsOther = (0, _objectWithoutPropertiesLoose2.default)(valueInputProps, _excluded2);
|
|
183
|
-
const
|
|
187
|
+
const filteredColumns = React.useMemo(() => {
|
|
188
|
+
if (filterColumns === undefined || typeof filterColumns !== 'function') {
|
|
189
|
+
return filterableColumns;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const filteredFields = filterColumns({
|
|
193
|
+
field: item.columnField,
|
|
194
|
+
columns: filterableColumns,
|
|
195
|
+
currentFilters: (filterModel == null ? void 0 : filterModel.items) || []
|
|
196
|
+
});
|
|
197
|
+
return filterableColumns.filter(column => filteredFields.includes(column.field));
|
|
198
|
+
}, [filterColumns, filterModel == null ? void 0 : filterModel.items, filterableColumns, item.columnField]);
|
|
199
|
+
const sortedFilteredColumns = React.useMemo(() => {
|
|
184
200
|
switch (columnsSort) {
|
|
185
201
|
case 'asc':
|
|
186
|
-
return
|
|
202
|
+
return filteredColumns.sort((a, b) => collator.compare(getColumnLabel(a), getColumnLabel(b)));
|
|
187
203
|
|
|
188
204
|
case 'desc':
|
|
189
|
-
return
|
|
205
|
+
return filteredColumns.sort((a, b) => -collator.compare(getColumnLabel(a), getColumnLabel(b)));
|
|
190
206
|
|
|
191
207
|
default:
|
|
192
|
-
return
|
|
208
|
+
return filteredColumns;
|
|
193
209
|
}
|
|
194
|
-
}, [
|
|
210
|
+
}, [filteredColumns, columnsSort]);
|
|
195
211
|
const currentColumn = item.columnField ? apiRef.current.getColumn(item.columnField) : null;
|
|
196
212
|
const currentOperator = React.useMemo(() => {
|
|
197
213
|
var _currentColumn$filter;
|
|
@@ -320,7 +336,7 @@ const GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(pro
|
|
|
320
336
|
onChange: changeColumn,
|
|
321
337
|
native: isBaseSelectNative
|
|
322
338
|
}, (_rootProps$components4 = rootProps.componentsProps) == null ? void 0 : _rootProps$components4.baseSelect, {
|
|
323
|
-
children:
|
|
339
|
+
children: sortedFilteredColumns.map(col => /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionComponent, {
|
|
324
340
|
value: col.field,
|
|
325
341
|
children: getColumnLabel(col)
|
|
326
342
|
}, col.field))
|
|
@@ -415,6 +431,13 @@ process.env.NODE_ENV !== "production" ? GridFilterForm.propTypes = {
|
|
|
415
431
|
*/
|
|
416
432
|
disableMultiFilterOperator: _propTypes.default.bool,
|
|
417
433
|
|
|
434
|
+
/**
|
|
435
|
+
* Allows to filter the columns displayed in the filter form.
|
|
436
|
+
* @param {FilterColumnsArgs} args The columns of the grid and name of field.
|
|
437
|
+
* @returns {GridColDef['field'][]} The filtered fields array.
|
|
438
|
+
*/
|
|
439
|
+
filterColumns: _propTypes.default.func,
|
|
440
|
+
|
|
418
441
|
/**
|
|
419
442
|
* A ref allowing to set imperative focus.
|
|
420
443
|
* It can be passed to the el
|