@mui/x-data-grid 5.14.0 → 5.15.2
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 +147 -5
- package/DataGrid/DataGrid.js +7 -1
- package/DataGrid/useDataGridProps.js +1 -0
- package/colDef/gridStringColDef.js +1 -1
- package/components/GridRow.js +5 -1
- package/components/base/GridOverlays.js +2 -2
- package/components/cell/GridEditInputCell.d.ts +2 -5
- package/components/cell/GridEditInputCell.js +13 -14
- package/components/cell/GridEditSingleSelectCell.d.ts +4 -0
- package/components/cell/GridEditSingleSelectCell.js +11 -4
- package/components/columnSelection/GridCellCheckboxRenderer.js +5 -0
- package/components/containers/GridRoot.js +4 -2
- package/components/toolbar/GridToolbarDensitySelector.js +13 -4
- package/components/toolbar/GridToolbarExportContainer.js +13 -2
- package/constants/envConstants.d.ts +1 -1
- package/constants/envConstants.js +2 -11
- package/constants/gridClasses.d.ts +16 -0
- package/constants/gridClasses.js +1 -1
- package/constants/localeTextConstants.js +1 -1
- package/hooks/features/dimensions/useGridDimensions.js +6 -1
- package/hooks/features/editRows/useGridCellEditing.new.d.ts +1 -1
- package/hooks/features/editRows/useGridCellEditing.new.js +26 -16
- package/hooks/features/editRows/useGridCellEditing.old.js +2 -2
- package/hooks/features/editRows/useGridEditing.new.d.ts +1 -1
- package/hooks/features/editRows/useGridEditing.new.js +4 -0
- package/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/hooks/features/editRows/useGridRowEditing.new.d.ts +1 -1
- package/hooks/features/editRows/useGridRowEditing.new.js +16 -10
- package/hooks/features/export/utils.js +8 -1
- package/hooks/features/filter/gridFilterState.d.ts +12 -1
- package/hooks/features/filter/gridFilterUtils.d.ts +8 -5
- package/hooks/features/filter/gridFilterUtils.js +74 -43
- package/hooks/features/filter/useGridFilter.js +16 -3
- package/hooks/features/focus/useGridFocus.js +11 -6
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +42 -34
- package/hooks/features/pagination/useGridPageSize.js +3 -1
- package/hooks/features/rows/gridRowsSelector.d.ts +14 -0
- package/hooks/features/rows/gridRowsSelector.js +20 -1
- package/hooks/features/rows/gridRowsState.d.ts +8 -1
- package/hooks/features/rows/gridRowsUtils.d.ts +4 -0
- package/hooks/features/rows/gridRowsUtils.js +21 -3
- package/hooks/features/rows/index.d.ts +1 -1
- package/hooks/features/rows/index.js +1 -1
- package/hooks/features/rows/useGridRows.js +5 -2
- package/hooks/features/rows/useGridRowsMeta.js +19 -4
- package/hooks/features/rows/useGridRowsPreProcessors.js +2 -1
- package/hooks/features/scroll/useGridScroll.js +7 -2
- package/hooks/features/selection/useGridSelection.js +7 -3
- package/hooks/features/sorting/useGridSorting.js +8 -0
- package/hooks/features/statePersistence/gridStatePersistenceInterface.d.ts +3 -0
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +3 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +31 -16
- package/index.js +1 -1
- package/internals/index.d.ts +5 -1
- package/internals/index.js +4 -0
- package/legacy/DataGrid/DataGrid.js +7 -1
- package/legacy/DataGrid/useDataGridProps.js +1 -0
- package/legacy/colDef/gridStringColDef.js +1 -1
- package/legacy/components/GridRow.js +5 -1
- package/legacy/components/base/GridOverlays.js +2 -2
- package/legacy/components/cell/GridEditInputCell.js +13 -14
- package/legacy/components/cell/GridEditSingleSelectCell.js +11 -3
- package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +5 -0
- package/legacy/components/containers/GridRoot.js +4 -2
- package/legacy/components/toolbar/GridToolbarDensitySelector.js +14 -5
- package/legacy/components/toolbar/GridToolbarExportContainer.js +15 -2
- package/legacy/constants/envConstants.js +2 -11
- package/legacy/constants/gridClasses.js +1 -1
- package/legacy/constants/localeTextConstants.js +1 -1
- package/legacy/hooks/features/dimensions/useGridDimensions.js +6 -1
- package/legacy/hooks/features/editRows/useGridCellEditing.new.js +27 -17
- package/legacy/hooks/features/editRows/useGridCellEditing.old.js +2 -2
- package/legacy/hooks/features/editRows/useGridEditing.new.js +4 -0
- package/legacy/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/legacy/hooks/features/editRows/useGridRowEditing.new.js +16 -10
- package/legacy/hooks/features/export/utils.js +13 -1
- package/legacy/hooks/features/filter/gridFilterUtils.js +84 -55
- package/legacy/hooks/features/filter/useGridFilter.js +16 -3
- package/legacy/hooks/features/focus/useGridFocus.js +11 -6
- package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +47 -34
- package/legacy/hooks/features/pagination/useGridPageSize.js +3 -1
- package/legacy/hooks/features/rows/gridRowsSelector.js +23 -0
- package/legacy/hooks/features/rows/gridRowsUtils.js +21 -3
- package/legacy/hooks/features/rows/index.js +1 -1
- package/legacy/hooks/features/rows/useGridRows.js +5 -2
- package/legacy/hooks/features/rows/useGridRowsMeta.js +19 -4
- package/legacy/hooks/features/rows/useGridRowsPreProcessors.js +2 -1
- package/legacy/hooks/features/scroll/useGridScroll.js +7 -2
- package/legacy/hooks/features/selection/useGridSelection.js +7 -3
- package/legacy/hooks/features/sorting/useGridSorting.js +8 -0
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +32 -16
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +4 -0
- package/legacy/locales/arSD.js +1 -1
- package/legacy/locales/bgBG.js +1 -1
- package/legacy/locales/csCZ.js +1 -1
- package/legacy/locales/daDK.js +1 -1
- package/legacy/locales/deDE.js +9 -9
- package/legacy/locales/elGR.js +1 -1
- package/legacy/locales/esES.js +1 -1
- package/legacy/locales/faIR.js +1 -1
- package/legacy/locales/fiFI.js +1 -1
- package/legacy/locales/frFR.js +1 -1
- package/legacy/locales/heIL.js +1 -1
- package/legacy/locales/huHU.js +1 -1
- package/legacy/locales/itIT.js +15 -15
- package/legacy/locales/jaJP.js +3 -3
- package/legacy/locales/koKR.js +34 -30
- package/legacy/locales/nbNO.js +1 -1
- package/legacy/locales/nlNL.js +1 -1
- package/legacy/locales/plPL.js +1 -1
- package/legacy/locales/ptBR.js +1 -1
- package/legacy/locales/roRO.js +1 -1
- package/legacy/locales/ruRU.js +1 -1
- package/legacy/locales/skSK.js +1 -1
- package/legacy/locales/svSE.js +1 -1
- package/legacy/locales/trTR.js +1 -1
- package/legacy/locales/ukUA.js +1 -1
- package/legacy/locales/viVN.js +1 -1
- package/legacy/locales/zhCN.js +37 -33
- package/legacy/locales/zhTW.js +1 -1
- package/legacy/utils/keyboardUtils.js +8 -5
- package/locales/arSD.js +1 -1
- package/locales/bgBG.js +1 -1
- package/locales/csCZ.js +1 -1
- package/locales/daDK.js +1 -1
- package/locales/deDE.js +9 -9
- package/locales/elGR.js +1 -1
- package/locales/esES.js +1 -1
- package/locales/faIR.js +1 -1
- package/locales/fiFI.js +1 -1
- package/locales/frFR.js +1 -1
- package/locales/heIL.js +1 -1
- package/locales/huHU.js +1 -1
- package/locales/itIT.js +15 -15
- package/locales/jaJP.js +3 -3
- package/locales/koKR.js +30 -30
- package/locales/nbNO.js +1 -1
- package/locales/nlNL.js +1 -1
- package/locales/plPL.js +1 -1
- package/locales/ptBR.js +1 -1
- package/locales/roRO.js +1 -1
- package/locales/ruRU.js +1 -1
- package/locales/skSK.js +1 -1
- package/locales/svSE.js +1 -1
- package/locales/trTR.js +1 -1
- package/locales/ukUA.js +1 -1
- package/locales/viVN.js +1 -1
- package/locales/zhCN.js +33 -33
- package/locales/zhTW.js +1 -1
- package/models/gridRows.d.ts +5 -0
- package/models/props/DataGridProps.d.ts +8 -3
- package/modern/DataGrid/DataGrid.js +7 -1
- package/modern/DataGrid/useDataGridProps.js +1 -0
- package/modern/colDef/gridStringColDef.js +1 -1
- package/modern/components/GridRow.js +5 -1
- package/modern/components/base/GridOverlays.js +2 -2
- package/modern/components/cell/GridEditInputCell.js +13 -14
- package/modern/components/cell/GridEditSingleSelectCell.js +11 -4
- package/modern/components/columnSelection/GridCellCheckboxRenderer.js +5 -0
- package/modern/components/containers/GridRoot.js +4 -2
- package/modern/components/toolbar/GridToolbarDensitySelector.js +11 -4
- package/modern/components/toolbar/GridToolbarExportContainer.js +11 -2
- package/modern/constants/envConstants.js +2 -11
- package/modern/constants/gridClasses.js +1 -1
- package/modern/constants/localeTextConstants.js +1 -1
- package/modern/hooks/features/dimensions/useGridDimensions.js +6 -1
- package/modern/hooks/features/editRows/useGridCellEditing.new.js +24 -16
- package/modern/hooks/features/editRows/useGridCellEditing.old.js +2 -2
- package/modern/hooks/features/editRows/useGridEditing.new.js +4 -0
- package/modern/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/modern/hooks/features/editRows/useGridRowEditing.new.js +16 -10
- package/modern/hooks/features/export/utils.js +6 -1
- package/modern/hooks/features/filter/gridFilterUtils.js +73 -42
- package/modern/hooks/features/filter/useGridFilter.js +16 -3
- package/modern/hooks/features/focus/useGridFocus.js +11 -6
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +42 -30
- package/modern/hooks/features/pagination/useGridPageSize.js +3 -1
- package/modern/hooks/features/rows/gridRowsSelector.js +18 -1
- package/modern/hooks/features/rows/gridRowsUtils.js +19 -3
- package/modern/hooks/features/rows/index.js +1 -1
- package/modern/hooks/features/rows/useGridRows.js +5 -2
- package/modern/hooks/features/rows/useGridRowsMeta.js +17 -4
- package/modern/hooks/features/rows/useGridRowsPreProcessors.js +2 -1
- package/modern/hooks/features/scroll/useGridScroll.js +5 -2
- package/modern/hooks/features/selection/useGridSelection.js +7 -1
- package/modern/hooks/features/sorting/useGridSorting.js +8 -0
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +30 -15
- package/modern/index.js +1 -1
- package/modern/internals/index.js +4 -0
- package/modern/locales/arSD.js +1 -1
- package/modern/locales/bgBG.js +1 -1
- package/modern/locales/csCZ.js +1 -1
- package/modern/locales/daDK.js +1 -1
- package/modern/locales/deDE.js +9 -9
- package/modern/locales/elGR.js +1 -1
- package/modern/locales/esES.js +1 -1
- package/modern/locales/faIR.js +1 -1
- package/modern/locales/fiFI.js +1 -1
- package/modern/locales/frFR.js +1 -1
- package/modern/locales/heIL.js +1 -1
- package/modern/locales/huHU.js +1 -1
- package/modern/locales/itIT.js +15 -15
- package/modern/locales/jaJP.js +3 -3
- package/modern/locales/koKR.js +30 -30
- package/modern/locales/nbNO.js +1 -1
- package/modern/locales/nlNL.js +1 -1
- package/modern/locales/plPL.js +1 -1
- package/modern/locales/ptBR.js +1 -1
- package/modern/locales/roRO.js +1 -1
- package/modern/locales/ruRU.js +1 -1
- package/modern/locales/skSK.js +1 -1
- package/modern/locales/svSE.js +1 -1
- package/modern/locales/trTR.js +1 -1
- package/modern/locales/ukUA.js +1 -1
- package/modern/locales/viVN.js +1 -1
- package/modern/locales/zhCN.js +33 -33
- package/modern/locales/zhTW.js +1 -1
- package/modern/utils/keyboardUtils.js +7 -2
- package/node/DataGrid/DataGrid.js +7 -1
- package/node/DataGrid/useDataGridProps.js +1 -0
- package/node/colDef/gridStringColDef.js +1 -1
- package/node/components/GridRow.js +5 -1
- package/node/components/base/GridOverlays.js +2 -2
- package/node/components/cell/GridEditInputCell.js +15 -16
- package/node/components/cell/GridEditSingleSelectCell.js +10 -4
- package/node/components/columnSelection/GridCellCheckboxRenderer.js +5 -0
- package/node/components/containers/GridRoot.js +3 -1
- package/node/components/toolbar/GridToolbarDensitySelector.js +13 -4
- package/node/components/toolbar/GridToolbarExportContainer.js +13 -2
- package/node/constants/envConstants.js +2 -13
- package/node/constants/gridClasses.js +1 -1
- package/node/constants/localeTextConstants.js +1 -1
- package/node/hooks/features/dimensions/useGridDimensions.js +7 -1
- package/node/hooks/features/editRows/useGridCellEditing.new.js +26 -16
- package/node/hooks/features/editRows/useGridCellEditing.old.js +2 -2
- package/node/hooks/features/editRows/useGridEditing.new.js +4 -0
- package/node/hooks/features/editRows/useGridEditing.old.js +1 -1
- package/node/hooks/features/editRows/useGridRowEditing.new.js +16 -10
- package/node/hooks/features/export/utils.js +7 -0
- package/node/hooks/features/filter/gridFilterUtils.js +81 -47
- package/node/hooks/features/filter/useGridFilter.js +15 -2
- package/node/hooks/features/focus/useGridFocus.js +11 -6
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +43 -34
- package/node/hooks/features/pagination/useGridPageSize.js +4 -1
- package/node/hooks/features/rows/gridRowsSelector.js +24 -2
- package/node/hooks/features/rows/gridRowsUtils.js +23 -2
- package/node/hooks/features/rows/index.js +70 -12
- package/node/hooks/features/rows/useGridRows.js +5 -2
- package/node/hooks/features/rows/useGridRowsMeta.js +20 -4
- package/node/hooks/features/rows/useGridRowsPreProcessors.js +2 -1
- package/node/hooks/features/scroll/useGridScroll.js +7 -1
- package/node/hooks/features/selection/useGridSelection.js +7 -3
- package/node/hooks/features/sorting/useGridSorting.js +8 -0
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +31 -16
- package/node/index.js +1 -1
- package/node/internals/index.js +36 -0
- package/node/locales/arSD.js +1 -1
- package/node/locales/bgBG.js +1 -1
- package/node/locales/csCZ.js +1 -1
- package/node/locales/daDK.js +1 -1
- package/node/locales/deDE.js +9 -9
- package/node/locales/elGR.js +1 -1
- package/node/locales/esES.js +1 -1
- package/node/locales/faIR.js +1 -1
- package/node/locales/fiFI.js +1 -1
- package/node/locales/frFR.js +1 -1
- package/node/locales/heIL.js +1 -1
- package/node/locales/huHU.js +1 -1
- package/node/locales/itIT.js +15 -15
- package/node/locales/jaJP.js +3 -3
- package/node/locales/koKR.js +30 -30
- package/node/locales/nbNO.js +1 -1
- package/node/locales/nlNL.js +1 -1
- package/node/locales/plPL.js +1 -1
- package/node/locales/ptBR.js +1 -1
- package/node/locales/roRO.js +1 -1
- package/node/locales/ruRU.js +1 -1
- package/node/locales/skSK.js +1 -1
- package/node/locales/svSE.js +1 -1
- package/node/locales/trTR.js +1 -1
- package/node/locales/ukUA.js +1 -1
- package/node/locales/viVN.js +1 -1
- package/node/locales/zhCN.js +33 -33
- package/node/locales/zhTW.js +1 -1
- package/node/utils/keyboardUtils.js +10 -4
- package/package.json +1 -1
- package/utils/keyboardUtils.d.ts +2 -2
- package/utils/keyboardUtils.js +7 -2
|
@@ -8,6 +8,7 @@ import { gridDensityHeaderHeightSelector, gridDensityRowHeightSelector } from '.
|
|
|
8
8
|
import { useGridSelector } from '../../utils';
|
|
9
9
|
import { getVisibleRows } from '../../utils/useGridVisibleRows';
|
|
10
10
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
11
|
+
import { calculatePinnedRowsHeight } from '../rows/gridRowsUtils';
|
|
11
12
|
const isTestEnvironment = process.env.NODE_ENV === 'test';
|
|
12
13
|
|
|
13
14
|
const hasScroll = ({
|
|
@@ -47,6 +48,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
47
48
|
|
|
48
49
|
const rootElement = (_apiRef$current$rootE = apiRef.current.rootElementRef) == null ? void 0 : _apiRef$current$rootE.current;
|
|
49
50
|
const columnsTotalWidth = gridColumnsTotalWidthSelector(apiRef);
|
|
51
|
+
const pinnedRowsHeight = calculatePinnedRowsHeight(apiRef);
|
|
50
52
|
|
|
51
53
|
if (!rootDimensionsRef.current) {
|
|
52
54
|
return;
|
|
@@ -92,7 +94,10 @@ export function useGridDimensions(apiRef, props) {
|
|
|
92
94
|
width: Math.round(columnsTotalWidth),
|
|
93
95
|
height: rowsMeta.currentPageTotalHeight
|
|
94
96
|
},
|
|
95
|
-
container:
|
|
97
|
+
container: {
|
|
98
|
+
width: viewportOuterSize.width,
|
|
99
|
+
height: viewportOuterSize.height - pinnedRowsHeight.top - pinnedRowsHeight.bottom
|
|
100
|
+
},
|
|
96
101
|
scrollBarSize
|
|
97
102
|
});
|
|
98
103
|
hasScrollY = scrollInformation.hasScrollY;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
|
-
export declare const useGridCellEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onCellEditStart' | 'onCellEditStop' | 'cellModesModel' | 'onCellModesModelChange' | 'onProcessRowUpdateError' | 'signature'>) => void;
|
|
4
|
+
export declare const useGridCellEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onCellEditStart' | 'onCellEditStop' | 'cellModesModel' | 'onCellModesModelChange' | 'onProcessRowUpdateError' | 'signature' | 'disableIgnoreModificationsIfProcessingProps'>) => void;
|
|
@@ -15,6 +15,7 @@ import { GridCellEditStartReasons, GridCellEditStopReasons } from '../../../mode
|
|
|
15
15
|
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
16
|
export const useGridCellEditing = (apiRef, props) => {
|
|
17
17
|
const [cellModesModel, setCellModesModel] = React.useState({});
|
|
18
|
+
const cellModesModelRef = React.useRef(cellModesModel);
|
|
18
19
|
const prevCellModesModel = React.useRef({});
|
|
19
20
|
const {
|
|
20
21
|
processRowUpdate,
|
|
@@ -62,6 +63,10 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
if (apiRef.current.getCellMode(params.id, params.field) === GridCellModes.View) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
65
70
|
const newParams = _extends({}, params, {
|
|
66
71
|
reason: GridCellEditStopReasons.cellFocusOut
|
|
67
72
|
});
|
|
@@ -97,15 +102,14 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
97
102
|
} else if (params.isEditable) {
|
|
98
103
|
let reason;
|
|
99
104
|
|
|
100
|
-
if (isPrintableKey(event
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
+
if (isPrintableKey(event)) {
|
|
106
|
+
reason = GridCellEditStartReasons.printableKeyDown;
|
|
107
|
+
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
|
|
105
108
|
reason = GridCellEditStartReasons.printableKeyDown;
|
|
106
109
|
} else if (event.key === 'Enter') {
|
|
107
110
|
reason = GridCellEditStartReasons.enterKeyDown;
|
|
108
|
-
} else if (event.key === 'Delete') {
|
|
111
|
+
} else if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
112
|
+
// Delete on Windows, Backspace on macOS
|
|
109
113
|
reason = GridCellEditStartReasons.deleteKeyDown;
|
|
110
114
|
}
|
|
111
115
|
|
|
@@ -141,6 +145,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
141
145
|
field,
|
|
142
146
|
reason
|
|
143
147
|
} = params;
|
|
148
|
+
apiRef.current.unstable_runPendingEditCellValueMutation(id, field);
|
|
144
149
|
let cellToFocusAfter;
|
|
145
150
|
|
|
146
151
|
if (reason === GridCellEditStopReasons.enterKeyDown) {
|
|
@@ -154,7 +159,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
154
159
|
let ignoreModifications = reason === 'escapeKeyDown';
|
|
155
160
|
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
156
161
|
|
|
157
|
-
if (editingState[id][field].isProcessingProps) {
|
|
162
|
+
if (editingState[id][field].isProcessingProps && !props.disableIgnoreModificationsIfProcessingProps) {
|
|
158
163
|
// The user wants to stop editing the cell but we can't wait for the props to be processed.
|
|
159
164
|
// In this case, discard the modifications.
|
|
160
165
|
ignoreModifications = true;
|
|
@@ -166,7 +171,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
166
171
|
ignoreModifications,
|
|
167
172
|
cellToFocusAfter
|
|
168
173
|
});
|
|
169
|
-
}, [apiRef]);
|
|
174
|
+
}, [apiRef, props.disableIgnoreModificationsIfProcessingProps]);
|
|
170
175
|
useGridApiEventHandler(apiRef, 'cellDoubleClick', runIfEditModeIsCell(handleCellDoubleClick));
|
|
171
176
|
useGridApiEventHandler(apiRef, 'cellFocusOut', runIfEditModeIsCell(handleCellFocusOut));
|
|
172
177
|
useGridApiEventHandler(apiRef, 'cellKeyDown', runIfEditModeIsCell(handleCellKeyDown));
|
|
@@ -194,18 +199,21 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
194
199
|
}
|
|
195
200
|
|
|
196
201
|
setCellModesModel(newModel);
|
|
202
|
+
cellModesModelRef.current = newModel;
|
|
197
203
|
apiRef.current.publishEvent('cellModesModelChange', newModel);
|
|
198
204
|
}, [apiRef, onCellModesModelChange, props.cellModesModel, signature]);
|
|
199
205
|
const updateFieldInCellModesModel = React.useCallback((id, field, newProps) => {
|
|
200
|
-
|
|
206
|
+
// We use the ref because it always contain the up-to-date value, different from the state
|
|
207
|
+
// that needs a rerender to reflect the new value
|
|
208
|
+
const newModel = _extends({}, cellModesModelRef.current);
|
|
201
209
|
|
|
202
210
|
if (newProps !== null) {
|
|
203
211
|
newModel[id] = _extends({}, newModel[id], {
|
|
204
212
|
[field]: _extends({}, newProps)
|
|
205
213
|
});
|
|
206
214
|
} else {
|
|
207
|
-
const
|
|
208
|
-
otherFields = _objectWithoutPropertiesLoose(
|
|
215
|
+
const _newModel$id = newModel[id],
|
|
216
|
+
otherFields = _objectWithoutPropertiesLoose(_newModel$id, [field].map(_toPropertyKey)); // Ensure that we have a new object, not a reference
|
|
209
217
|
|
|
210
218
|
|
|
211
219
|
newModel[id] = otherFields;
|
|
@@ -216,7 +224,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
216
224
|
}
|
|
217
225
|
|
|
218
226
|
updateCellModesModel(newModel);
|
|
219
|
-
}, [
|
|
227
|
+
}, [updateCellModesModel]);
|
|
220
228
|
const updateOrDeleteFieldState = React.useCallback((id, field, newProps) => {
|
|
221
229
|
apiRef.current.setState(state => {
|
|
222
230
|
const newEditingState = _extends({}, state.editRows);
|
|
@@ -289,12 +297,12 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
289
297
|
apiRef.current.unstable_runPendingEditCellValueMutation(id, field);
|
|
290
298
|
|
|
291
299
|
const finishCellEditMode = () => {
|
|
300
|
+
updateOrDeleteFieldState(id, field, null);
|
|
301
|
+
updateFieldInCellModesModel(id, field, null);
|
|
302
|
+
|
|
292
303
|
if (cellToFocusAfter !== 'none') {
|
|
293
304
|
apiRef.current.unstable_moveFocusToRelativeCell(id, field, cellToFocusAfter);
|
|
294
305
|
}
|
|
295
|
-
|
|
296
|
-
updateOrDeleteFieldState(id, field, null);
|
|
297
|
-
updateFieldInCellModesModel(id, field, null);
|
|
298
306
|
};
|
|
299
307
|
|
|
300
308
|
if (ignoreModifications) {
|
|
@@ -343,6 +351,8 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
343
351
|
}
|
|
344
352
|
}, [apiRef, onProcessRowUpdateError, processRowUpdate, throwIfNotInMode, updateFieldInCellModesModel, updateOrDeleteFieldState]);
|
|
345
353
|
const setCellEditingEditCellValue = React.useCallback(async params => {
|
|
354
|
+
var _editingState$id, _editingState$id$fiel;
|
|
355
|
+
|
|
346
356
|
const {
|
|
347
357
|
id,
|
|
348
358
|
field,
|
|
@@ -394,7 +404,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
394
404
|
newProps.value = column.preProcessEditCellProps ? editingState[id][field].value : parsedValue;
|
|
395
405
|
updateOrDeleteFieldState(id, field, newProps);
|
|
396
406
|
editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
397
|
-
return !editingState[id][field].error;
|
|
407
|
+
return !((_editingState$id = editingState[id]) != null && (_editingState$id$fiel = _editingState$id[field]) != null && _editingState$id$fiel.error);
|
|
398
408
|
}, [apiRef, throwIfNotEditable, throwIfNotInMode, updateOrDeleteFieldState]);
|
|
399
409
|
const getRowWithUpdatedValuesFromCellEditing = React.useCallback((id, field) => {
|
|
400
410
|
const column = apiRef.current.getColumn(field);
|
|
@@ -199,7 +199,7 @@ export const useCellEditing = (apiRef, props) => {
|
|
|
199
199
|
const isEditMode = cellMode === GridCellModes.Edit;
|
|
200
200
|
const isModifierKeyPressed = event.ctrlKey || event.metaKey || event.altKey;
|
|
201
201
|
|
|
202
|
-
if (!isEditMode && isCellEnterEditModeKeys(event
|
|
202
|
+
if (!isEditMode && isCellEnterEditModeKeys(event) && !isModifierKeyPressed && !(event.key === ' ' && event.shiftKey)) {
|
|
203
203
|
apiRef.current.publishEvent('cellEditStart', params, event);
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -269,7 +269,7 @@ export const useCellEditing = (apiRef, props) => {
|
|
|
269
269
|
|
|
270
270
|
apiRef.current.setCellMode(params.id, params.field, GridCellModes.Edit);
|
|
271
271
|
|
|
272
|
-
if (isKeyboardEvent(event) && isPrintableKey(event
|
|
272
|
+
if (isKeyboardEvent(event) && isPrintableKey(event)) {
|
|
273
273
|
apiRef.current.unstable_setEditCellProps({
|
|
274
274
|
id: params.id,
|
|
275
275
|
field: params.field,
|
|
@@ -3,4 +3,4 @@ import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
4
|
import { GridStateInitializer } from '../../utils/useGridInitializeState';
|
|
5
5
|
export declare const editingStateInitializer: GridStateInitializer;
|
|
6
|
-
export declare const useGridEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'isCellEditable' | 'editMode' | 'processRowUpdate'>) => void;
|
|
6
|
+
export declare const useGridEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'isCellEditable' | 'editMode' | 'processRowUpdate' | 'disableIgnoreModificationsIfProcessingProps'>) => void;
|
|
@@ -30,7 +30,7 @@ export function useGridEditing(apiRef, props) {
|
|
|
30
30
|
stateSelector: gridEditRowsStateSelector,
|
|
31
31
|
changeEvent: 'editRowsModelChange'
|
|
32
32
|
});
|
|
33
|
-
const isCellEditable = React.useCallback(params => !params.rowNode.isAutoGenerated && !!params.colDef.editable && !!params.colDef.renderEditCell && (!props.isCellEditable || props.isCellEditable(params)), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
const isCellEditable = React.useCallback(params => !params.rowNode.isAutoGenerated && !params.rowNode.isPinned && !!params.colDef.editable && !!params.colDef.renderEditCell && (!props.isCellEditable || props.isCellEditable(params)), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
34
|
[props.isCellEditable]);
|
|
35
35
|
|
|
36
36
|
const maybeDebounce = (id, field, debounceMs, callback) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
|
-
export declare const useGridRowEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onRowEditStart' | 'onRowEditStop' | 'onProcessRowUpdateError' | 'rowModesModel' | 'onRowModesModelChange' | 'signature'>) => void;
|
|
4
|
+
export declare const useGridRowEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onRowEditStart' | 'onRowEditStop' | 'onProcessRowUpdateError' | 'rowModesModel' | 'onRowModesModelChange' | 'signature' | 'disableIgnoreModificationsIfProcessingProps'>) => void;
|
|
@@ -16,6 +16,7 @@ import { GridRowEditStopReasons, GridRowEditStartReasons } from '../../../models
|
|
|
16
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');
|
|
17
17
|
export const useGridRowEditing = (apiRef, props) => {
|
|
18
18
|
const [rowModesModel, setRowModesModel] = React.useState({});
|
|
19
|
+
const rowModesModelRef = React.useRef(rowModesModel);
|
|
19
20
|
const prevRowModesModel = React.useRef({});
|
|
20
21
|
const focusTimeout = React.useRef(null);
|
|
21
22
|
const nextFocusedCell = React.useRef(null);
|
|
@@ -90,6 +91,11 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
90
91
|
// The row might have been deleted during the click
|
|
91
92
|
if (!apiRef.current.getRow(params.id)) {
|
|
92
93
|
return;
|
|
94
|
+
} // The row may already changed its mode
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if (apiRef.current.getRowMode(params.id) === GridRowModes.View) {
|
|
98
|
+
return;
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
const rowParams = apiRef.current.getRowParams(params.id);
|
|
@@ -153,15 +159,14 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
153
159
|
} else if (params.isEditable) {
|
|
154
160
|
let reason;
|
|
155
161
|
|
|
156
|
-
if (isPrintableKey(event
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
162
|
+
if (isPrintableKey(event)) {
|
|
163
|
+
reason = GridRowEditStartReasons.printableKeyDown;
|
|
164
|
+
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
|
|
161
165
|
reason = GridRowEditStartReasons.printableKeyDown;
|
|
162
166
|
} else if (event.key === 'Enter') {
|
|
163
167
|
reason = GridRowEditStartReasons.enterKeyDown;
|
|
164
|
-
} else if (event.key === 'Delete') {
|
|
168
|
+
} else if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
169
|
+
// Delete on Windows, Backspace on macOS
|
|
165
170
|
reason = GridRowEditStartReasons.deleteKeyDown;
|
|
166
171
|
}
|
|
167
172
|
|
|
@@ -214,7 +219,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
214
219
|
let ignoreModifications = reason === 'escapeKeyDown';
|
|
215
220
|
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
216
221
|
|
|
217
|
-
if (!ignoreModifications) {
|
|
222
|
+
if (!ignoreModifications && !props.disableIgnoreModificationsIfProcessingProps) {
|
|
218
223
|
// The user wants to stop editing the cell but we can't wait for the props to be processed.
|
|
219
224
|
// In this case, discard the modifications if any field is processing its props.
|
|
220
225
|
ignoreModifications = Object.values(editingState[id]).some(fieldProps => {
|
|
@@ -228,7 +233,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
228
233
|
field,
|
|
229
234
|
cellToFocusAfter
|
|
230
235
|
});
|
|
231
|
-
}, [apiRef]);
|
|
236
|
+
}, [apiRef, props.disableIgnoreModificationsIfProcessingProps]);
|
|
232
237
|
useGridApiEventHandler(apiRef, 'cellDoubleClick', runIfEditModeIsRow(handleCellDoubleClick));
|
|
233
238
|
useGridApiEventHandler(apiRef, 'cellFocusIn', runIfEditModeIsRow(handleCellFocusIn));
|
|
234
239
|
useGridApiEventHandler(apiRef, 'cellFocusOut', runIfEditModeIsRow(handleCellFocusOut));
|
|
@@ -261,10 +266,11 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
261
266
|
}
|
|
262
267
|
|
|
263
268
|
setRowModesModel(newModel);
|
|
269
|
+
rowModesModelRef.current = newModel;
|
|
264
270
|
apiRef.current.publishEvent('rowModesModelChange', newModel);
|
|
265
271
|
}, [apiRef, onRowModesModelChange, props.rowModesModel, signature]);
|
|
266
272
|
const updateRowInRowModesModel = React.useCallback((id, newProps) => {
|
|
267
|
-
const newModel = _extends({},
|
|
273
|
+
const newModel = _extends({}, rowModesModelRef.current);
|
|
268
274
|
|
|
269
275
|
if (newProps !== null) {
|
|
270
276
|
newModel[id] = _extends({}, newProps);
|
|
@@ -273,7 +279,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
273
279
|
}
|
|
274
280
|
|
|
275
281
|
updateRowModesModel(newModel);
|
|
276
|
-
}, [
|
|
282
|
+
}, [updateRowModesModel]);
|
|
277
283
|
const updateOrDeleteRowState = React.useCallback((id, newProps) => {
|
|
278
284
|
apiRef.current.setState(state => {
|
|
279
285
|
const newEditingState = _extends({}, state.editRows);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { gridColumnDefinitionsSelector, gridVisibleColumnDefinitionsSelector } from '../columns';
|
|
2
2
|
import { gridFilteredSortedRowIdsSelector } from '../filter';
|
|
3
|
-
import { gridRowTreeSelector } from '../rows/gridRowsSelector';
|
|
3
|
+
import { gridPinnedRowsSelector, gridRowTreeSelector } from '../rows/gridRowsSelector';
|
|
4
4
|
export const getColumnsToExport = ({
|
|
5
5
|
apiRef,
|
|
6
6
|
options
|
|
@@ -17,6 +17,8 @@ export const getColumnsToExport = ({
|
|
|
17
17
|
export const defaultGetRowsToExport = ({
|
|
18
18
|
apiRef
|
|
19
19
|
}) => {
|
|
20
|
+
var _pinnedRows$top, _pinnedRows$bottom;
|
|
21
|
+
|
|
20
22
|
const filteredSortedRowIds = gridFilteredSortedRowIdsSelector(apiRef);
|
|
21
23
|
const rowTree = gridRowTreeSelector(apiRef);
|
|
22
24
|
const selectedRows = apiRef.current.getSelectedRows();
|
|
@@ -25,6 +27,11 @@ export const defaultGetRowsToExport = ({
|
|
|
25
27
|
|
|
26
28
|
return ((_rowTree$id$position = rowTree[id].position) != null ? _rowTree$id$position : 'body') === 'body';
|
|
27
29
|
});
|
|
30
|
+
const pinnedRows = gridPinnedRowsSelector(apiRef);
|
|
31
|
+
const topPinnedRowsIds = (pinnedRows == null ? void 0 : (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.map(row => row.id)) || [];
|
|
32
|
+
const bottomPinnedRowsIds = (pinnedRows == null ? void 0 : (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.map(row => row.id)) || [];
|
|
33
|
+
bodyRows.unshift(...topPinnedRowsIds);
|
|
34
|
+
bodyRows.push(...bottomPinnedRowsIds);
|
|
28
35
|
|
|
29
36
|
if (selectedRows.size > 0) {
|
|
30
37
|
return bodyRows.filter(id => selectedRows.has(id));
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { GridFilterItem } from '../../../models/gridFilterItem';
|
|
1
2
|
import { GridFilterModel } from '../../../models/gridFilterModel';
|
|
2
3
|
import { GridRowId } from '../../../models/gridRows';
|
|
4
|
+
export declare type GridFilterItemResult = {
|
|
5
|
+
[key: Required<GridFilterItem>['id']]: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare type GridQuickFilterValueResult = {
|
|
8
|
+
[key: string]: boolean;
|
|
9
|
+
};
|
|
3
10
|
export declare const getDefaultGridFilterModel: () => GridFilterModel;
|
|
4
11
|
export interface GridFilterState {
|
|
5
12
|
filterModel: GridFilterModel;
|
|
@@ -31,8 +38,12 @@ export interface GridFilterInitialState {
|
|
|
31
38
|
* @param {GridRowId} rowId The id of the row we want to filter.
|
|
32
39
|
* @param {(filterItem: GridFilterItem) => boolean} shouldApplyItem An optional callback to allow the filtering engine to only apply some items.
|
|
33
40
|
*/
|
|
34
|
-
export declare type GridAggregatedFilterItemApplier = (rowId: GridRowId, shouldApplyItem?: (columnField: string) => boolean) =>
|
|
41
|
+
export declare type GridAggregatedFilterItemApplier = (rowId: GridRowId, shouldApplyItem?: (columnField: string) => boolean) => {
|
|
42
|
+
passingFilterItems: null | GridFilterItemResult;
|
|
43
|
+
passingQuickFilterValues: null | GridQuickFilterValueResult;
|
|
44
|
+
};
|
|
35
45
|
export interface GridFilteringMethodParams {
|
|
36
46
|
isRowMatchingFilters: GridAggregatedFilterItemApplier | null;
|
|
47
|
+
filterModel: GridFilterModel;
|
|
37
48
|
}
|
|
38
49
|
export declare type GridFilteringMethodValue = Omit<GridFilterState, 'filterModel'>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { GridFilterItem, GridFilterModel } from '../../../models';
|
|
2
|
+
import { GridFilterItem, GridFilterModel, GridRowId } from '../../../models';
|
|
3
3
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
4
4
|
import { GridStateCommunity } from '../../../models/gridStateCommunity';
|
|
5
|
-
import { GridAggregatedFilterItemApplier } from './gridFilterState';
|
|
5
|
+
import { GridAggregatedFilterItemApplier, GridFilterItemResult, GridQuickFilterValueResult } from './gridFilterState';
|
|
6
|
+
declare type GridFilterItemApplierNotAggregated = (rowId: GridRowId, shouldApplyItem?: (columnField: string) => boolean) => GridFilterItemResult;
|
|
6
7
|
/**
|
|
7
8
|
* Adds default values to the optional fields of a filter items.
|
|
8
9
|
* @param {GridFilterItem} item The raw filter item.
|
|
@@ -19,12 +20,14 @@ export declare const mergeStateWithFilterModel: (filterModel: GridFilterModel, d
|
|
|
19
20
|
* @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
20
21
|
* @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
|
|
21
22
|
*/
|
|
22
|
-
export declare const buildAggregatedFilterItemsApplier: (filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>) =>
|
|
23
|
+
export declare const buildAggregatedFilterItemsApplier: (filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>) => GridFilterItemApplierNotAggregated | null;
|
|
23
24
|
/**
|
|
24
25
|
* Generates a method to easily check if a row is matching the current quick filter.
|
|
25
26
|
* @param {any[]} values The model with which we want to filter the rows.
|
|
26
27
|
* @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
27
28
|
* @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
|
|
28
29
|
*/
|
|
29
|
-
export declare const buildAggregatedQuickFilterApplier: (filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>) =>
|
|
30
|
-
export declare const buildAggregatedFilterApplier: (filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>) => GridAggregatedFilterItemApplier
|
|
30
|
+
export declare const buildAggregatedQuickFilterApplier: (filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>) => GridFilterItemApplierNotAggregated | null;
|
|
31
|
+
export declare const buildAggregatedFilterApplier: (filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>) => GridAggregatedFilterItemApplier;
|
|
32
|
+
export declare const passFilterLogic: (allFilterItemResults: (null | GridFilterItemResult)[], allQuickFilterResults: (null | GridQuickFilterValueResult)[], filterModel: GridFilterModel) => boolean;
|
|
33
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { GridLinkOperator } from '../../../models';
|
|
3
|
+
import { getDefaultGridFilterModel } from './gridFilterState';
|
|
3
4
|
import { buildWarning } from '../../../utils/warning';
|
|
4
5
|
import { gridColumnFieldsSelector, gridColumnLookupSelector } from '../columns';
|
|
5
|
-
import { gridRowTreeSelector } from '../rows/gridRowsSelector';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Adds default values to the optional fields of a filter items.
|
|
@@ -78,10 +78,8 @@ export const mergeStateWithFilterModel = (filterModel, disableMultipleColumnsFil
|
|
|
78
78
|
|
|
79
79
|
export const buildAggregatedFilterItemsApplier = (filterModel, apiRef) => {
|
|
80
80
|
const {
|
|
81
|
-
items
|
|
82
|
-
linkOperator = GridLinkOperator.And
|
|
81
|
+
items
|
|
83
82
|
} = filterModel;
|
|
84
|
-
const tree = gridRowTreeSelector(apiRef);
|
|
85
83
|
|
|
86
84
|
const getFilterCallbackFromItem = filterItem => {
|
|
87
85
|
if (!filterItem.columnField || !filterItem.operatorValue) {
|
|
@@ -145,18 +143,12 @@ export const buildAggregatedFilterItemsApplier = (filterModel, apiRef) => {
|
|
|
145
143
|
}
|
|
146
144
|
|
|
147
145
|
return (rowId, shouldApplyFilter) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (linkOperator === GridLinkOperator.And) {
|
|
155
|
-
return filteredAppliers.every(applier => applier.fn(rowId));
|
|
156
|
-
} // Return `true` as soon as we have a passing filter
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return filteredAppliers.some(applier => applier.fn(rowId));
|
|
146
|
+
const resultPerItemId = {};
|
|
147
|
+
const filteredAppliers = shouldApplyFilter ? appliers.filter(applier => shouldApplyFilter(applier.item.columnField)) : appliers;
|
|
148
|
+
filteredAppliers.forEach(applier => {
|
|
149
|
+
resultPerItemId[applier.item.id] = applier.fn(rowId);
|
|
150
|
+
});
|
|
151
|
+
return resultPerItemId;
|
|
160
152
|
};
|
|
161
153
|
};
|
|
162
154
|
/**
|
|
@@ -168,8 +160,7 @@ export const buildAggregatedFilterItemsApplier = (filterModel, apiRef) => {
|
|
|
168
160
|
|
|
169
161
|
export const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
170
162
|
const {
|
|
171
|
-
quickFilterValues = []
|
|
172
|
-
quickFilterLogicOperator = GridLinkOperator.And
|
|
163
|
+
quickFilterValues = []
|
|
173
164
|
} = filterModel;
|
|
174
165
|
|
|
175
166
|
if (quickFilterValues.length === 0) {
|
|
@@ -190,6 +181,11 @@ export const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
190
181
|
}); // If some value does not have an applier we ignore them
|
|
191
182
|
|
|
192
183
|
const sanitizedQuickFilterValues = quickFilterValues.filter((value, index) => Object.keys(appliersPerColumnField).some(field => appliersPerColumnField[field][index] != null));
|
|
184
|
+
|
|
185
|
+
if (sanitizedQuickFilterValues.length === 0) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
193
189
|
return (rowId, shouldApplyFilter) => {
|
|
194
190
|
const usedCellParams = {};
|
|
195
191
|
const columnsFieldsToFilter = [];
|
|
@@ -198,10 +194,10 @@ export const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
198
194
|
usedCellParams[columnField] = apiRef.current.getCellParams(rowId, columnField);
|
|
199
195
|
columnsFieldsToFilter.push(columnField);
|
|
200
196
|
}
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
197
|
+
});
|
|
198
|
+
const quickFilterValueResult = {};
|
|
199
|
+
sanitizedQuickFilterValues.forEach((value, index) => {
|
|
200
|
+
const isPassing = columnsFieldsToFilter.some(field => {
|
|
205
201
|
var _appliersPerColumnFie, _appliersPerColumnFie2;
|
|
206
202
|
|
|
207
203
|
if (appliersPerColumnField[field][index] == null) {
|
|
@@ -209,36 +205,71 @@ export const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
209
205
|
}
|
|
210
206
|
|
|
211
207
|
return (_appliersPerColumnFie = (_appliersPerColumnFie2 = appliersPerColumnField[field])[index]) == null ? void 0 : _appliersPerColumnFie.call(_appliersPerColumnFie2, usedCellParams[field]);
|
|
212
|
-
})
|
|
213
|
-
|
|
208
|
+
});
|
|
209
|
+
quickFilterValueResult[value] = isPassing;
|
|
210
|
+
});
|
|
211
|
+
return quickFilterValueResult;
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
export const buildAggregatedFilterApplier = (filterModel, apiRef) => {
|
|
215
|
+
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, apiRef);
|
|
216
|
+
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, apiRef);
|
|
217
|
+
return (rowId, shouldApplyFilter) => ({
|
|
218
|
+
passingFilterItems: isRowMatchingFilterItems && isRowMatchingFilterItems(rowId, shouldApplyFilter),
|
|
219
|
+
passingQuickFilterValues: isRowMatchingQuickFilter && isRowMatchingQuickFilter(rowId, shouldApplyFilter)
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
export const passFilterLogic = (allFilterItemResults, allQuickFilterResults, filterModel) => {
|
|
223
|
+
var _filterModel$quickFil, _filterModel$linkOper;
|
|
214
224
|
|
|
225
|
+
const cleanedAllFilterItemResults = allFilterItemResults.filter(result => result != null);
|
|
226
|
+
const cleanedAllQuickFilterResults = allQuickFilterResults.filter(result => result != null); // Defaultize operators
|
|
215
227
|
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
const quickFilterLogicOperator = (_filterModel$quickFil = filterModel.quickFilterLogicOperator) != null ? _filterModel$quickFil : getDefaultGridFilterModel().quickFilterLogicOperator;
|
|
229
|
+
const linkOperator = (_filterModel$linkOper = filterModel.linkOperator) != null ? _filterModel$linkOper : getDefaultGridFilterModel().linkOperator; // get result for filter items model
|
|
218
230
|
|
|
219
|
-
|
|
231
|
+
if (cleanedAllFilterItemResults.length > 0) {
|
|
232
|
+
// Return true if the item pass with one of the rows
|
|
233
|
+
const filterItemPredicate = item => {
|
|
234
|
+
return cleanedAllFilterItemResults.some(filterItemResult => filterItemResult[item.id]);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
if (linkOperator === GridLinkOperator.And) {
|
|
238
|
+
const passesAllFilters = filterModel.items.every(filterItemPredicate);
|
|
239
|
+
|
|
240
|
+
if (!passesAllFilters) {
|
|
220
241
|
return false;
|
|
221
242
|
}
|
|
243
|
+
} else {
|
|
244
|
+
const passesSomeFilters = filterModel.items.some(filterItemPredicate);
|
|
222
245
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, apiRef);
|
|
229
|
-
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, apiRef);
|
|
246
|
+
if (!passesSomeFilters) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} // get result for quick filter model
|
|
230
251
|
|
|
231
|
-
if (isRowMatchingFilterItems == null && isRowMatchingQuickFilter == null) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
252
|
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
253
|
+
if (cleanedAllQuickFilterResults.length > 0 && filterModel.quickFilterValues != null) {
|
|
254
|
+
// Return true if the item pass with one of the rows
|
|
255
|
+
const quickFilterValuePredicate = value => {
|
|
256
|
+
return cleanedAllQuickFilterResults.some(quickFilterValueResult => quickFilterValueResult[value]);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
if (quickFilterLogicOperator === GridLinkOperator.And) {
|
|
260
|
+
const passesAllQuickFilterValues = filterModel.quickFilterValues.every(quickFilterValuePredicate);
|
|
238
261
|
|
|
239
|
-
|
|
240
|
-
|
|
262
|
+
if (!passesAllQuickFilterValues) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
const passesSomeQuickFilterValues = filterModel.quickFilterValues.some(quickFilterValuePredicate);
|
|
267
|
+
|
|
268
|
+
if (!passesSomeQuickFilterValues) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
241
272
|
}
|
|
242
273
|
|
|
243
|
-
return
|
|
274
|
+
return true;
|
|
244
275
|
};
|
|
@@ -12,7 +12,7 @@ import { useFirstRender } from '../../utils/useFirstRender';
|
|
|
12
12
|
import { gridRowIdsSelector } from '../rows';
|
|
13
13
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
14
14
|
import { GRID_DEFAULT_STRATEGY, useGridRegisterStrategyProcessor } from '../../core/strategyProcessing';
|
|
15
|
-
import { buildAggregatedFilterApplier, sanitizeFilterModel, mergeStateWithFilterModel, cleanFilterItem } from './gridFilterUtils';
|
|
15
|
+
import { buildAggregatedFilterApplier, sanitizeFilterModel, mergeStateWithFilterModel, cleanFilterItem, passFilterLogic } from './gridFilterUtils';
|
|
16
16
|
import { isDeepEqual } from '../../../utils/utils';
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
18
|
export const filterStateInitializer = (state, props, apiRef) => {
|
|
@@ -49,7 +49,8 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
49
49
|
const filterModel = gridFilterModelSelector(state, apiRef.current.instanceId);
|
|
50
50
|
const isRowMatchingFilters = props.filterMode === GridFeatureModeConstant.client ? buildAggregatedFilterApplier(filterModel, apiRef) : null;
|
|
51
51
|
const filteringResult = apiRef.current.unstable_applyStrategyProcessor('filtering', {
|
|
52
|
-
isRowMatchingFilters
|
|
52
|
+
isRowMatchingFilters,
|
|
53
|
+
filterModel: filterModel != null ? filterModel : getDefaultGridFilterModel()
|
|
53
54
|
});
|
|
54
55
|
return _extends({}, state, {
|
|
55
56
|
filter: _extends({}, state.filter, filteringResult)
|
|
@@ -261,7 +262,19 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
261
262
|
|
|
262
263
|
for (let i = 0; i < rowIds.length; i += 1) {
|
|
263
264
|
const rowId = rowIds[i];
|
|
264
|
-
|
|
265
|
+
let isRowPassing;
|
|
266
|
+
|
|
267
|
+
if (typeof rowId === 'string' && rowId.startsWith('auto-generated-group-footer')) {
|
|
268
|
+
isRowPassing = true;
|
|
269
|
+
} else {
|
|
270
|
+
const {
|
|
271
|
+
passingFilterItems,
|
|
272
|
+
passingQuickFilterValues
|
|
273
|
+
} = params.isRowMatchingFilters(rowId);
|
|
274
|
+
isRowPassing = passFilterLogic([passingFilterItems], [passingQuickFilterValues], params.filterModel);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
filteredRowsLookup[rowId] = isRowPassing;
|
|
265
278
|
}
|
|
266
279
|
|
|
267
280
|
return {
|
|
@@ -60,6 +60,12 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
if (focusedCell) {
|
|
64
|
+
// There's a focused cell but another cell was clicked
|
|
65
|
+
// Publishes an event to notify that the focus was lost
|
|
66
|
+
apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(focusedCell.id, focusedCell.field));
|
|
67
|
+
}
|
|
68
|
+
|
|
63
69
|
apiRef.current.publishEvent('cellFocusIn', apiRef.current.getCellParams(id, field));
|
|
64
70
|
}, [apiRef, logger]);
|
|
65
71
|
const setColumnHeaderFocus = React.useCallback((field, event = {}) => {
|
|
@@ -191,11 +197,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
191
197
|
|
|
192
198
|
if (!apiRef.current.getRow(focusedCell.id)) {
|
|
193
199
|
return;
|
|
194
|
-
}
|
|
195
|
-
// Publishes an event to notify that the focus was lost
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(focusedCell.id, focusedCell.field), event);
|
|
200
|
+
}
|
|
199
201
|
|
|
200
202
|
if (cellParams) {
|
|
201
203
|
apiRef.current.setCellFocus(cellParams.id, cellParams.field);
|
|
@@ -206,7 +208,10 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
206
208
|
columnHeader: null
|
|
207
209
|
}
|
|
208
210
|
}));
|
|
209
|
-
apiRef.current.forceUpdate();
|
|
211
|
+
apiRef.current.forceUpdate(); // There's a focused cell but another element (not a cell) was clicked
|
|
212
|
+
// Publishes an event to notify that the focus was lost
|
|
213
|
+
|
|
214
|
+
apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(focusedCell.id, focusedCell.field), event);
|
|
210
215
|
}
|
|
211
216
|
}, [apiRef]);
|
|
212
217
|
const handleCellModeChange = React.useCallback(params => {
|