@mui/x-data-grid 7.17.0 → 7.19.0
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 +208 -5
- package/DataGrid/DataGrid.js +16 -1
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +2 -1
- package/components/GridRow.js +1 -0
- package/components/cell/GridCell.js +33 -9
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -1
- package/components/columnSelection/GridCellCheckboxRenderer.js +12 -4
- package/components/columnSelection/GridHeaderCheckbox.d.ts +1 -1
- package/components/containers/GridRoot.js +1 -1
- package/components/containers/GridRootStyles.js +32 -23
- package/components/containers/GridToolbarContainer.js +1 -1
- package/components/menu/GridMenu.js +1 -1
- package/components/panel/GridPanel.d.ts +1 -1
- package/components/panel/GridPanel.js +1 -1
- package/components/panel/GridPanelContent.js +1 -1
- package/components/panel/GridPanelFooter.js +1 -1
- package/components/panel/GridPanelHeader.js +1 -1
- package/components/panel/GridPanelWrapper.js +1 -1
- package/components/panel/filterPanel/filterPanelUtils.d.ts +1 -1
- package/components/toolbar/GridToolbarQuickFilter.js +1 -1
- package/components/virtualization/GridBottomContainer.d.ts +1 -1
- package/components/virtualization/GridBottomContainer.js +18 -1
- package/components/virtualization/GridMainContainer.js +3 -1
- package/components/virtualization/GridTopContainer.d.ts +1 -1
- package/components/virtualization/GridTopContainer.js +1 -1
- package/components/virtualization/GridVirtualScrollbar.js +1 -7
- package/components/virtualization/GridVirtualScroller.js +1 -0
- package/components/virtualization/GridVirtualScrollerFiller.js +3 -4
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.d.ts +4 -4
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -2
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/hooks/features/columnResize/columnResizeSelector.d.ts +1 -1
- package/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/hooks/features/columns/gridColumnsSelector.d.ts +12 -12
- package/hooks/features/columns/gridColumnsUtils.js +3 -2
- package/hooks/features/density/densitySelector.d.ts +1 -1
- package/hooks/features/dimensions/gridDimensionsApi.d.ts +4 -0
- package/hooks/features/dimensions/useGridDimensions.d.ts +1 -1
- package/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/hooks/features/editing/useGridCellEditing.js +3 -19
- package/hooks/features/editing/useGridRowEditing.js +7 -2
- package/hooks/features/editing/utils.d.ts +2 -0
- package/hooks/features/editing/utils.js +15 -0
- package/hooks/features/export/useGridPrintExport.js +2 -1
- package/hooks/features/filter/gridFilterSelector.d.ts +17 -17
- package/hooks/features/focus/gridFocusStateSelector.d.ts +8 -8
- package/hooks/features/focus/useGridFocus.js +2 -1
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +3 -3
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +10 -46
- package/hooks/features/keyboardNavigation/utils.d.ts +17 -0
- package/hooks/features/keyboardNavigation/utils.js +58 -0
- package/hooks/features/pagination/gridPaginationSelector.d.ts +9 -9
- package/hooks/features/rowSelection/gridRowSelectionSelector.d.ts +3 -3
- package/hooks/features/rowSelection/useGridRowSelection.d.ts +1 -1
- package/hooks/features/rowSelection/useGridRowSelection.js +105 -29
- package/hooks/features/rowSelection/utils.d.ts +10 -0
- package/hooks/features/rowSelection/utils.js +156 -1
- package/hooks/features/rows/gridRowSpanningSelectors.d.ts +4 -0
- package/hooks/features/rows/gridRowSpanningSelectors.js +5 -0
- package/hooks/features/rows/gridRowSpanningUtils.d.ts +10 -0
- package/hooks/features/rows/gridRowSpanningUtils.js +42 -0
- package/hooks/features/rows/gridRowsSelector.d.ts +14 -14
- package/hooks/features/rows/useGridRowSpanning.d.ts +27 -0
- package/hooks/features/rows/useGridRowSpanning.js +257 -0
- package/hooks/features/rows/useGridRows.d.ts +1 -1
- package/hooks/features/rows/useGridRows.js +7 -1
- package/hooks/features/scroll/useGridScroll.js +19 -19
- package/hooks/features/sorting/gridSortingSelector.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +5 -5
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +17 -7
- package/hooks/utils/useGridApiEventHandler.js +0 -1
- package/hooks/utils/useGridVisibleRows.d.ts +2 -2
- package/index.js +1 -1
- package/internals/index.d.ts +2 -0
- package/internals/index.js +2 -0
- package/locales/bgBG.js +8 -9
- package/locales/deDE.js +4 -4
- package/locales/frFR.js +4 -4
- package/locales/hrHR.d.ts +1 -1
- package/locales/hrHR.js +69 -46
- package/locales/jaJP.js +1 -2
- package/locales/ptPT.d.ts +1 -1
- package/locales/ptPT.js +4 -4
- package/locales/viVN.js +20 -20
- package/locales/zhHK.d.ts +1 -1
- package/models/colDef/gridColDef.d.ts +4 -0
- package/models/gridRowSelectionModel.d.ts +4 -0
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/props/DataGridProps.d.ts +30 -1
- package/modern/DataGrid/DataGrid.js +16 -1
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +2 -1
- package/modern/components/GridRow.js +1 -0
- package/modern/components/cell/GridCell.js +33 -9
- package/modern/components/columnHeaders/GridBaseColumnHeaders.js +1 -1
- package/modern/components/columnSelection/GridCellCheckboxRenderer.js +12 -4
- package/modern/components/containers/GridRoot.js +1 -1
- package/modern/components/containers/GridRootStyles.js +32 -23
- package/modern/components/containers/GridToolbarContainer.js +1 -1
- package/modern/components/menu/GridMenu.js +1 -1
- package/modern/components/panel/GridPanel.js +1 -1
- package/modern/components/panel/GridPanelContent.js +1 -1
- package/modern/components/panel/GridPanelFooter.js +1 -1
- package/modern/components/panel/GridPanelHeader.js +1 -1
- package/modern/components/panel/GridPanelWrapper.js +1 -1
- package/modern/components/toolbar/GridToolbarQuickFilter.js +1 -1
- package/modern/components/virtualization/GridBottomContainer.js +18 -1
- package/modern/components/virtualization/GridMainContainer.js +3 -1
- package/modern/components/virtualization/GridTopContainer.js +1 -1
- package/modern/components/virtualization/GridVirtualScrollbar.js +1 -7
- package/modern/components/virtualization/GridVirtualScroller.js +1 -0
- package/modern/components/virtualization/GridVirtualScrollerFiller.js +3 -4
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/modern/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/modern/hooks/features/columns/gridColumnsUtils.js +3 -2
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/modern/hooks/features/editing/useGridCellEditing.js +3 -19
- package/modern/hooks/features/editing/useGridRowEditing.js +7 -2
- package/modern/hooks/features/editing/utils.js +15 -0
- package/modern/hooks/features/export/useGridPrintExport.js +2 -1
- package/modern/hooks/features/focus/useGridFocus.js +2 -1
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +10 -46
- package/modern/hooks/features/keyboardNavigation/utils.js +58 -0
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +105 -29
- package/modern/hooks/features/rowSelection/utils.js +156 -1
- package/modern/hooks/features/rows/gridRowSpanningSelectors.js +5 -0
- package/modern/hooks/features/rows/gridRowSpanningUtils.js +42 -0
- package/modern/hooks/features/rows/useGridRowSpanning.js +257 -0
- package/modern/hooks/features/rows/useGridRows.js +7 -1
- package/modern/hooks/features/scroll/useGridScroll.js +19 -19
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +17 -7
- package/modern/hooks/utils/useGridApiEventHandler.js +0 -1
- package/modern/index.js +1 -1
- package/modern/internals/index.js +2 -0
- package/modern/locales/bgBG.js +8 -9
- package/modern/locales/deDE.js +4 -4
- package/modern/locales/frFR.js +4 -4
- package/modern/locales/hrHR.js +69 -46
- package/modern/locales/jaJP.js +1 -2
- package/modern/locales/ptPT.js +4 -4
- package/modern/locales/viVN.js +20 -20
- package/modern/utils/createSelector.js +6 -0
- package/modern/utils/domUtils.js +12 -12
- package/node/DataGrid/DataGrid.js +16 -1
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +2 -1
- package/node/components/GridRow.js +1 -0
- package/node/components/cell/GridCell.js +33 -9
- package/node/components/columnHeaders/GridBaseColumnHeaders.js +1 -1
- package/node/components/columnSelection/GridCellCheckboxRenderer.js +12 -4
- package/node/components/containers/GridRoot.js +1 -1
- package/node/components/containers/GridRootStyles.js +32 -23
- package/node/components/containers/GridToolbarContainer.js +1 -1
- package/node/components/menu/GridMenu.js +1 -1
- package/node/components/panel/GridPanel.js +1 -1
- package/node/components/panel/GridPanelContent.js +1 -1
- package/node/components/panel/GridPanelFooter.js +1 -1
- package/node/components/panel/GridPanelHeader.js +1 -1
- package/node/components/panel/GridPanelWrapper.js +1 -1
- package/node/components/toolbar/GridToolbarQuickFilter.js +1 -1
- package/node/components/virtualization/GridBottomContainer.js +18 -1
- package/node/components/virtualization/GridMainContainer.js +3 -1
- package/node/components/virtualization/GridTopContainer.js +1 -1
- package/node/components/virtualization/GridVirtualScrollbar.js +1 -7
- package/node/components/virtualization/GridVirtualScroller.js +1 -0
- package/node/components/virtualization/GridVirtualScrollerFiller.js +3 -4
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/node/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/node/hooks/features/columns/gridColumnsUtils.js +3 -2
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/node/hooks/features/editing/useGridCellEditing.js +3 -19
- package/node/hooks/features/editing/useGridRowEditing.js +7 -2
- package/node/hooks/features/editing/utils.js +22 -0
- package/node/hooks/features/export/useGridPrintExport.js +2 -1
- package/node/hooks/features/focus/useGridFocus.js +2 -1
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +16 -53
- package/node/hooks/features/keyboardNavigation/utils.js +68 -0
- package/node/hooks/features/rowSelection/useGridRowSelection.js +102 -26
- package/node/hooks/features/rowSelection/utils.js +160 -1
- package/node/hooks/features/rows/gridRowSpanningSelectors.js +11 -0
- package/node/hooks/features/rows/gridRowSpanningUtils.js +52 -0
- package/node/hooks/features/rows/useGridRowSpanning.js +267 -0
- package/node/hooks/features/rows/useGridRows.js +7 -1
- package/node/hooks/features/scroll/useGridScroll.js +19 -19
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +17 -7
- package/node/hooks/utils/useGridApiEventHandler.js +0 -1
- package/node/index.js +1 -1
- package/node/internals/index.js +38 -15
- package/node/locales/bgBG.js +8 -9
- package/node/locales/deDE.js +4 -4
- package/node/locales/frFR.js +4 -4
- package/node/locales/hrHR.js +69 -46
- package/node/locales/jaJP.js +1 -2
- package/node/locales/ptPT.js +4 -4
- package/node/locales/viVN.js +20 -20
- package/node/utils/createSelector.js +6 -0
- package/node/utils/domUtils.js +12 -12
- package/package.json +3 -3
- package/utils/createSelector.js +6 -0
- package/utils/domUtils.d.ts +4 -4
- package/utils/domUtils.js +12 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useRtl } from '@mui/system/RtlProvider';
|
|
3
|
-
import { gridVisibleColumnDefinitionsSelector } from "../columns/gridColumnsSelector.js";
|
|
3
|
+
import { gridVisibleColumnDefinitionsSelector, gridVisibleColumnFieldsSelector } from "../columns/gridColumnsSelector.js";
|
|
4
4
|
import { useGridLogger } from "../../utils/useGridLogger.js";
|
|
5
5
|
import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
|
|
6
6
|
import { gridExpandedSortedRowEntriesSelector } from "../filter/gridFilterSelector.js";
|
|
@@ -10,50 +10,12 @@ import { gridClasses } from "../../../constants/gridClasses.js";
|
|
|
10
10
|
import { GridCellModes } from "../../../models/gridEditRowModel.js";
|
|
11
11
|
import { isNavigationKey } from "../../../utils/keyboardUtils.js";
|
|
12
12
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "../../../constants/gridDetailPanelToggleField.js";
|
|
13
|
-
import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
|
|
14
13
|
import { gridFocusColumnGroupHeaderSelector } from "../focus/index.js";
|
|
15
14
|
import { gridColumnGroupsHeaderMaxDepthSelector } from "../columnGrouping/gridColumnGroupsSelector.js";
|
|
16
15
|
import { gridHeaderFilteringEditFieldSelector, gridHeaderFilteringMenuSelector } from "../headerFiltering/gridHeaderFilteringSelectors.js";
|
|
17
16
|
import { useGridRegisterPipeProcessor } from "../../core/pipeProcessing/index.js";
|
|
18
17
|
import { isEventTargetInPortal } from "../../../utils/domUtils.js";
|
|
19
|
-
|
|
20
|
-
const pinnedRows = gridPinnedRowsSelector(apiRef) || {};
|
|
21
|
-
return [...(pinnedRows.top || []), ...rows, ...(pinnedRows.bottom || [])];
|
|
22
|
-
}
|
|
23
|
-
const getLeftColumnIndex = ({
|
|
24
|
-
currentColIndex,
|
|
25
|
-
firstColIndex,
|
|
26
|
-
lastColIndex,
|
|
27
|
-
isRtl
|
|
28
|
-
}) => {
|
|
29
|
-
if (isRtl) {
|
|
30
|
-
if (currentColIndex < lastColIndex) {
|
|
31
|
-
return currentColIndex + 1;
|
|
32
|
-
}
|
|
33
|
-
} else if (!isRtl) {
|
|
34
|
-
if (currentColIndex > firstColIndex) {
|
|
35
|
-
return currentColIndex - 1;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
};
|
|
40
|
-
const getRightColumnIndex = ({
|
|
41
|
-
currentColIndex,
|
|
42
|
-
firstColIndex,
|
|
43
|
-
lastColIndex,
|
|
44
|
-
isRtl
|
|
45
|
-
}) => {
|
|
46
|
-
if (isRtl) {
|
|
47
|
-
if (currentColIndex > firstColIndex) {
|
|
48
|
-
return currentColIndex - 1;
|
|
49
|
-
}
|
|
50
|
-
} else if (!isRtl) {
|
|
51
|
-
if (currentColIndex < lastColIndex) {
|
|
52
|
-
return currentColIndex + 1;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
};
|
|
18
|
+
import { enrichPageRowsWithPinnedRows, getLeftColumnIndex, getRightColumnIndex, findNonRowSpannedCell } from "./utils.js";
|
|
57
19
|
|
|
58
20
|
/**
|
|
59
21
|
* @requires useGridSorting (method) - can be after
|
|
@@ -73,11 +35,12 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
73
35
|
|
|
74
36
|
/**
|
|
75
37
|
* @param {number} colIndex Index of the column to focus
|
|
76
|
-
* @param {
|
|
38
|
+
* @param {GridRowId} rowId index of the row to focus
|
|
77
39
|
* @param {string} closestColumnToUse Which closest column cell to use when the cell is spanned by `colSpan`.
|
|
40
|
+
* @param {string} rowSpanScanDirection Which direction to search to find the next cell not hidden by `rowSpan`.
|
|
78
41
|
* TODO replace with apiRef.current.moveFocusToRelativeCell()
|
|
79
42
|
*/
|
|
80
|
-
const goToCell = React.useCallback((colIndex, rowId, closestColumnToUse = 'left') => {
|
|
43
|
+
const goToCell = React.useCallback((colIndex, rowId, closestColumnToUse = 'left', rowSpanScanDirection = 'up') => {
|
|
81
44
|
const visibleSortedRows = gridExpandedSortedRowEntriesSelector(apiRef);
|
|
82
45
|
const nextCellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, colIndex);
|
|
83
46
|
if (nextCellColSpanInfo && nextCellColSpanInfo.spannedByColSpan) {
|
|
@@ -87,16 +50,17 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
87
50
|
colIndex = nextCellColSpanInfo.rightVisibleCellIndex;
|
|
88
51
|
}
|
|
89
52
|
}
|
|
53
|
+
const field = gridVisibleColumnFieldsSelector(apiRef)[colIndex];
|
|
54
|
+
const nonRowSpannedRowId = findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection);
|
|
90
55
|
// `scrollToIndexes` requires a rowIndex relative to all visible rows.
|
|
91
56
|
// Those rows do not include pinned rows, but pinned rows do not need scroll anyway.
|
|
92
|
-
const rowIndexRelativeToAllRows = visibleSortedRows.findIndex(row => row.id ===
|
|
57
|
+
const rowIndexRelativeToAllRows = visibleSortedRows.findIndex(row => row.id === nonRowSpannedRowId);
|
|
93
58
|
logger.debug(`Navigating to cell row ${rowIndexRelativeToAllRows}, col ${colIndex}`);
|
|
94
59
|
apiRef.current.scrollToIndexes({
|
|
95
60
|
colIndex,
|
|
96
61
|
rowIndex: rowIndexRelativeToAllRows
|
|
97
62
|
});
|
|
98
|
-
|
|
99
|
-
apiRef.current.setCellFocus(rowId, field);
|
|
63
|
+
apiRef.current.setCellFocus(nonRowSpannedRowId, field);
|
|
100
64
|
}, [apiRef, logger]);
|
|
101
65
|
const goToHeader = React.useCallback((colIndex, event) => {
|
|
102
66
|
logger.debug(`Navigating to header col ${colIndex}`);
|
|
@@ -432,7 +396,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
432
396
|
{
|
|
433
397
|
// "Enter" is only triggered by the row / cell editing feature
|
|
434
398
|
if (rowIndexBefore < lastRowIndexInPage) {
|
|
435
|
-
goToCell(colIndexBefore, getRowIdFromIndex(rowIndexBefore + 1));
|
|
399
|
+
goToCell(colIndexBefore, getRowIdFromIndex(rowIndexBefore + 1), isRtl ? 'right' : 'left', 'down');
|
|
436
400
|
}
|
|
437
401
|
break;
|
|
438
402
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { gridFilteredSortedRowIdsSelector } from "../filter/gridFilterSelector.js";
|
|
2
|
+
import { gridRowSpanningHiddenCellsSelector } from "../rows/gridRowSpanningSelectors.js";
|
|
3
|
+
import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
|
|
4
|
+
export function enrichPageRowsWithPinnedRows(apiRef, rows) {
|
|
5
|
+
const pinnedRows = gridPinnedRowsSelector(apiRef) || {};
|
|
6
|
+
return [...(pinnedRows.top || []), ...rows, ...(pinnedRows.bottom || [])];
|
|
7
|
+
}
|
|
8
|
+
export const getLeftColumnIndex = ({
|
|
9
|
+
currentColIndex,
|
|
10
|
+
firstColIndex,
|
|
11
|
+
lastColIndex,
|
|
12
|
+
isRtl
|
|
13
|
+
}) => {
|
|
14
|
+
if (isRtl) {
|
|
15
|
+
if (currentColIndex < lastColIndex) {
|
|
16
|
+
return currentColIndex + 1;
|
|
17
|
+
}
|
|
18
|
+
} else if (!isRtl) {
|
|
19
|
+
if (currentColIndex > firstColIndex) {
|
|
20
|
+
return currentColIndex - 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
export const getRightColumnIndex = ({
|
|
26
|
+
currentColIndex,
|
|
27
|
+
firstColIndex,
|
|
28
|
+
lastColIndex,
|
|
29
|
+
isRtl
|
|
30
|
+
}) => {
|
|
31
|
+
if (isRtl) {
|
|
32
|
+
if (currentColIndex > firstColIndex) {
|
|
33
|
+
return currentColIndex - 1;
|
|
34
|
+
}
|
|
35
|
+
} else if (!isRtl) {
|
|
36
|
+
if (currentColIndex < lastColIndex) {
|
|
37
|
+
return currentColIndex + 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
export function findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection) {
|
|
43
|
+
const rowSpanHiddenCells = gridRowSpanningHiddenCellsSelector(apiRef);
|
|
44
|
+
if (!rowSpanHiddenCells[rowId]?.[field]) {
|
|
45
|
+
return rowId;
|
|
46
|
+
}
|
|
47
|
+
const filteredSortedRowIds = gridFilteredSortedRowIdsSelector(apiRef);
|
|
48
|
+
// find closest non row spanned cell in the given `rowSpanScanDirection`
|
|
49
|
+
let nextRowIndex = filteredSortedRowIds.indexOf(rowId) + (rowSpanScanDirection === 'down' ? 1 : -1);
|
|
50
|
+
while (nextRowIndex >= 0 && nextRowIndex < filteredSortedRowIds.length) {
|
|
51
|
+
const nextRowId = filteredSortedRowIds[nextRowIndex];
|
|
52
|
+
if (!rowSpanHiddenCells[nextRowId]?.[field]) {
|
|
53
|
+
return nextRowId;
|
|
54
|
+
}
|
|
55
|
+
nextRowIndex += rowSpanScanDirection === 'down' ? 1 : -1;
|
|
56
|
+
}
|
|
57
|
+
return rowId;
|
|
58
|
+
}
|
|
@@ -3,11 +3,12 @@ import * as React from 'react';
|
|
|
3
3
|
import { GridSignature, useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
|
|
4
4
|
import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
5
5
|
import { useGridLogger } from "../../utils/useGridLogger.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useGridSelector } from "../../utils/useGridSelector.js";
|
|
7
|
+
import { gridRowMaximumTreeDepthSelector, gridRowTreeSelector } from "../rows/gridRowsSelector.js";
|
|
7
8
|
import { gridRowSelectionStateSelector, selectedGridRowsSelector, selectedIdsLookupSelector } from "./gridRowSelectionSelector.js";
|
|
8
9
|
import { gridPaginatedVisibleSortedGridRowIdsSelector } from "../pagination/index.js";
|
|
9
10
|
import { gridFocusCellSelector } from "../focus/gridFocusStateSelector.js";
|
|
10
|
-
import { gridExpandedSortedRowIdsSelector,
|
|
11
|
+
import { gridExpandedSortedRowIdsSelector, gridFilteredRowsLookupSelector } from "../filter/gridFilterSelector.js";
|
|
11
12
|
import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from "../../../colDef/index.js";
|
|
12
13
|
import { GridCellModes } from "../../../models/gridEditRowModel.js";
|
|
13
14
|
import { isKeyboardEvent, isNavigationKey } from "../../../utils/keyboardUtils.js";
|
|
@@ -15,7 +16,7 @@ import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
|
|
|
15
16
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "../../../constants/gridDetailPanelToggleField.js";
|
|
16
17
|
import { gridClasses } from "../../../constants/gridClasses.js";
|
|
17
18
|
import { isEventTargetInPortal } from "../../../utils/domUtils.js";
|
|
18
|
-
import { isMultipleRowSelectionEnabled } from "./utils.js";
|
|
19
|
+
import { isMultipleRowSelectionEnabled, findRowsToSelect, findRowsToDeselect } from "./utils.js";
|
|
19
20
|
const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
20
21
|
if (selectionModelProp == null) {
|
|
21
22
|
return selectionModelProp;
|
|
@@ -40,11 +41,12 @@ export const rowSelectionStateInitializer = (state, props) => _extends({}, state
|
|
|
40
41
|
*/
|
|
41
42
|
export const useGridRowSelection = (apiRef, props) => {
|
|
42
43
|
const logger = useGridLogger(apiRef, 'useGridSelection');
|
|
43
|
-
const runIfRowSelectionIsEnabled = callback => (...args) => {
|
|
44
|
+
const runIfRowSelectionIsEnabled = React.useCallback(callback => (...args) => {
|
|
44
45
|
if (props.rowSelection) {
|
|
45
46
|
callback(...args);
|
|
46
47
|
}
|
|
47
|
-
};
|
|
48
|
+
}, [props.rowSelection]);
|
|
49
|
+
const applyAutoSelection = props.signature !== GridSignature.DataGrid && (props.rowSelectionPropagation?.parents || props.rowSelectionPropagation?.descendants);
|
|
48
50
|
const propRowSelectionModel = React.useMemo(() => {
|
|
49
51
|
return getSelectionModelPropValue(props.rowSelectionModel, gridRowSelectionStateSelector(apiRef.current.state));
|
|
50
52
|
}, [apiRef, props.rowSelectionModel]);
|
|
@@ -63,6 +65,8 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
63
65
|
} = props;
|
|
64
66
|
const canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
|
|
65
67
|
const visibleRows = useGridVisibleRows(apiRef, props);
|
|
68
|
+
const tree = useGridSelector(apiRef, gridRowTreeSelector);
|
|
69
|
+
const isNestedData = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector) > 1;
|
|
66
70
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
67
71
|
let endId = id;
|
|
68
72
|
const startId = lastRowToggled.current ?? id;
|
|
@@ -87,7 +91,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
87
91
|
}, !isSelected);
|
|
88
92
|
}, [apiRef]);
|
|
89
93
|
|
|
90
|
-
|
|
94
|
+
/*
|
|
91
95
|
* API METHODS
|
|
92
96
|
*/
|
|
93
97
|
const setRowSelectionModel = React.useCallback(model => {
|
|
@@ -125,34 +129,80 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
125
129
|
lastRowToggled.current = id;
|
|
126
130
|
if (resetSelection) {
|
|
127
131
|
logger.debug(`Setting selection for row ${id}`);
|
|
128
|
-
|
|
132
|
+
const newSelection = [];
|
|
133
|
+
const addRow = rowId => {
|
|
134
|
+
newSelection.push(rowId);
|
|
135
|
+
};
|
|
136
|
+
if (isSelected) {
|
|
137
|
+
addRow(id);
|
|
138
|
+
if (applyAutoSelection) {
|
|
139
|
+
findRowsToSelect(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
apiRef.current.setRowSelectionModel(newSelection);
|
|
129
143
|
} else {
|
|
130
144
|
logger.debug(`Toggling selection for row ${id}`);
|
|
131
145
|
const selection = gridRowSelectionStateSelector(apiRef.current.state);
|
|
132
|
-
const newSelection = selection
|
|
146
|
+
const newSelection = new Set(selection);
|
|
147
|
+
newSelection.delete(id);
|
|
148
|
+
const addRow = rowId => {
|
|
149
|
+
newSelection.add(rowId);
|
|
150
|
+
};
|
|
151
|
+
const removeRow = rowId => {
|
|
152
|
+
newSelection.delete(rowId);
|
|
153
|
+
};
|
|
133
154
|
if (isSelected) {
|
|
134
|
-
|
|
155
|
+
addRow(id);
|
|
156
|
+
if (applyAutoSelection) {
|
|
157
|
+
findRowsToSelect(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
158
|
+
}
|
|
159
|
+
} else if (applyAutoSelection) {
|
|
160
|
+
findRowsToDeselect(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, removeRow);
|
|
135
161
|
}
|
|
136
|
-
const isSelectionValid = newSelection.
|
|
162
|
+
const isSelectionValid = newSelection.size < 2 || canHaveMultipleSelection;
|
|
137
163
|
if (isSelectionValid) {
|
|
138
|
-
apiRef.current.setRowSelectionModel(newSelection);
|
|
164
|
+
apiRef.current.setRowSelectionModel(Array.from(newSelection));
|
|
139
165
|
}
|
|
140
166
|
}
|
|
141
|
-
}, [apiRef, logger, canHaveMultipleSelection]);
|
|
167
|
+
}, [apiRef, logger, applyAutoSelection, tree, props.rowSelectionPropagation?.descendants, props.rowSelectionPropagation?.parents, canHaveMultipleSelection]);
|
|
142
168
|
const selectRows = React.useCallback((ids, isSelected = true, resetSelection = false) => {
|
|
143
169
|
logger.debug(`Setting selection for several rows`);
|
|
144
170
|
const selectableIds = ids.filter(id => apiRef.current.isRowSelectable(id));
|
|
145
171
|
let newSelection;
|
|
146
172
|
if (resetSelection) {
|
|
147
|
-
|
|
173
|
+
if (isSelected) {
|
|
174
|
+
newSelection = selectableIds;
|
|
175
|
+
if (applyAutoSelection) {
|
|
176
|
+
const addRow = rowId => {
|
|
177
|
+
newSelection.push(rowId);
|
|
178
|
+
};
|
|
179
|
+
selectableIds.forEach(id => {
|
|
180
|
+
findRowsToSelect(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
newSelection = [];
|
|
185
|
+
}
|
|
148
186
|
} else {
|
|
149
187
|
// We clone the existing object to avoid mutating the same object returned by the selector to others part of the project
|
|
150
188
|
const selectionLookup = _extends({}, selectedIdsLookupSelector(apiRef));
|
|
189
|
+
const addRow = rowId => {
|
|
190
|
+
selectionLookup[rowId] = rowId;
|
|
191
|
+
};
|
|
192
|
+
const removeRow = rowId => {
|
|
193
|
+
delete selectionLookup[rowId];
|
|
194
|
+
};
|
|
151
195
|
selectableIds.forEach(id => {
|
|
152
196
|
if (isSelected) {
|
|
153
197
|
selectionLookup[id] = id;
|
|
198
|
+
if (applyAutoSelection) {
|
|
199
|
+
findRowsToSelect(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
200
|
+
}
|
|
154
201
|
} else {
|
|
155
|
-
|
|
202
|
+
removeRow(id);
|
|
203
|
+
if (applyAutoSelection) {
|
|
204
|
+
findRowsToDeselect(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, removeRow);
|
|
205
|
+
}
|
|
156
206
|
}
|
|
157
207
|
});
|
|
158
208
|
newSelection = Object.values(selectionLookup);
|
|
@@ -161,7 +211,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
161
211
|
if (isSelectionValid) {
|
|
162
212
|
apiRef.current.setRowSelectionModel(newSelection);
|
|
163
213
|
}
|
|
164
|
-
}, [apiRef,
|
|
214
|
+
}, [logger, applyAutoSelection, canHaveMultipleSelection, apiRef, tree, props.rowSelectionPropagation?.descendants, props.rowSelectionPropagation?.parents]);
|
|
165
215
|
const selectRowRange = React.useCallback(({
|
|
166
216
|
startId,
|
|
167
217
|
endId
|
|
@@ -193,29 +243,52 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
193
243
|
useGridApiMethod(apiRef, selectionPublicApi, 'public');
|
|
194
244
|
useGridApiMethod(apiRef, selectionPrivateApi, props.signature === GridSignature.DataGrid ? 'private' : 'public');
|
|
195
245
|
|
|
196
|
-
|
|
246
|
+
/*
|
|
197
247
|
* EVENTS
|
|
198
248
|
*/
|
|
199
|
-
const removeOutdatedSelection = React.useCallback(() => {
|
|
200
|
-
if (props.keepNonExistentRowsSelected) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
249
|
+
const removeOutdatedSelection = React.useCallback((sortModelUpdated = false) => {
|
|
203
250
|
const currentSelection = gridRowSelectionStateSelector(apiRef.current.state);
|
|
204
|
-
const
|
|
251
|
+
const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
|
|
205
252
|
|
|
206
253
|
// We clone the existing object to avoid mutating the same object returned by the selector to others part of the project
|
|
207
254
|
const selectionLookup = _extends({}, selectedIdsLookupSelector(apiRef));
|
|
208
255
|
let hasChanged = false;
|
|
209
256
|
currentSelection.forEach(id => {
|
|
210
|
-
if (
|
|
257
|
+
if (filteredRowsLookup[id] === false) {
|
|
258
|
+
if (props.keepNonExistentRowsSelected) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
211
261
|
delete selectionLookup[id];
|
|
212
262
|
hasChanged = true;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (!props.rowSelectionPropagation?.parents) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const node = tree[id];
|
|
269
|
+
if (node.type === 'group') {
|
|
270
|
+
const isAutoGenerated = node.isAutoGenerated;
|
|
271
|
+
if (isAutoGenerated) {
|
|
272
|
+
delete selectionLookup[id];
|
|
273
|
+
hasChanged = true;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
// Keep previously selected tree data parents selected if all their children are filtered out
|
|
277
|
+
if (!node.children.every(childId => filteredRowsLookup[childId] === false)) {
|
|
278
|
+
delete selectionLookup[id];
|
|
279
|
+
hasChanged = true;
|
|
280
|
+
}
|
|
213
281
|
}
|
|
214
282
|
});
|
|
215
|
-
if (hasChanged) {
|
|
216
|
-
|
|
283
|
+
if (hasChanged || isNestedData && !sortModelUpdated) {
|
|
284
|
+
const newSelection = Object.values(selectionLookup);
|
|
285
|
+
if (isNestedData) {
|
|
286
|
+
apiRef.current.selectRows(newSelection, true, true);
|
|
287
|
+
} else {
|
|
288
|
+
apiRef.current.setRowSelectionModel(newSelection);
|
|
289
|
+
}
|
|
217
290
|
}
|
|
218
|
-
}, [apiRef, props.keepNonExistentRowsSelected]);
|
|
291
|
+
}, [apiRef, isNestedData, props.rowSelectionPropagation?.parents, props.keepNonExistentRowsSelected, tree]);
|
|
219
292
|
const handleSingleRowSelection = React.useCallback((id, event) => {
|
|
220
293
|
const hasCtrlKey = event.metaKey || event.ctrlKey;
|
|
221
294
|
|
|
@@ -276,8 +349,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
276
349
|
}, [apiRef, expandMouseRowRangeSelection, canHaveMultipleSelection]);
|
|
277
350
|
const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
|
|
278
351
|
const rowsToBeSelected = props.pagination && props.checkboxSelectionVisibleOnly && props.paginationMode === 'client' ? gridPaginatedVisibleSortedGridRowIdsSelector(apiRef) : gridExpandedSortedRowIdsSelector(apiRef);
|
|
279
|
-
|
|
280
|
-
apiRef.current.selectRows(rowsToBeSelected, params.value, filterModel?.items.length > 0);
|
|
352
|
+
apiRef.current.selectRows(rowsToBeSelected, params.value);
|
|
281
353
|
}, [apiRef, props.checkboxSelectionVisibleOnly, props.pagination, props.paginationMode]);
|
|
282
354
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
283
355
|
// Get the most recent cell mode because it may have been changed by another listener
|
|
@@ -341,14 +413,15 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
341
413
|
selectRows(apiRef.current.getAllRowIds(), true);
|
|
342
414
|
}
|
|
343
415
|
}, [apiRef, handleSingleRowSelection, selectRows, visibleRows.rows, canHaveMultipleSelection]);
|
|
344
|
-
useGridApiEventHandler(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(removeOutdatedSelection));
|
|
416
|
+
useGridApiEventHandler(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(() => removeOutdatedSelection(true)));
|
|
417
|
+
useGridApiEventHandler(apiRef, 'filteredRowsSet', runIfRowSelectionIsEnabled(removeOutdatedSelection));
|
|
345
418
|
useGridApiEventHandler(apiRef, 'rowClick', runIfRowSelectionIsEnabled(handleRowClick));
|
|
346
419
|
useGridApiEventHandler(apiRef, 'rowSelectionCheckboxChange', runIfRowSelectionIsEnabled(handleRowSelectionCheckboxChange));
|
|
347
420
|
useGridApiEventHandler(apiRef, 'headerSelectionCheckboxChange', handleHeaderSelectionCheckboxChange);
|
|
348
421
|
useGridApiEventHandler(apiRef, 'cellMouseDown', runIfRowSelectionIsEnabled(preventSelectionOnShift));
|
|
349
422
|
useGridApiEventHandler(apiRef, 'cellKeyDown', runIfRowSelectionIsEnabled(handleCellKeyDown));
|
|
350
423
|
|
|
351
|
-
|
|
424
|
+
/*
|
|
352
425
|
* EFFECTS
|
|
353
426
|
*/
|
|
354
427
|
React.useEffect(() => {
|
|
@@ -386,4 +459,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
386
459
|
apiRef.current.setRowSelectionModel([]);
|
|
387
460
|
}
|
|
388
461
|
}, [apiRef, canHaveMultipleSelection, checkboxSelection, isStateControlled, props.rowSelection]);
|
|
462
|
+
React.useEffect(() => {
|
|
463
|
+
runIfRowSelectionIsEnabled(removeOutdatedSelection);
|
|
464
|
+
}, [removeOutdatedSelection, runIfRowSelectionIsEnabled]);
|
|
389
465
|
};
|
|
@@ -1,8 +1,163 @@
|
|
|
1
1
|
import { GridSignature } from "../../utils/useGridApiEventHandler.js";
|
|
2
|
+
import { GRID_ROOT_GROUP_ID } from "../rows/gridRowsUtils.js";
|
|
3
|
+
import { gridFilteredRowsLookupSelector } from "../filter/gridFilterSelector.js";
|
|
4
|
+
import { gridSortedRowIdsSelector } from "../sorting/gridSortingSelector.js";
|
|
5
|
+
import { selectedIdsLookupSelector } from "./gridRowSelectionSelector.js";
|
|
6
|
+
import { gridRowTreeSelector } from "../rows/gridRowsSelector.js";
|
|
7
|
+
import { createSelector } from "../../../utils/createSelector.js";
|
|
8
|
+
export const ROW_SELECTION_PROPAGATION_DEFAULT = {
|
|
9
|
+
parents: false,
|
|
10
|
+
descendants: false
|
|
11
|
+
};
|
|
12
|
+
function getGridRowGroupSelectableDescendants(apiRef, groupId) {
|
|
13
|
+
const rowTree = gridRowTreeSelector(apiRef);
|
|
14
|
+
const sortedRowIds = gridSortedRowIdsSelector(apiRef);
|
|
15
|
+
const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
|
|
16
|
+
const groupNode = rowTree[groupId];
|
|
17
|
+
if (!groupNode || groupNode.type !== 'group') {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const descendants = [];
|
|
21
|
+
const startIndex = sortedRowIds.findIndex(id => id === groupId) + 1;
|
|
22
|
+
for (let index = startIndex; index < sortedRowIds.length && rowTree[sortedRowIds[index]]?.depth > groupNode.depth; index += 1) {
|
|
23
|
+
const id = sortedRowIds[index];
|
|
24
|
+
if (filteredRowsLookup[id] !== false && apiRef.current.isRowSelectable(id)) {
|
|
25
|
+
descendants.push(id);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return descendants;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// TODO v8: Use `createSelectorV8`
|
|
32
|
+
export function getCheckboxPropsSelector(groupId, autoSelectParents) {
|
|
33
|
+
return createSelector(gridRowTreeSelector, gridSortedRowIdsSelector, gridFilteredRowsLookupSelector, selectedIdsLookupSelector, (rowTree, sortedRowIds, filteredRowsLookup, rowSelectionLookup) => {
|
|
34
|
+
const groupNode = rowTree[groupId];
|
|
35
|
+
if (!groupNode || groupNode.type !== 'group') {
|
|
36
|
+
return {
|
|
37
|
+
isIndeterminate: false,
|
|
38
|
+
isChecked: rowSelectionLookup[groupId] === groupId
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (rowSelectionLookup[groupId] === groupId) {
|
|
42
|
+
return {
|
|
43
|
+
isIndeterminate: false,
|
|
44
|
+
isChecked: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
let selectableDescendentsCount = 0;
|
|
48
|
+
let selectedDescendentsCount = 0;
|
|
49
|
+
const startIndex = sortedRowIds.findIndex(id => id === groupId) + 1;
|
|
50
|
+
for (let index = startIndex; index < sortedRowIds.length && rowTree[sortedRowIds[index]]?.depth > groupNode.depth; index += 1) {
|
|
51
|
+
const id = sortedRowIds[index];
|
|
52
|
+
if (filteredRowsLookup[id] !== false) {
|
|
53
|
+
selectableDescendentsCount += 1;
|
|
54
|
+
if (rowSelectionLookup[id] !== undefined) {
|
|
55
|
+
selectedDescendentsCount += 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
isIndeterminate: selectedDescendentsCount > 0 && selectedDescendentsCount < selectableDescendentsCount || selectedDescendentsCount === selectableDescendentsCount && rowSelectionLookup[groupId] === undefined,
|
|
61
|
+
isChecked: autoSelectParents ? selectedDescendentsCount > 0 : rowSelectionLookup[groupId] === groupId
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
}
|
|
2
65
|
export function isMultipleRowSelectionEnabled(props) {
|
|
3
66
|
if (props.signature === GridSignature.DataGrid) {
|
|
4
67
|
// DataGrid Community has multiple row selection enabled only if checkbox selection is enabled.
|
|
5
68
|
return props.checkboxSelection && props.disableMultipleRowSelection !== true;
|
|
6
69
|
}
|
|
7
70
|
return !props.disableMultipleRowSelection;
|
|
8
|
-
}
|
|
71
|
+
}
|
|
72
|
+
const getRowNodeParents = (tree, id) => {
|
|
73
|
+
const parents = [];
|
|
74
|
+
let parent = id;
|
|
75
|
+
while (parent != null && parent !== GRID_ROOT_GROUP_ID) {
|
|
76
|
+
const node = tree[parent];
|
|
77
|
+
if (!node) {
|
|
78
|
+
return parents;
|
|
79
|
+
}
|
|
80
|
+
parents.push(parent);
|
|
81
|
+
parent = node.parent;
|
|
82
|
+
}
|
|
83
|
+
return parents;
|
|
84
|
+
};
|
|
85
|
+
const getFilteredRowNodeSiblings = (tree, filteredRows, id) => {
|
|
86
|
+
const node = tree[id];
|
|
87
|
+
if (!node) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const parent = node.parent;
|
|
91
|
+
if (parent == null) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const parentNode = tree[parent];
|
|
95
|
+
return parentNode.children.filter(childId => childId !== id && filteredRows[childId]);
|
|
96
|
+
};
|
|
97
|
+
export const findRowsToSelect = (apiRef, tree, selectedRow, autoSelectDescendants, autoSelectParents, addRow) => {
|
|
98
|
+
const filteredRows = gridFilteredRowsLookupSelector(apiRef);
|
|
99
|
+
const selectedIdsLookup = selectedIdsLookupSelector(apiRef);
|
|
100
|
+
const selectedDescendants = new Set([]);
|
|
101
|
+
if (!autoSelectDescendants && !autoSelectParents) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (autoSelectDescendants) {
|
|
105
|
+
const rowNode = tree[selectedRow];
|
|
106
|
+
if (rowNode?.type === 'group') {
|
|
107
|
+
const descendants = getGridRowGroupSelectableDescendants(apiRef, selectedRow);
|
|
108
|
+
descendants.forEach(rowId => {
|
|
109
|
+
addRow(rowId);
|
|
110
|
+
selectedDescendants.add(rowId);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (autoSelectParents) {
|
|
115
|
+
const checkAllDescendantsSelected = rowId => {
|
|
116
|
+
if (selectedIdsLookup[rowId] !== rowId && !selectedDescendants.has(rowId)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const node = tree[rowId];
|
|
120
|
+
if (node?.type !== 'group') {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return node.children.every(checkAllDescendantsSelected);
|
|
124
|
+
};
|
|
125
|
+
const traverseParents = rowId => {
|
|
126
|
+
const siblings = getFilteredRowNodeSiblings(tree, filteredRows, rowId);
|
|
127
|
+
if (siblings.length === 0 || siblings.every(checkAllDescendantsSelected)) {
|
|
128
|
+
const rowNode = tree[rowId];
|
|
129
|
+
const parent = rowNode.parent;
|
|
130
|
+
if (parent != null && parent !== GRID_ROOT_GROUP_ID && apiRef.current.isRowSelectable(parent)) {
|
|
131
|
+
addRow(parent);
|
|
132
|
+
selectedDescendants.add(parent);
|
|
133
|
+
traverseParents(parent);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
traverseParents(selectedRow);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
export const findRowsToDeselect = (apiRef, tree, deselectedRow, autoSelectDescendants, autoSelectParents, removeRow) => {
|
|
141
|
+
const selectedIdsLookup = selectedIdsLookupSelector(apiRef);
|
|
142
|
+
if (!autoSelectParents && !autoSelectDescendants) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (autoSelectParents) {
|
|
146
|
+
const allParents = getRowNodeParents(tree, deselectedRow);
|
|
147
|
+
allParents.forEach(parent => {
|
|
148
|
+
const isSelected = selectedIdsLookup[parent] === parent;
|
|
149
|
+
if (isSelected) {
|
|
150
|
+
removeRow(parent);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (autoSelectDescendants) {
|
|
155
|
+
const rowNode = tree[deselectedRow];
|
|
156
|
+
if (rowNode?.type === 'group') {
|
|
157
|
+
const descendants = getGridRowGroupSelectableDescendants(apiRef, deselectedRow);
|
|
158
|
+
descendants.forEach(descendant => {
|
|
159
|
+
removeRow(descendant);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createSelector } from "../../../utils/createSelector.js";
|
|
2
|
+
const gridRowSpanningStateSelector = state => state.rowSpanning;
|
|
3
|
+
export const gridRowSpanningHiddenCellsSelector = createSelector(gridRowSpanningStateSelector, rowSpanning => rowSpanning.hiddenCells);
|
|
4
|
+
export const gridRowSpanningSpannedCellsSelector = createSelector(gridRowSpanningStateSelector, rowSpanning => rowSpanning.spannedCells);
|
|
5
|
+
export const gridRowSpanningHiddenCellsOriginMapSelector = createSelector(gridRowSpanningStateSelector, rowSpanning => rowSpanning.hiddenCellOriginMap);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function getUnprocessedRange(testRange, processedRange) {
|
|
2
|
+
if (testRange.firstRowIndex >= processedRange.firstRowIndex && testRange.lastRowIndex <= processedRange.lastRowIndex) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
// Overflowing at the end
|
|
6
|
+
// Example: testRange={ firstRowIndex: 10, lastRowIndex: 20 }, processedRange={ firstRowIndex: 0, lastRowIndex: 15 }
|
|
7
|
+
// Unprocessed Range={ firstRowIndex: 16, lastRowIndex: 20 }
|
|
8
|
+
if (testRange.firstRowIndex >= processedRange.firstRowIndex && testRange.lastRowIndex > processedRange.lastRowIndex) {
|
|
9
|
+
return {
|
|
10
|
+
firstRowIndex: processedRange.lastRowIndex,
|
|
11
|
+
lastRowIndex: testRange.lastRowIndex
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
// Overflowing at the beginning
|
|
15
|
+
// Example: testRange={ firstRowIndex: 0, lastRowIndex: 20 }, processedRange={ firstRowIndex: 16, lastRowIndex: 30 }
|
|
16
|
+
// Unprocessed Range={ firstRowIndex: 0, lastRowIndex: 15 }
|
|
17
|
+
if (testRange.firstRowIndex < processedRange.firstRowIndex && testRange.lastRowIndex <= processedRange.lastRowIndex) {
|
|
18
|
+
return {
|
|
19
|
+
firstRowIndex: testRange.firstRowIndex,
|
|
20
|
+
lastRowIndex: processedRange.firstRowIndex - 1
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// TODO: Should return two ranges handle overflowing at both ends ?
|
|
24
|
+
return testRange;
|
|
25
|
+
}
|
|
26
|
+
export function isRowContextInitialized(renderContext) {
|
|
27
|
+
return renderContext.firstRowIndex !== 0 || renderContext.lastRowIndex !== 0;
|
|
28
|
+
}
|
|
29
|
+
export function isRowRangeUpdated(range1, range2) {
|
|
30
|
+
return range1.firstRowIndex !== range2.firstRowIndex || range1.lastRowIndex !== range2.lastRowIndex;
|
|
31
|
+
}
|
|
32
|
+
export const getCellValue = (row, colDef, apiRef) => {
|
|
33
|
+
if (!row) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
let cellValue = row[colDef.field];
|
|
37
|
+
const valueGetter = colDef.rowSpanValueGetter ?? colDef.valueGetter;
|
|
38
|
+
if (valueGetter) {
|
|
39
|
+
cellValue = valueGetter(cellValue, row, colDef, apiRef);
|
|
40
|
+
}
|
|
41
|
+
return cellValue;
|
|
42
|
+
};
|