@mui/x-data-grid 7.0.0-alpha.5 → 7.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +226 -6
- package/DataGrid/DataGrid.js +25 -19
- package/DataGrid/useDataGridProps.js +0 -1
- package/colDef/gridDateOperators.js +13 -6
- package/colDef/gridSingleSelectColDef.js +6 -15
- package/components/cell/GridEditSingleSelectCell.d.ts +1 -2
- package/components/cell/GridEditSingleSelectCell.js +9 -29
- package/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/components/panel/filterPanel/GridFilterForm.js +44 -9
- package/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +25 -8
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -2
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -48
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -2
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -57
- package/components/panel/filterPanel/filterPanelUtils.d.ts +3 -2
- package/components/panel/filterPanel/filterPanelUtils.js +10 -5
- package/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/hooks/features/rowSelection/utils.d.ts +2 -0
- package/hooks/features/rowSelection/utils.js +8 -0
- package/hooks/utils/useGridAriaAttributes.js +2 -1
- package/index.js +1 -1
- package/legacy/DataGrid/DataGrid.js +25 -19
- package/legacy/DataGrid/useDataGridProps.js +0 -1
- package/legacy/colDef/gridDateOperators.js +13 -13
- package/legacy/colDef/gridSingleSelectColDef.js +6 -15
- package/legacy/components/cell/GridEditSingleSelectCell.js +8 -28
- package/legacy/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/legacy/components/panel/filterPanel/GridFilterForm.js +51 -19
- package/legacy/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterInputDate.js +27 -8
- package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -53
- package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -59
- package/legacy/components/panel/filterPanel/filterPanelUtils.js +10 -6
- package/legacy/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/legacy/hooks/features/rowSelection/utils.js +8 -0
- package/legacy/hooks/utils/useGridAriaAttributes.js +2 -1
- package/legacy/index.js +1 -1
- package/models/props/DataGridProps.d.ts +26 -25
- package/modern/DataGrid/DataGrid.js +25 -19
- package/modern/DataGrid/useDataGridProps.js +0 -1
- package/modern/colDef/gridDateOperators.js +13 -6
- package/modern/colDef/gridSingleSelectColDef.js +6 -15
- package/modern/components/cell/GridEditSingleSelectCell.js +9 -29
- package/modern/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/modern/components/panel/filterPanel/GridFilterForm.js +44 -9
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +24 -6
- package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -47
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -56
- package/modern/components/panel/filterPanel/filterPanelUtils.js +10 -5
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/modern/hooks/features/rowSelection/utils.js +8 -0
- package/modern/hooks/utils/useGridAriaAttributes.js +2 -1
- package/modern/index.js +1 -1
- package/node/DataGrid/DataGrid.js +25 -19
- package/node/DataGrid/useDataGridProps.js +0 -1
- package/node/colDef/gridDateOperators.js +13 -6
- package/node/colDef/gridSingleSelectColDef.js +5 -14
- package/node/components/cell/GridEditSingleSelectCell.js +8 -28
- package/node/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/node/components/panel/filterPanel/GridFilterForm.js +44 -9
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputDate.js +24 -6
- package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -46
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -55
- package/node/components/panel/filterPanel/filterPanelUtils.js +12 -7
- package/node/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/node/hooks/features/rowSelection/utils.js +14 -0
- package/node/hooks/utils/useGridAriaAttributes.js +2 -1
- package/node/index.js +1 -1
- package/package.json +3 -3
|
@@ -15,6 +15,7 @@ import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
|
15
15
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from '../../../constants/gridDetailPanelToggleField';
|
|
16
16
|
import { gridClasses } from '../../../constants/gridClasses';
|
|
17
17
|
import { isEventTargetInPortal } from '../../../utils/domUtils';
|
|
18
|
+
import { isMultipleRowSelectionEnabled } from './utils';
|
|
18
19
|
const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
19
20
|
if (selectionModelProp == null) {
|
|
20
21
|
return selectionModelProp;
|
|
@@ -57,11 +58,10 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
57
58
|
});
|
|
58
59
|
const {
|
|
59
60
|
checkboxSelection,
|
|
60
|
-
disableMultipleRowSelection,
|
|
61
61
|
disableRowSelectionOnClick,
|
|
62
62
|
isRowSelectable: propIsRowSelectable
|
|
63
63
|
} = props;
|
|
64
|
-
const canHaveMultipleSelection =
|
|
64
|
+
const canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
|
|
65
65
|
const visibleRows = useGridVisibleRows(apiRef, props);
|
|
66
66
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
67
67
|
let endId = id;
|
|
@@ -91,7 +91,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
91
91
|
* API METHODS
|
|
92
92
|
*/
|
|
93
93
|
const setRowSelectionModel = React.useCallback(model => {
|
|
94
|
-
if (props.signature === GridSignature.DataGrid && !
|
|
94
|
+
if (props.signature === GridSignature.DataGrid && !canHaveMultipleSelection && Array.isArray(model) && model.length > 1) {
|
|
95
95
|
throw new Error(['MUI: `rowSelectionModel` can only contain 1 item in DataGrid.', 'You need to upgrade to DataGridPro or DataGridPremium component to unlock multiple selection.'].join('\n'));
|
|
96
96
|
}
|
|
97
97
|
const currentModel = gridRowSelectionStateSelector(apiRef.current.state);
|
|
@@ -102,7 +102,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
102
102
|
}));
|
|
103
103
|
apiRef.current.forceUpdate();
|
|
104
104
|
}
|
|
105
|
-
}, [apiRef, logger, props.rowSelection, props.signature,
|
|
105
|
+
}, [apiRef, logger, props.rowSelection, props.signature, canHaveMultipleSelection]);
|
|
106
106
|
const isRowSelected = React.useCallback(id => gridRowSelectionStateSelector(apiRef.current.state).includes(id), [apiRef]);
|
|
107
107
|
const isRowSelectable = React.useCallback(id => {
|
|
108
108
|
if (propIsRowSelectable && !propIsRowSelectable(apiRef.current.getRowParams(id))) {
|
|
@@ -253,24 +253,24 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
253
253
|
if (rowNode.type === 'pinnedRow') {
|
|
254
254
|
return;
|
|
255
255
|
}
|
|
256
|
-
if (event.shiftKey &&
|
|
256
|
+
if (event.shiftKey && canHaveMultipleSelection) {
|
|
257
257
|
expandMouseRowRangeSelection(params.id);
|
|
258
258
|
} else {
|
|
259
259
|
handleSingleRowSelection(params.id, event);
|
|
260
260
|
}
|
|
261
|
-
}, [disableRowSelectionOnClick, canHaveMultipleSelection,
|
|
261
|
+
}, [disableRowSelectionOnClick, canHaveMultipleSelection, apiRef, expandMouseRowRangeSelection, handleSingleRowSelection]);
|
|
262
262
|
const preventSelectionOnShift = React.useCallback((params, event) => {
|
|
263
263
|
if (canHaveMultipleSelection && event.shiftKey) {
|
|
264
264
|
window.getSelection()?.removeAllRanges();
|
|
265
265
|
}
|
|
266
266
|
}, [canHaveMultipleSelection]);
|
|
267
267
|
const handleRowSelectionCheckboxChange = React.useCallback((params, event) => {
|
|
268
|
-
if (event.nativeEvent.shiftKey) {
|
|
268
|
+
if (canHaveMultipleSelection && event.nativeEvent.shiftKey) {
|
|
269
269
|
expandMouseRowRangeSelection(params.id);
|
|
270
270
|
} else {
|
|
271
|
-
apiRef.current.selectRow(params.id, params.value);
|
|
271
|
+
apiRef.current.selectRow(params.id, params.value, !canHaveMultipleSelection);
|
|
272
272
|
}
|
|
273
|
-
}, [apiRef, expandMouseRowRangeSelection]);
|
|
273
|
+
}, [apiRef, expandMouseRowRangeSelection, canHaveMultipleSelection]);
|
|
274
274
|
const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
|
|
275
275
|
const shouldLimitSelectionToCurrentPage = props.checkboxSelectionVisibleOnly && props.pagination;
|
|
276
276
|
const rowsToBeSelected = shouldLimitSelectionToCurrentPage ? gridPaginatedVisibleSortedGridRowIdsSelector(apiRef) : gridExpandedSortedRowIdsSelector(apiRef);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GridSignature } from '../../utils/useGridApiEventHandler';
|
|
2
|
+
export function isMultipleRowSelectionEnabled(props) {
|
|
3
|
+
if (props.signature === GridSignature.DataGrid) {
|
|
4
|
+
// DataGrid Community has multiple row selection enabled only if checkbox selection is enabled.
|
|
5
|
+
return props.checkboxSelection && props.disableMultipleRowSelection !== true;
|
|
6
|
+
}
|
|
7
|
+
return !props.disableMultipleRowSelection;
|
|
8
|
+
}
|
|
@@ -4,6 +4,7 @@ import { useGridRootProps } from './useGridRootProps';
|
|
|
4
4
|
import { gridColumnGroupsHeaderMaxDepthSelector } from '../features/columnGrouping/gridColumnGroupsSelector';
|
|
5
5
|
import { gridPinnedRowsCountSelector, gridRowCountSelector } from '../features/rows/gridRowsSelector';
|
|
6
6
|
import { useGridPrivateApiContext } from './useGridPrivateApiContext';
|
|
7
|
+
import { isMultipleRowSelectionEnabled } from '../features/rowSelection/utils';
|
|
7
8
|
export const useGridAriaAttributes = () => {
|
|
8
9
|
const apiRef = useGridPrivateApiContext();
|
|
9
10
|
const rootProps = useGridRootProps();
|
|
@@ -19,6 +20,6 @@ export const useGridAriaAttributes = () => {
|
|
|
19
20
|
role,
|
|
20
21
|
'aria-colcount': visibleColumns.length,
|
|
21
22
|
'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + totalRowCount,
|
|
22
|
-
'aria-multiselectable':
|
|
23
|
+
'aria-multiselectable': isMultipleRowSelectionEnabled(rootProps)
|
|
23
24
|
};
|
|
24
25
|
};
|
package/modern/index.js
CHANGED
|
@@ -49,21 +49,21 @@ DataGridRaw.propTypes = {
|
|
|
49
49
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
50
50
|
// ----------------------------------------------------------------------
|
|
51
51
|
/**
|
|
52
|
-
* The ref object that allows
|
|
52
|
+
* The ref object that allows Data Grid manipulation. Can be instantiated with `useGridApiRef()`.
|
|
53
53
|
*/
|
|
54
54
|
apiRef: _propTypes.default.shape({
|
|
55
55
|
current: _propTypes.default.object.isRequired
|
|
56
56
|
}),
|
|
57
57
|
/**
|
|
58
|
-
* The label of the
|
|
58
|
+
* The label of the Data Grid.
|
|
59
59
|
*/
|
|
60
60
|
'aria-label': _propTypes.default.string,
|
|
61
61
|
/**
|
|
62
|
-
* The id of the element containing a label for the
|
|
62
|
+
* The id of the element containing a label for the Data Grid.
|
|
63
63
|
*/
|
|
64
64
|
'aria-labelledby': _propTypes.default.string,
|
|
65
65
|
/**
|
|
66
|
-
* If `true`, the
|
|
66
|
+
* If `true`, the Data Grid height is dynamic and follow the number of rows in the Data Grid.
|
|
67
67
|
* @default false
|
|
68
68
|
*/
|
|
69
69
|
autoHeight: _propTypes.default.bool,
|
|
@@ -77,7 +77,7 @@ DataGridRaw.propTypes = {
|
|
|
77
77
|
*/
|
|
78
78
|
cellModesModel: _propTypes.default.object,
|
|
79
79
|
/**
|
|
80
|
-
* If `true`, the
|
|
80
|
+
* If `true`, the Data Grid will display an extra column with checkboxes for selecting rows.
|
|
81
81
|
* @default false
|
|
82
82
|
*/
|
|
83
83
|
checkboxSelection: _propTypes.default.bool,
|
|
@@ -97,7 +97,7 @@ DataGridRaw.propTypes = {
|
|
|
97
97
|
columnBuffer: _propTypes.default.number,
|
|
98
98
|
columnGroupingModel: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
99
99
|
/**
|
|
100
|
-
* Sets the height in pixel of the column headers in the
|
|
100
|
+
* Sets the height in pixel of the column headers in the Data Grid.
|
|
101
101
|
* @default 56
|
|
102
102
|
*/
|
|
103
103
|
columnHeaderHeight: _propTypes.default.number,
|
|
@@ -117,12 +117,12 @@ DataGridRaw.propTypes = {
|
|
|
117
117
|
*/
|
|
118
118
|
columnThreshold: _propTypes.default.number,
|
|
119
119
|
/**
|
|
120
|
-
* Set the column visibility model of the
|
|
121
|
-
* If defined, the
|
|
120
|
+
* Set the column visibility model of the Data Grid.
|
|
121
|
+
* If defined, the Data Grid will ignore the `hide` property in [[GridColDef]].
|
|
122
122
|
*/
|
|
123
123
|
columnVisibilityModel: _propTypes.default.object,
|
|
124
124
|
/**
|
|
125
|
-
* Set the density of the
|
|
125
|
+
* Set the density of the Data Grid.
|
|
126
126
|
* @default "standard"
|
|
127
127
|
*/
|
|
128
128
|
density: _propTypes.default.oneOf(['comfortable', 'compact', 'standard']),
|
|
@@ -152,6 +152,12 @@ DataGridRaw.propTypes = {
|
|
|
152
152
|
* @ignore - do not document
|
|
153
153
|
*/
|
|
154
154
|
disableEval: _propTypes.default.bool,
|
|
155
|
+
/**
|
|
156
|
+
* If `true`, multiple selection using the Ctrl/CMD or Shift key is disabled.
|
|
157
|
+
* The MIT DataGrid will ignore this prop, unless `checkboxSelection` is enabled.
|
|
158
|
+
* @default false (`!props.checkboxSelection` for MIT Data Grid)
|
|
159
|
+
*/
|
|
160
|
+
disableMultipleRowSelection: _propTypes.default.bool,
|
|
155
161
|
/**
|
|
156
162
|
* If `true`, the selection on click on a row or cell is disabled.
|
|
157
163
|
* @default false
|
|
@@ -188,7 +194,7 @@ DataGridRaw.propTypes = {
|
|
|
188
194
|
*/
|
|
189
195
|
filterMode: _propTypes.default.oneOf(['client', 'server']),
|
|
190
196
|
/**
|
|
191
|
-
* Set the filter model of the
|
|
197
|
+
* Set the filter model of the Data Grid.
|
|
192
198
|
*/
|
|
193
199
|
filterModel: _propTypes.default.shape({
|
|
194
200
|
items: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
@@ -203,7 +209,7 @@ DataGridRaw.propTypes = {
|
|
|
203
209
|
quickFilterValues: _propTypes.default.array
|
|
204
210
|
}),
|
|
205
211
|
/**
|
|
206
|
-
* Forwarded props for the
|
|
212
|
+
* Forwarded props for the Data Grid root element.
|
|
207
213
|
* @ignore - do not document.
|
|
208
214
|
*/
|
|
209
215
|
forwardedProps: _propTypes.default.object,
|
|
@@ -271,7 +277,7 @@ DataGridRaw.propTypes = {
|
|
|
271
277
|
*/
|
|
272
278
|
ignoreDiacritics: _propTypes.default.bool,
|
|
273
279
|
/**
|
|
274
|
-
* If `true`, the
|
|
280
|
+
* If `true`, the Data Grid will not use `valueFormatter` when exporting to CSV or copying to clipboard.
|
|
275
281
|
* If an object is provided, you can choose to ignore the `valueFormatter` for CSV export or clipboard export.
|
|
276
282
|
* @default false
|
|
277
283
|
*/
|
|
@@ -309,7 +315,7 @@ DataGridRaw.propTypes = {
|
|
|
309
315
|
*/
|
|
310
316
|
loading: _propTypes.default.bool,
|
|
311
317
|
/**
|
|
312
|
-
* Set the locale text of the
|
|
318
|
+
* Set the locale text of the Data Grid.
|
|
313
319
|
* You can find all the translation keys supported in [the source](https://github.com/mui/mui-x/blob/HEAD/packages/grid/x-data-grid/src/constants/localeTextConstants.ts) in the GitHub repository.
|
|
314
320
|
*/
|
|
315
321
|
localeText: _propTypes.default.object,
|
|
@@ -477,7 +483,7 @@ DataGridRaw.propTypes = {
|
|
|
477
483
|
*/
|
|
478
484
|
onProcessRowUpdateError: _propTypes.default.func,
|
|
479
485
|
/**
|
|
480
|
-
* Callback fired when the
|
|
486
|
+
* Callback fired when the Data Grid is resized.
|
|
481
487
|
* @param {ElementSize} containerSize With all properties from [[ElementSize]].
|
|
482
488
|
* @param {MuiEvent<{}>} event The event object.
|
|
483
489
|
* @param {GridCallbackDetails} details Additional details for this callback.
|
|
@@ -535,7 +541,7 @@ DataGridRaw.propTypes = {
|
|
|
535
541
|
*/
|
|
536
542
|
onSortModelChange: _propTypes.default.func,
|
|
537
543
|
/**
|
|
538
|
-
* Callback fired when the state of the
|
|
544
|
+
* Callback fired when the state of the Data Grid is updated.
|
|
539
545
|
* @param {GridState} state The new state.
|
|
540
546
|
* @param {MuiEvent<{}>} event The event object.
|
|
541
547
|
* @param {GridCallbackDetails} details Additional details for this callback.
|
|
@@ -589,7 +595,7 @@ DataGridRaw.propTypes = {
|
|
|
589
595
|
*/
|
|
590
596
|
rowCount: _propTypes.default.number,
|
|
591
597
|
/**
|
|
592
|
-
* Sets the height in pixel of a row in the
|
|
598
|
+
* Sets the height in pixel of a row in the Data Grid.
|
|
593
599
|
* @default 52
|
|
594
600
|
*/
|
|
595
601
|
rowHeight: _propTypes.default.number,
|
|
@@ -614,7 +620,7 @@ DataGridRaw.propTypes = {
|
|
|
614
620
|
*/
|
|
615
621
|
rowSelection: _propTypes.default.bool,
|
|
616
622
|
/**
|
|
617
|
-
* Sets the row selection model of the
|
|
623
|
+
* Sets the row selection model of the Data Grid.
|
|
618
624
|
*/
|
|
619
625
|
rowSelectionModel: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired), _propTypes.default.number, _propTypes.default.string]),
|
|
620
626
|
/**
|
|
@@ -628,7 +634,7 @@ DataGridRaw.propTypes = {
|
|
|
628
634
|
*/
|
|
629
635
|
rowThreshold: _propTypes.default.number,
|
|
630
636
|
/**
|
|
631
|
-
* Override the height/width of the
|
|
637
|
+
* Override the height/width of the Data Grid inner scrollbar.
|
|
632
638
|
*/
|
|
633
639
|
scrollbarSize: _propTypes.default.number,
|
|
634
640
|
/**
|
|
@@ -662,7 +668,7 @@ DataGridRaw.propTypes = {
|
|
|
662
668
|
*/
|
|
663
669
|
sortingOrder: _propTypes.default.arrayOf(_propTypes.default.oneOf(['asc', 'desc'])),
|
|
664
670
|
/**
|
|
665
|
-
* Set the sort model of the
|
|
671
|
+
* Set the sort model of the Data Grid.
|
|
666
672
|
*/
|
|
667
673
|
sortModel: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
668
674
|
field: _propTypes.default.string.isRequired,
|
|
@@ -17,7 +17,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
17
17
|
const DATA_GRID_FORCED_PROPS = {
|
|
18
18
|
disableMultipleColumnsFiltering: true,
|
|
19
19
|
disableMultipleColumnsSorting: true,
|
|
20
|
-
disableMultipleRowSelection: true,
|
|
21
20
|
throttleRowsMs: undefined,
|
|
22
21
|
hideFooterRowCount: false,
|
|
23
22
|
pagination: true,
|
|
@@ -5,14 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getGridDateOperators = void 0;
|
|
7
7
|
var _GridFilterInputDate = require("../components/panel/filterPanel/GridFilterInputDate");
|
|
8
|
-
const dateRegex = /(\d+)-(\d+)-(\d+)/;
|
|
9
|
-
const dateTimeRegex = /(\d+)-(\d+)-(\d+)T(\d+):(\d+)/;
|
|
10
8
|
function buildApplyFilterFn(filterItem, compareFn, showTime, keepHours) {
|
|
11
9
|
if (!filterItem.value) {
|
|
12
10
|
return null;
|
|
13
11
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
12
|
+
const date = new Date(filterItem.value);
|
|
13
|
+
if (showTime) {
|
|
14
|
+
date.setSeconds(0, 0);
|
|
15
|
+
} else {
|
|
16
|
+
date.setHours(0, 0, 0, 0);
|
|
17
|
+
}
|
|
18
|
+
const time = date.getTime();
|
|
16
19
|
return value => {
|
|
17
20
|
if (!value) {
|
|
18
21
|
return false;
|
|
@@ -23,8 +26,12 @@ function buildApplyFilterFn(filterItem, compareFn, showTime, keepHours) {
|
|
|
23
26
|
|
|
24
27
|
// Make a copy of the date to not reset the hours in the original object
|
|
25
28
|
const dateCopy = new Date(value);
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
if (showTime) {
|
|
30
|
+
dateCopy.setSeconds(0, 0);
|
|
31
|
+
} else {
|
|
32
|
+
dateCopy.setHours(0, 0, 0, 0);
|
|
33
|
+
}
|
|
34
|
+
return compareFn(dateCopy.getTime(), time);
|
|
28
35
|
};
|
|
29
36
|
}
|
|
30
37
|
const getGridDateOperators = showTime => [{
|
|
@@ -35,16 +35,10 @@ const GRID_SINGLE_SELECT_COL_DEF = exports.GRID_SINGLE_SELECT_COL_DEF = (0, _ext
|
|
|
35
35
|
if (!(0, _filterPanelUtils.isSingleSelectColDef)(colDef)) {
|
|
36
36
|
return '';
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
row: id ? api.getRow(id) : null,
|
|
43
|
-
field
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
valueOptions = colDef.valueOptions;
|
|
47
|
-
}
|
|
38
|
+
const valueOptions = (0, _filterPanelUtils.getValueOptions)(colDef, {
|
|
39
|
+
id,
|
|
40
|
+
row: id ? api.getRow(id) : null
|
|
41
|
+
});
|
|
48
42
|
if (value == null) {
|
|
49
43
|
return '';
|
|
50
44
|
}
|
|
@@ -62,10 +56,7 @@ const GRID_SINGLE_SELECT_COL_DEF = exports.GRID_SINGLE_SELECT_COL_DEF = (0, _ext
|
|
|
62
56
|
// @ts-ignore
|
|
63
57
|
pastedValueParser: (value, params) => {
|
|
64
58
|
const colDef = params.colDef;
|
|
65
|
-
const
|
|
66
|
-
const valueOptions = typeof colDefValueOptions === 'function' ? colDefValueOptions({
|
|
67
|
-
field: colDef.field
|
|
68
|
-
}) : colDefValueOptions || [];
|
|
59
|
+
const valueOptions = (0, _filterPanelUtils.getValueOptions)(colDef) || [];
|
|
69
60
|
const getOptionValue = colDef.getOptionValue;
|
|
70
61
|
const valueOption = valueOptions.find(option => {
|
|
71
62
|
if (getOptionValue(option) === value) {
|
|
@@ -19,7 +19,7 @@ var _gridEditRowModel = require("../../models/gridEditRowModel");
|
|
|
19
19
|
var _filterPanelUtils = require("../panel/filterPanel/filterPanelUtils");
|
|
20
20
|
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
|
|
21
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange", "initialOpen"
|
|
22
|
+
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange", "initialOpen"],
|
|
23
23
|
_excluded2 = ["MenuProps"];
|
|
24
24
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
25
25
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -37,9 +37,7 @@ function GridEditSingleSelectCell(props) {
|
|
|
37
37
|
hasFocus,
|
|
38
38
|
error,
|
|
39
39
|
onValueChange,
|
|
40
|
-
initialOpen = rootProps.editMode === _gridEditRowModel.GridEditModes.Cell
|
|
41
|
-
getOptionLabel: getOptionLabelProp,
|
|
42
|
-
getOptionValue: getOptionValueProp
|
|
40
|
+
initialOpen = rootProps.editMode === _gridEditRowModel.GridEditModes.Cell
|
|
43
41
|
} = props,
|
|
44
42
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
45
43
|
const apiRef = (0, _useGridApiContext.useGridApiContext)();
|
|
@@ -61,21 +59,15 @@ function GridEditSingleSelectCell(props) {
|
|
|
61
59
|
if (!(0, _filterPanelUtils.isSingleSelectColDef)(colDef)) {
|
|
62
60
|
return null;
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
row,
|
|
69
|
-
field
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
valueOptions = colDef?.valueOptions;
|
|
73
|
-
}
|
|
62
|
+
const valueOptions = (0, _filterPanelUtils.getValueOptions)(colDef, {
|
|
63
|
+
id,
|
|
64
|
+
row
|
|
65
|
+
});
|
|
74
66
|
if (!valueOptions) {
|
|
75
67
|
return null;
|
|
76
68
|
}
|
|
77
|
-
const getOptionValue =
|
|
78
|
-
const getOptionLabel =
|
|
69
|
+
const getOptionValue = colDef.getOptionValue;
|
|
70
|
+
const getOptionLabel = colDef.getOptionLabel;
|
|
79
71
|
const handleChange = async event => {
|
|
80
72
|
if (!(0, _filterPanelUtils.isSingleSelectColDef)(colDef) || !valueOptions) {
|
|
81
73
|
return;
|
|
@@ -164,18 +156,6 @@ process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes = {
|
|
|
164
156
|
* The cell value formatted with the column valueFormatter.
|
|
165
157
|
*/
|
|
166
158
|
formattedValue: _propTypes.default.any,
|
|
167
|
-
/**
|
|
168
|
-
* Used to determine the label displayed for a given value option.
|
|
169
|
-
* @param {ValueOptions} value The current value option.
|
|
170
|
-
* @returns {string} The text to be displayed.
|
|
171
|
-
*/
|
|
172
|
-
getOptionLabel: _propTypes.default.func,
|
|
173
|
-
/**
|
|
174
|
-
* Used to determine the value used for a value option.
|
|
175
|
-
* @param {ValueOptions} value The current value option.
|
|
176
|
-
* @returns {string} The value to be used.
|
|
177
|
-
*/
|
|
178
|
-
getOptionValue: _propTypes.default.func,
|
|
179
159
|
/**
|
|
180
160
|
* If true, the cell is the active element.
|
|
181
161
|
*/
|
|
@@ -10,6 +10,7 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
|
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
12
|
var _utils = require("@mui/utils");
|
|
13
|
+
var _utils2 = require("../../hooks/features/rowSelection/utils");
|
|
13
14
|
var _useGridSelector = require("../../hooks/utils/useGridSelector");
|
|
14
15
|
var _gridFocusStateSelector = require("../../hooks/features/focus/gridFocusStateSelector");
|
|
15
16
|
var _gridRowSelectionSelector = require("../../hooks/features/rowSelection/gridRowSelectionSelector");
|
|
@@ -111,7 +112,8 @@ const GridHeaderCheckbox = exports.GridHeaderCheckbox = /*#__PURE__*/React.forwa
|
|
|
111
112
|
'aria-label': label
|
|
112
113
|
},
|
|
113
114
|
tabIndex: tabIndex,
|
|
114
|
-
onKeyDown: handleKeyDown
|
|
115
|
+
onKeyDown: handleKeyDown,
|
|
116
|
+
disabled: !(0, _utils2.isMultipleRowSelectionEnabled)(rootProps)
|
|
115
117
|
}, rootProps.slotProps?.baseCheckbox, other));
|
|
116
118
|
});
|
|
117
119
|
process.env.NODE_ENV !== "production" ? GridHeaderCheckbox.propTypes = {
|
|
@@ -20,6 +20,7 @@ var _gridFilterItem = require("../../../models/gridFilterItem");
|
|
|
20
20
|
var _useGridApiContext = require("../../../hooks/utils/useGridApiContext");
|
|
21
21
|
var _useGridRootProps = require("../../../hooks/utils/useGridRootProps");
|
|
22
22
|
var _gridClasses = require("../../../constants/gridClasses");
|
|
23
|
+
var _filterPanelUtils = require("./filterPanelUtils");
|
|
23
24
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
24
25
|
const _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "multiFilterOperator", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "logicOperators", "columnsSort", "filterColumns", "deleteIconProps", "logicOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "children"],
|
|
25
26
|
_excluded2 = ["InputComponentProps"];
|
|
@@ -138,23 +139,39 @@ const GridFilterForm = exports.GridFilterForm = /*#__PURE__*/React.forwardRef(fu
|
|
|
138
139
|
const hasLogicOperatorColumn = hasMultipleFilters && logicOperators.length > 0;
|
|
139
140
|
const baseFormControlProps = rootProps.slotProps?.baseFormControl || {};
|
|
140
141
|
const baseSelectProps = rootProps.slotProps?.baseSelect || {};
|
|
141
|
-
const isBaseSelectNative = baseSelectProps.native ??
|
|
142
|
+
const isBaseSelectNative = baseSelectProps.native ?? false;
|
|
142
143
|
const baseInputLabelProps = rootProps.slotProps?.baseInputLabel || {};
|
|
143
144
|
const baseSelectOptionProps = rootProps.slotProps?.baseSelectOption || {};
|
|
144
145
|
const {
|
|
145
146
|
InputComponentProps
|
|
146
147
|
} = valueInputProps,
|
|
147
148
|
valueInputPropsOther = (0, _objectWithoutPropertiesLoose2.default)(valueInputProps, _excluded2);
|
|
148
|
-
const
|
|
149
|
+
const {
|
|
150
|
+
filteredColumns,
|
|
151
|
+
selectedField
|
|
152
|
+
} = React.useMemo(() => {
|
|
153
|
+
let itemField = item.field;
|
|
149
154
|
if (filterColumns === undefined || typeof filterColumns !== 'function') {
|
|
150
|
-
return
|
|
155
|
+
return {
|
|
156
|
+
filteredColumns: filterableColumns,
|
|
157
|
+
selectedField: itemField
|
|
158
|
+
};
|
|
151
159
|
}
|
|
152
160
|
const filteredFields = filterColumns({
|
|
153
161
|
field: item.field,
|
|
154
162
|
columns: filterableColumns,
|
|
155
163
|
currentFilters: filterModel?.items || []
|
|
156
164
|
});
|
|
157
|
-
return
|
|
165
|
+
return {
|
|
166
|
+
filteredColumns: filterableColumns.filter(column => {
|
|
167
|
+
const isFieldIncluded = filteredFields.includes(column.field);
|
|
168
|
+
if (column.field === item.field && !isFieldIncluded) {
|
|
169
|
+
itemField = undefined;
|
|
170
|
+
}
|
|
171
|
+
return isFieldIncluded;
|
|
172
|
+
}),
|
|
173
|
+
selectedField: itemField
|
|
174
|
+
};
|
|
158
175
|
}, [filterColumns, filterModel?.items, filterableColumns, item.field]);
|
|
159
176
|
const sortedFilteredColumns = React.useMemo(() => {
|
|
160
177
|
switch (columnsSort) {
|
|
@@ -185,11 +202,29 @@ const GridFilterForm = exports.GridFilterForm = /*#__PURE__*/React.forwardRef(fu
|
|
|
185
202
|
const newOperator = column.filterOperators.find(operator => operator.value === item.operator) || column.filterOperators[0];
|
|
186
203
|
|
|
187
204
|
// Erase filter value if the input component or filtered column type is modified
|
|
188
|
-
const
|
|
205
|
+
const eraseFilterValue = !newOperator.InputComponent || newOperator.InputComponent !== currentOperator?.InputComponent || column.type !== currentColumn.type;
|
|
206
|
+
let filterValue = eraseFilterValue ? undefined : item.value;
|
|
207
|
+
|
|
208
|
+
// Check filter value against the new valueOptions
|
|
209
|
+
if (column.type === 'singleSelect' && filterValue !== undefined) {
|
|
210
|
+
const colDef = column;
|
|
211
|
+
const valueOptions = (0, _filterPanelUtils.getValueOptions)(colDef);
|
|
212
|
+
if (Array.isArray(filterValue)) {
|
|
213
|
+
filterValue = filterValue.filter(val => {
|
|
214
|
+
return (
|
|
215
|
+
// Only keep values that are in the new value options
|
|
216
|
+
(0, _filterPanelUtils.getValueFromValueOptions)(val, valueOptions, colDef?.getOptionValue) !== undefined
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
} else if ((0, _filterPanelUtils.getValueFromValueOptions)(item.value, valueOptions, colDef?.getOptionValue) === undefined) {
|
|
220
|
+
// Reset the filter value if it is not in the new value options
|
|
221
|
+
filterValue = undefined;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
189
224
|
applyFilterChanges((0, _extends2.default)({}, item, {
|
|
190
225
|
field,
|
|
191
226
|
operator: newOperator.value,
|
|
192
|
-
value:
|
|
227
|
+
value: filterValue
|
|
193
228
|
}));
|
|
194
229
|
}, [apiRef, applyFilterChanges, item, currentColumn, currentOperator]);
|
|
195
230
|
const changeOperator = React.useCallback(event => {
|
|
@@ -264,7 +299,7 @@ const GridFilterForm = exports.GridFilterForm = /*#__PURE__*/React.forwardRef(fu
|
|
|
264
299
|
inputProps: {
|
|
265
300
|
'aria-label': apiRef.current.getLocaleText('filterPanelLogicOperator')
|
|
266
301
|
},
|
|
267
|
-
value: multiFilterOperator,
|
|
302
|
+
value: multiFilterOperator ?? '',
|
|
268
303
|
onChange: changeLogicOperator,
|
|
269
304
|
disabled: !!disableMultiFilterOperator || logicOperators.length === 1,
|
|
270
305
|
native: isBaseSelectNative
|
|
@@ -289,7 +324,7 @@ const GridFilterForm = exports.GridFilterForm = /*#__PURE__*/React.forwardRef(fu
|
|
|
289
324
|
labelId: columnSelectLabelId,
|
|
290
325
|
id: columnSelectId,
|
|
291
326
|
label: apiRef.current.getLocaleText('filterPanelColumns'),
|
|
292
|
-
value:
|
|
327
|
+
value: selectedField ?? '',
|
|
293
328
|
onChange: changeColumn,
|
|
294
329
|
native: isBaseSelectNative
|
|
295
330
|
}, rootProps.slotProps?.baseSelect, {
|
|
@@ -335,7 +370,7 @@ const GridFilterForm = exports.GridFilterForm = /*#__PURE__*/React.forwardRef(fu
|
|
|
335
370
|
item: item,
|
|
336
371
|
applyValue: applyFilterChanges,
|
|
337
372
|
focusElementRef: valueRef
|
|
338
|
-
}, currentOperator.InputComponentProps, InputComponentProps)) : null
|
|
373
|
+
}, currentOperator.InputComponentProps, InputComponentProps), item.field) : null
|
|
339
374
|
}))]
|
|
340
375
|
}));
|
|
341
376
|
});
|
|
@@ -40,7 +40,7 @@ function GridFilterInputBoolean(props) {
|
|
|
40
40
|
const labelId = (0, _utils.unstable_useId)();
|
|
41
41
|
const selectId = (0, _utils.unstable_useId)();
|
|
42
42
|
const baseSelectProps = rootProps.slotProps?.baseSelect || {};
|
|
43
|
-
const isSelectNative = baseSelectProps.native ??
|
|
43
|
+
const isSelectNative = baseSelectProps.native ?? false;
|
|
44
44
|
const baseSelectOptionProps = rootProps.slotProps?.baseSelectOption || {};
|
|
45
45
|
const onFilterChange = React.useCallback(event => {
|
|
46
46
|
const value = event.target.value;
|
|
@@ -16,6 +16,23 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
16
16
|
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "InputProps", "isFilterActive", "clearButton", "tabIndex", "disabled"];
|
|
17
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
18
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
|
+
function convertFilterItemValueToInputValue(itemValue, inputType) {
|
|
20
|
+
if (itemValue == null) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
const dateCopy = new Date(itemValue);
|
|
24
|
+
// The date picker expects the date to be in the local timezone.
|
|
25
|
+
// But .toISOString() converts it to UTC with zero offset.
|
|
26
|
+
// So we need to subtract the timezone offset.
|
|
27
|
+
dateCopy.setMinutes(dateCopy.getMinutes() - dateCopy.getTimezoneOffset());
|
|
28
|
+
if (inputType === 'date') {
|
|
29
|
+
return dateCopy.toISOString().substring(0, 10);
|
|
30
|
+
}
|
|
31
|
+
if (inputType === 'datetime-local') {
|
|
32
|
+
return dateCopy.toISOString().substring(0, 19);
|
|
33
|
+
}
|
|
34
|
+
return dateCopy.toISOString().substring(0, 10);
|
|
35
|
+
}
|
|
19
36
|
function GridFilterInputDate(props) {
|
|
20
37
|
const {
|
|
21
38
|
item,
|
|
@@ -30,25 +47,26 @@ function GridFilterInputDate(props) {
|
|
|
30
47
|
} = props,
|
|
31
48
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
32
49
|
const filterTimeout = (0, _useTimeout.useTimeout)();
|
|
33
|
-
const [filterValueState, setFilterValueState] = React.useState(item.value
|
|
50
|
+
const [filterValueState, setFilterValueState] = React.useState(() => convertFilterItemValueToInputValue(item.value, type));
|
|
34
51
|
const [applying, setIsApplying] = React.useState(false);
|
|
35
52
|
const id = (0, _utils.unstable_useId)();
|
|
36
53
|
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
37
54
|
const onFilterChange = React.useCallback(event => {
|
|
55
|
+
filterTimeout.clear();
|
|
38
56
|
const value = event.target.value;
|
|
39
|
-
setFilterValueState(
|
|
57
|
+
setFilterValueState(value);
|
|
40
58
|
setIsApplying(true);
|
|
41
59
|
filterTimeout.start(rootProps.filterDebounceMs, () => {
|
|
42
60
|
applyValue((0, _extends2.default)({}, item, {
|
|
43
|
-
value
|
|
61
|
+
value: new Date(value)
|
|
44
62
|
}));
|
|
45
63
|
setIsApplying(false);
|
|
46
64
|
});
|
|
47
65
|
}, [applyValue, item, rootProps.filterDebounceMs, filterTimeout]);
|
|
48
66
|
React.useEffect(() => {
|
|
49
|
-
const
|
|
50
|
-
setFilterValueState(
|
|
51
|
-
}, [item.value]);
|
|
67
|
+
const value = convertFilterItemValueToInputValue(item.value, type);
|
|
68
|
+
setFilterValueState(value);
|
|
69
|
+
}, [item.value, type]);
|
|
52
70
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTextField, (0, _extends2.default)({
|
|
53
71
|
fullWidth: true,
|
|
54
72
|
id: id,
|