@mui/x-data-grid 9.10.1 → 9.12.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 +283 -0
- package/DataGrid/DataGrid.js +3 -1
- package/DataGrid/DataGrid.mjs +3 -1
- package/DataGrid/useDataGridProps.d.mts +1 -1
- package/DataGrid/useDataGridProps.d.ts +1 -1
- package/README.md +1 -11
- package/components/cell/GridCell.js +14 -1
- package/components/cell/GridCell.mjs +14 -1
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -1
- package/components/columnHeaders/GridBaseColumnHeaders.mjs +1 -1
- package/components/columnHeaders/GridColumnHeaderItem.js +4 -0
- package/components/columnHeaders/GridColumnHeaderItem.mjs +4 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.mts +7 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +7 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +5 -4
- package/components/columnHeaders/GridGenericColumnHeaderItem.mjs +5 -4
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +18 -6
- package/components/panel/filterPanel/GridFilterInputSingleSelect.mjs +18 -6
- package/components/toolbarV8/Toolbar.js +2 -125
- package/components/toolbarV8/Toolbar.mjs +2 -125
- package/components/toolbarV8/ToolbarButton.js +11 -50
- package/components/toolbarV8/ToolbarButton.mjs +11 -50
- package/constants/gridClasses.d.mts +12 -0
- package/constants/gridClasses.d.ts +12 -0
- package/constants/gridClasses.js +1 -1
- package/constants/gridClasses.mjs +1 -1
- package/constants/localeTextConstants.js +4 -0
- package/constants/localeTextConstants.mjs +4 -0
- package/hooks/core/useGridApiInitialization.js +5 -1
- package/hooks/core/useGridApiInitialization.mjs +5 -1
- package/hooks/core/useGridStateInitialization.js +3 -1
- package/hooks/core/useGridStateInitialization.mjs +3 -1
- package/hooks/core/useGridVirtualizer.js +3 -0
- package/hooks/core/useGridVirtualizer.mjs +3 -0
- package/hooks/features/columnResize/useGridColumnResize.js +5 -0
- package/hooks/features/columnResize/useGridColumnResize.mjs +5 -0
- package/hooks/features/columns/gridColumnsUtils.d.mts +1 -1
- package/hooks/features/columns/gridColumnsUtils.d.ts +1 -1
- package/hooks/features/columns/gridColumnsUtils.js +2 -2
- package/hooks/features/columns/gridColumnsUtils.mjs +2 -2
- package/hooks/features/dataSource/gridDataSourceSelector.js +6 -2
- package/hooks/features/dataSource/gridDataSourceSelector.mjs +6 -2
- package/hooks/features/dataSource/useGridDataSourceBase.js +47 -5
- package/hooks/features/dataSource/useGridDataSourceBase.mjs +47 -5
- package/hooks/features/dataSource/useGridDataSourceFilterModelChange.d.mts +9 -0
- package/hooks/features/dataSource/useGridDataSourceFilterModelChange.d.ts +9 -0
- package/hooks/features/dataSource/useGridDataSourceFilterModelChange.js +57 -0
- package/hooks/features/dataSource/useGridDataSourceFilterModelChange.mjs +49 -0
- package/hooks/features/editing/useGridCellEditing.js +3 -1
- package/hooks/features/editing/useGridCellEditing.mjs +3 -1
- package/hooks/features/editing/useGridRowEditing.js +3 -1
- package/hooks/features/editing/useGridRowEditing.mjs +3 -1
- package/hooks/features/filter/gridFilterUtils.d.mts +13 -0
- package/hooks/features/filter/gridFilterUtils.d.ts +13 -0
- package/hooks/features/filter/gridFilterUtils.js +32 -1
- package/hooks/features/filter/gridFilterUtils.mjs +29 -1
- package/hooks/features/filter/useGridFilter.js +1 -21
- package/hooks/features/filter/useGridFilter.mjs +2 -22
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +1 -1
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.mjs +1 -1
- package/hooks/features/rows/gridRowsUtils.js +17 -1
- package/hooks/features/rows/gridRowsUtils.mjs +17 -1
- package/hooks/features/rows/useGridRowSpanning.js +5 -0
- package/hooks/features/rows/useGridRowSpanning.mjs +5 -0
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.mts +1 -1
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
- package/hooks/utils/useGridEvent.d.mts +2 -2
- package/hooks/utils/useGridEvent.d.ts +2 -2
- package/hooks/utils/useGridEvent.js +2 -0
- package/hooks/utils/useGridEvent.mjs +2 -0
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/internals/index.d.mts +2 -0
- package/internals/index.d.ts +2 -0
- package/internals/index.js +20 -0
- package/internals/index.mjs +2 -0
- package/locales/arSD.js +5 -0
- package/locales/arSD.mjs +5 -0
- package/locales/beBY.js +5 -0
- package/locales/beBY.mjs +5 -0
- package/locales/bgBG.js +5 -0
- package/locales/bgBG.mjs +5 -0
- package/locales/bnBD.js +5 -0
- package/locales/bnBD.mjs +5 -0
- package/locales/caES.js +5 -0
- package/locales/caES.mjs +5 -0
- package/locales/csCZ.js +5 -0
- package/locales/csCZ.mjs +5 -0
- package/locales/daDK.js +5 -0
- package/locales/daDK.mjs +5 -0
- package/locales/deDE.js +5 -0
- package/locales/deDE.mjs +5 -0
- package/locales/elGR.js +5 -0
- package/locales/elGR.mjs +5 -0
- package/locales/esES.js +5 -0
- package/locales/esES.mjs +5 -0
- package/locales/faIR.js +5 -0
- package/locales/faIR.mjs +5 -0
- package/locales/fiFI.js +5 -0
- package/locales/fiFI.mjs +5 -0
- package/locales/frFR.js +5 -0
- package/locales/frFR.mjs +5 -0
- package/locales/heIL.js +5 -0
- package/locales/heIL.mjs +5 -0
- package/locales/hrHR.js +5 -0
- package/locales/hrHR.mjs +5 -0
- package/locales/huHU.js +5 -0
- package/locales/huHU.mjs +5 -0
- package/locales/hyAM.js +5 -0
- package/locales/hyAM.mjs +5 -0
- package/locales/idID.js +5 -0
- package/locales/idID.mjs +5 -0
- package/locales/isIS.js +5 -0
- package/locales/isIS.mjs +5 -0
- package/locales/itIT.js +5 -0
- package/locales/itIT.mjs +5 -0
- package/locales/jaJP.js +5 -0
- package/locales/jaJP.mjs +5 -0
- package/locales/koKR.js +5 -0
- package/locales/koKR.mjs +5 -0
- package/locales/nbNO.js +5 -0
- package/locales/nbNO.mjs +5 -0
- package/locales/nlNL.js +5 -0
- package/locales/nlNL.mjs +5 -0
- package/locales/nnNO.js +5 -0
- package/locales/nnNO.mjs +5 -0
- package/locales/plPL.js +5 -0
- package/locales/plPL.mjs +5 -0
- package/locales/ptBR.js +5 -0
- package/locales/ptBR.mjs +5 -0
- package/locales/ptPT.js +5 -0
- package/locales/ptPT.mjs +5 -0
- package/locales/roRO.js +5 -0
- package/locales/roRO.mjs +5 -0
- package/locales/ruRU.js +5 -0
- package/locales/ruRU.mjs +5 -0
- package/locales/skSK.js +5 -0
- package/locales/skSK.mjs +5 -0
- package/locales/svSE.js +5 -0
- package/locales/svSE.mjs +5 -0
- package/locales/thTH.js +5 -0
- package/locales/thTH.mjs +5 -0
- package/locales/trTR.js +5 -0
- package/locales/trTR.mjs +5 -0
- package/locales/ukUA.js +5 -0
- package/locales/ukUA.mjs +5 -0
- package/locales/urPK.js +5 -0
- package/locales/urPK.mjs +5 -0
- package/locales/viVN.js +5 -0
- package/locales/viVN.mjs +5 -0
- package/locales/zhCN.js +5 -0
- package/locales/zhCN.mjs +5 -0
- package/locales/zhHK.js +5 -0
- package/locales/zhHK.mjs +5 -0
- package/locales/zhTW.js +5 -0
- package/locales/zhTW.mjs +5 -0
- package/models/api/gridApiCommon.d.mts +2 -2
- package/models/api/gridApiCommon.d.ts +2 -2
- package/models/api/gridCallbackDetails.d.mts +11 -1
- package/models/api/gridCallbackDetails.d.ts +11 -1
- package/models/api/gridLocaleTextApi.d.mts +3 -0
- package/models/api/gridLocaleTextApi.d.ts +3 -0
- package/models/api/gridRowApi.d.mts +12 -0
- package/models/api/gridRowApi.d.ts +12 -0
- package/models/api/gridStateApi.d.mts +3 -2
- package/models/api/gridStateApi.d.ts +3 -2
- package/models/api/index.d.mts +1 -1
- package/models/api/index.d.ts +1 -1
- package/models/colDef/gridColDef.d.mts +5 -0
- package/models/colDef/gridColDef.d.ts +5 -0
- package/models/configuration/gridConfiguration.d.mts +13 -1
- package/models/configuration/gridConfiguration.d.ts +13 -1
- package/models/controlStateItem.d.mts +3 -2
- package/models/controlStateItem.d.ts +3 -2
- package/models/events/gridEventListener.d.mts +3 -2
- package/models/events/gridEventListener.d.ts +3 -2
- package/models/props/DataGridProps.d.mts +38 -35
- package/models/props/DataGridProps.d.ts +38 -35
- package/package.json +4 -4
- package/utils/domUtils.js +1 -1
- package/utils/domUtils.mjs +1 -1
- package/utils/getPublicApiRef.d.mts +2 -2
- package/utils/getPublicApiRef.d.ts +2 -2
- package/utils/getPublicApiRef.js +15 -3
- package/utils/getPublicApiRef.mjs +15 -3
- package/components/toolbarV8/ToolbarContext.d.mts +0 -11
- package/components/toolbarV8/ToolbarContext.d.ts +0 -11
- package/components/toolbarV8/ToolbarContext.js +0 -21
- package/components/toolbarV8/ToolbarContext.mjs +0 -13
- package/components/toolbarV8/utils.d.mts +0 -5
- package/components/toolbarV8/utils.d.ts +0 -5
- package/components/toolbarV8/utils.js +0 -23
- package/components/toolbarV8/utils.mjs +0 -17
|
@@ -5,6 +5,7 @@ import { EventManager } from '@mui/x-internals/EventManager';
|
|
|
5
5
|
import { Store } from '@mui/x-internals/store';
|
|
6
6
|
import { useGridApiMethod } from "../utils/useGridApiMethod.mjs";
|
|
7
7
|
import { GridSignature } from "../../constants/signature.mjs";
|
|
8
|
+
import { getPublicApiRef } from "../../utils/getPublicApiRef.mjs";
|
|
8
9
|
const SYMBOL_API_PRIVATE = Symbol('mui.api_private');
|
|
9
10
|
const isSyntheticEvent = event => {
|
|
10
11
|
return event.isPropagationStopped !== undefined;
|
|
@@ -85,8 +86,11 @@ export function useGridApiInitialization(inputApiRef, props) {
|
|
|
85
86
|
return;
|
|
86
87
|
}
|
|
87
88
|
const details = props.signature === GridSignature.DataGridPro || props.signature === GridSignature.DataGridPremium ? {
|
|
89
|
+
apiRef: getPublicApiRef(privateApiRef),
|
|
88
90
|
api: privateApiRef.current.getPublicApi()
|
|
89
|
-
} : {
|
|
91
|
+
} : {
|
|
92
|
+
apiRef: getPublicApiRef(privateApiRef)
|
|
93
|
+
};
|
|
90
94
|
privateApiRef.current.eventManager.emit(name, params, event, details);
|
|
91
95
|
}, [privateApiRef, props.signature]);
|
|
92
96
|
const subscribeEvent = React.useCallback((event, handler, options) => {
|
|
@@ -12,6 +12,7 @@ var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/form
|
|
|
12
12
|
var React = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _utils = require("../utils");
|
|
14
14
|
var _utils2 = require("../../utils/utils");
|
|
15
|
+
var _getPublicApiRef = require("../../utils/getPublicApiRef");
|
|
15
16
|
const useGridStateInitialization = apiRef => {
|
|
16
17
|
const controlStateMapRef = React.useRef({});
|
|
17
18
|
const registerControlState = React.useCallback(controlStateItem => {
|
|
@@ -75,7 +76,8 @@ const useGridStateInitialization = apiRef => {
|
|
|
75
76
|
if (controlState.propOnChange && hasPropChanged) {
|
|
76
77
|
controlState.propOnChange(model, {
|
|
77
78
|
reason,
|
|
78
|
-
api: apiRef.current
|
|
79
|
+
api: apiRef.current,
|
|
80
|
+
apiRef: (0, _getPublicApiRef.getPublicApiRef)(apiRef)
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
83
|
if (!ignoreSetState) {
|
|
@@ -5,6 +5,7 @@ import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { useGridApiMethod } from "../utils/index.mjs";
|
|
7
7
|
import { isFunction } from "../../utils/utils.mjs";
|
|
8
|
+
import { getPublicApiRef } from "../../utils/getPublicApiRef.mjs";
|
|
8
9
|
export const useGridStateInitialization = apiRef => {
|
|
9
10
|
const controlStateMapRef = React.useRef({});
|
|
10
11
|
const registerControlState = React.useCallback(controlStateItem => {
|
|
@@ -68,7 +69,8 @@ export const useGridStateInitialization = apiRef => {
|
|
|
68
69
|
if (controlState.propOnChange && hasPropChanged) {
|
|
69
70
|
controlState.propOnChange(model, {
|
|
70
71
|
reason,
|
|
71
|
-
api: apiRef.current
|
|
72
|
+
api: apiRef.current,
|
|
73
|
+
apiRef: getPublicApiRef(apiRef)
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
if (!ignoreSetState) {
|
|
@@ -26,6 +26,7 @@ var _useGridVisibleRows = require("../utils/useGridVisibleRows");
|
|
|
26
26
|
var _pagination = require("../features/pagination");
|
|
27
27
|
var _gridFocusedVirtualCellSelector = require("../features/virtualization/gridFocusedVirtualCellSelector");
|
|
28
28
|
var _rowSelection = require("../features/rowSelection");
|
|
29
|
+
var _gridColumnGroupsSelector = require("../features/columnGrouping/gridColumnGroupsSelector");
|
|
29
30
|
var _dataGridPropsDefaultValues = require("../../constants/dataGridPropsDefaultValues");
|
|
30
31
|
var _gridRowsUtils = require("../features/rows/gridRowsUtils");
|
|
31
32
|
var _gridColumnsUtils = require("../features/columns/gridColumnsUtils");
|
|
@@ -87,6 +88,8 @@ function useGridVirtualizer() {
|
|
|
87
88
|
const groupHeaderHeight = Math.floor((rootProps.columnGroupHeaderHeight ?? rootProps.columnHeaderHeight) * density);
|
|
88
89
|
const headerFilterHeight = Math.floor((rootProps.headerFilterHeight ?? rootProps.columnHeaderHeight) * density);
|
|
89
90
|
const columnsTotalWidth = (0, _useGridSelector.useGridSelector)(apiRef, columnsTotalWidthSelector);
|
|
91
|
+
// `getTotalHeaderHeight` reads the group depth imperatively, subscribe so it re-renders when it changes.
|
|
92
|
+
(0, _utils.eslintUseValue)((0, _useGridSelector.useGridSelector)(apiRef, _gridColumnGroupsSelector.gridColumnGroupsHeaderMaxDepthSelector));
|
|
90
93
|
const headersTotalHeight = (0, _gridColumnsUtils.getTotalHeaderHeight)(apiRef, rootProps);
|
|
91
94
|
const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
|
|
92
95
|
const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
|
|
@@ -18,6 +18,7 @@ import { useGridVisibleRows } from "../utils/useGridVisibleRows.mjs";
|
|
|
18
18
|
import { gridPaginationSelector } from "../features/pagination/index.mjs";
|
|
19
19
|
import { gridFocusedVirtualCellSelector } from "../features/virtualization/gridFocusedVirtualCellSelector.mjs";
|
|
20
20
|
import { gridRowSelectionManagerSelector } from "../features/rowSelection/index.mjs";
|
|
21
|
+
import { gridColumnGroupsHeaderMaxDepthSelector } from "../features/columnGrouping/gridColumnGroupsSelector.mjs";
|
|
21
22
|
import { DATA_GRID_PROPS_DEFAULT_VALUES } from "../../constants/dataGridPropsDefaultValues.mjs";
|
|
22
23
|
import { getValidRowHeight, minimalContentHeight, rowHeightWarning } from "../features/rows/gridRowsUtils.mjs";
|
|
23
24
|
import { getTotalHeaderHeight } from "../features/columns/gridColumnsUtils.mjs";
|
|
@@ -79,6 +80,8 @@ export function useGridVirtualizer() {
|
|
|
79
80
|
const groupHeaderHeight = Math.floor((rootProps.columnGroupHeaderHeight ?? rootProps.columnHeaderHeight) * density);
|
|
80
81
|
const headerFilterHeight = Math.floor((rootProps.headerFilterHeight ?? rootProps.columnHeaderHeight) * density);
|
|
81
82
|
const columnsTotalWidth = useGridSelector(apiRef, columnsTotalWidthSelector);
|
|
83
|
+
// `getTotalHeaderHeight` reads the group depth imperatively, subscribe so it re-renders when it changes.
|
|
84
|
+
eslintUseValue(useGridSelector(apiRef, gridColumnGroupsHeaderMaxDepthSelector));
|
|
82
85
|
const headersTotalHeight = getTotalHeaderHeight(apiRef, rootProps);
|
|
83
86
|
const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
|
|
84
87
|
const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
|
|
@@ -568,6 +568,11 @@ const useGridColumnResize = (apiRef, props) => {
|
|
|
568
568
|
if (!props.disableVirtualization && options.disableColumnVirtualization) {
|
|
569
569
|
apiRef.current.unstable_setColumnVirtualization(false);
|
|
570
570
|
await columnVirtualizationDisabled();
|
|
571
|
+
|
|
572
|
+
// The grid may have unmounted while awaiting, which nulls the root element ref.
|
|
573
|
+
if (!apiRef.current.rootElementRef?.current) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
571
576
|
}
|
|
572
577
|
const widthByField = extractColumnWidths(apiRef, options, columns);
|
|
573
578
|
const newColumns = columns.map(column => (0, _extends2.default)({}, column, {
|
|
@@ -560,6 +560,11 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
560
560
|
if (!props.disableVirtualization && options.disableColumnVirtualization) {
|
|
561
561
|
apiRef.current.unstable_setColumnVirtualization(false);
|
|
562
562
|
await columnVirtualizationDisabled();
|
|
563
|
+
|
|
564
|
+
// The grid may have unmounted while awaiting, which nulls the root element ref.
|
|
565
|
+
if (!apiRef.current.rootElementRef?.current) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
563
568
|
}
|
|
564
569
|
const widthByField = extractColumnWidths(apiRef, options, columns);
|
|
565
570
|
const newColumns = columns.map(column => _extends({}, column, {
|
|
@@ -67,4 +67,4 @@ export declare function getFirstNonSpannedColumnToRender({
|
|
|
67
67
|
lastRowToRender: number;
|
|
68
68
|
visibleRows: GridRowEntry[];
|
|
69
69
|
}): number;
|
|
70
|
-
export declare function getTotalHeaderHeight(apiRef: RefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'columnHeaderHeight' | 'headerFilterHeight' | 'listView' | 'columnGroupHeaderHeight'>): number;
|
|
70
|
+
export declare function getTotalHeaderHeight(apiRef: RefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'columnHeaderHeight' | 'headerFilterHeight' | 'listView' | 'columnGroupHeaderHeight' | 'signature' | 'headerFilters'>): number;
|
|
@@ -67,4 +67,4 @@ export declare function getFirstNonSpannedColumnToRender({
|
|
|
67
67
|
lastRowToRender: number;
|
|
68
68
|
visibleRows: GridRowEntry[];
|
|
69
69
|
}): number;
|
|
70
|
-
export declare function getTotalHeaderHeight(apiRef: RefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'columnHeaderHeight' | 'headerFilterHeight' | 'listView' | 'columnGroupHeaderHeight'>): number;
|
|
70
|
+
export declare function getTotalHeaderHeight(apiRef: RefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'columnHeaderHeight' | 'headerFilterHeight' | 'listView' | 'columnGroupHeaderHeight' | 'signature' | 'headerFilters'>): number;
|
|
@@ -19,7 +19,6 @@ var _signature = require("../../../constants/signature");
|
|
|
19
19
|
var _gridColumnsSelector = require("./gridColumnsSelector");
|
|
20
20
|
var _utils = require("../../../utils/utils");
|
|
21
21
|
var _densitySelector = require("../density/densitySelector");
|
|
22
|
-
var _gridHeaderFilteringSelectors = require("../headerFiltering/gridHeaderFilteringSelectors");
|
|
23
22
|
var _gridColumnGroupsSelector = require("../columnGrouping/gridColumnGroupsSelector");
|
|
24
23
|
const COLUMNS_DIMENSION_PROPERTIES = exports.COLUMNS_DIMENSION_PROPERTIES = ['maxWidth', 'minWidth', 'width', 'flex'];
|
|
25
24
|
/**
|
|
@@ -360,7 +359,8 @@ function getTotalHeaderHeight(apiRef, props) {
|
|
|
360
359
|
}
|
|
361
360
|
const densityFactor = (0, _densitySelector.gridDensityFactorSelector)(apiRef);
|
|
362
361
|
const maxDepth = (0, _gridColumnGroupsSelector.gridColumnGroupsHeaderMaxDepthSelector)(apiRef);
|
|
363
|
-
|
|
362
|
+
// Not `gridHeaderFilteringEnabledSelector`: that state is synced in an effect, so it lags one render behind `props.headerFilters`.
|
|
363
|
+
const isHeaderFilteringEnabled = props.signature !== 'DataGrid' && (props.headerFilters ?? false);
|
|
364
364
|
const columnHeadersHeight = Math.floor(props.columnHeaderHeight * densityFactor);
|
|
365
365
|
const columnGroupHeadersHeight = Math.floor((props.columnGroupHeaderHeight ?? props.columnHeaderHeight) * densityFactor);
|
|
366
366
|
const filterHeadersHeight = isHeaderFilteringEnabled ? Math.floor((props.headerFilterHeight ?? props.columnHeaderHeight) * densityFactor) : 0;
|
|
@@ -6,7 +6,6 @@ import { GridSignature } from "../../../constants/signature.mjs";
|
|
|
6
6
|
import { gridColumnsStateSelector, gridColumnVisibilityModelSelector } from "./gridColumnsSelector.mjs";
|
|
7
7
|
import { clamp } from "../../../utils/utils.mjs";
|
|
8
8
|
import { gridDensityFactorSelector } from "../density/densitySelector.mjs";
|
|
9
|
-
import { gridHeaderFilteringEnabledSelector } from "../headerFiltering/gridHeaderFilteringSelectors.mjs";
|
|
10
9
|
import { gridColumnGroupsHeaderMaxDepthSelector } from "../columnGrouping/gridColumnGroupsSelector.mjs";
|
|
11
10
|
export const COLUMNS_DIMENSION_PROPERTIES = ['maxWidth', 'minWidth', 'width', 'flex'];
|
|
12
11
|
/**
|
|
@@ -345,7 +344,8 @@ export function getTotalHeaderHeight(apiRef, props) {
|
|
|
345
344
|
}
|
|
346
345
|
const densityFactor = gridDensityFactorSelector(apiRef);
|
|
347
346
|
const maxDepth = gridColumnGroupsHeaderMaxDepthSelector(apiRef);
|
|
348
|
-
|
|
347
|
+
// Not `gridHeaderFilteringEnabledSelector`: that state is synced in an effect, so it lags one render behind `props.headerFilters`.
|
|
348
|
+
const isHeaderFilteringEnabled = props.signature !== 'DataGrid' && (props.headerFilters ?? false);
|
|
349
349
|
const columnHeadersHeight = Math.floor(props.columnHeaderHeight * densityFactor);
|
|
350
350
|
const columnGroupHeadersHeight = Math.floor((props.columnGroupHeaderHeight ?? props.columnHeaderHeight) * densityFactor);
|
|
351
351
|
const filterHeadersHeight = isHeaderFilteringEnabled ? Math.floor((props.headerFilterHeight ?? props.columnHeaderHeight) * densityFactor) : 0;
|
|
@@ -5,14 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.gridGetRowsParamsSelector = void 0;
|
|
7
7
|
var _gridFilterSelector = require("../filter/gridFilterSelector");
|
|
8
|
+
var _gridFilterUtils = require("../filter/gridFilterUtils");
|
|
8
9
|
var _gridSortingSelector = require("../sorting/gridSortingSelector");
|
|
9
10
|
var _gridPaginationSelector = require("../pagination/gridPaginationSelector");
|
|
11
|
+
var _columns = require("../columns");
|
|
10
12
|
var _createSelector = require("../../../utils/createSelector");
|
|
11
|
-
const gridGetRowsParamsSelector = exports.gridGetRowsParamsSelector = (0, _createSelector.createSelector)(_gridFilterSelector.gridFilterModelSelector, _gridSortingSelector.gridSortModelSelector, _gridPaginationSelector.gridPaginationModelSelector, (filterModel, sortModel, paginationModel) => ({
|
|
13
|
+
const gridGetRowsParamsSelector = exports.gridGetRowsParamsSelector = (0, _createSelector.createSelector)(_gridFilterSelector.gridFilterModelSelector, _gridSortingSelector.gridSortModelSelector, _gridPaginationSelector.gridPaginationModelSelector, _columns.gridColumnLookupSelector, (filterModel, sortModel, paginationModel, columnsLookup) => ({
|
|
12
14
|
groupKeys: [],
|
|
13
15
|
paginationModel,
|
|
14
16
|
sortModel,
|
|
15
|
-
|
|
17
|
+
// An item without a value is an incomplete filter, not a constraint. The client-side
|
|
18
|
+
// engine already ignores those, so the server must not be asked to honor them either.
|
|
19
|
+
filterModel: (0, _gridFilterUtils.removeIncompleteFilterItems)(filterModel, columnsLookup),
|
|
16
20
|
start: paginationModel.page * paginationModel.pageSize,
|
|
17
21
|
end: paginationModel.page * paginationModel.pageSize + paginationModel.pageSize - 1
|
|
18
22
|
}));
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { gridFilterModelSelector } from "../filter/gridFilterSelector.mjs";
|
|
2
|
+
import { removeIncompleteFilterItems } from "../filter/gridFilterUtils.mjs";
|
|
2
3
|
import { gridSortModelSelector } from "../sorting/gridSortingSelector.mjs";
|
|
3
4
|
import { gridPaginationModelSelector } from "../pagination/gridPaginationSelector.mjs";
|
|
5
|
+
import { gridColumnLookupSelector } from "../columns/index.mjs";
|
|
4
6
|
import { createSelector } from "../../../utils/createSelector.mjs";
|
|
5
|
-
export const gridGetRowsParamsSelector = createSelector(gridFilterModelSelector, gridSortModelSelector, gridPaginationModelSelector, (filterModel, sortModel, paginationModel) => ({
|
|
7
|
+
export const gridGetRowsParamsSelector = createSelector(gridFilterModelSelector, gridSortModelSelector, gridPaginationModelSelector, gridColumnLookupSelector, (filterModel, sortModel, paginationModel, columnsLookup) => ({
|
|
6
8
|
groupKeys: [],
|
|
7
9
|
paginationModel,
|
|
8
10
|
sortModel,
|
|
9
|
-
|
|
11
|
+
// An item without a value is an incomplete filter, not a constraint. The client-side
|
|
12
|
+
// engine already ignores those, so the server must not be asked to honor them either.
|
|
13
|
+
filterModel: removeIncompleteFilterItems(filterModel, columnsLookup),
|
|
10
14
|
start: paginationModel.page * paginationModel.pageSize,
|
|
11
15
|
end: paginationModel.page * paginationModel.pageSize + paginationModel.pageSize - 1
|
|
12
16
|
}));
|
|
@@ -21,7 +21,10 @@ var _strategyProcessing = require("../../core/strategyProcessing");
|
|
|
21
21
|
var _useGridSelector = require("../../utils/useGridSelector");
|
|
22
22
|
var _gridPaginationSelector = require("../pagination/gridPaginationSelector");
|
|
23
23
|
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
24
|
+
var _columns = require("../columns");
|
|
25
|
+
var _gridFilterUtils = require("../filter/gridFilterUtils");
|
|
24
26
|
var _gridDataSourceSelector = require("./gridDataSourceSelector");
|
|
27
|
+
var _useGridDataSourceFilterModelChange = require("./useGridDataSourceFilterModelChange");
|
|
25
28
|
var _utils2 = require("./utils");
|
|
26
29
|
var _cache = require("./cache");
|
|
27
30
|
var _gridDataSourceError = require("./gridDataSourceError");
|
|
@@ -47,6 +50,11 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
47
50
|
}, [currentStrategy]);
|
|
48
51
|
const paginationModel = (0, _useGridSelector.useGridSelector)(apiRef, _gridPaginationSelector.gridPaginationModelSelector);
|
|
49
52
|
const lastRequestId = React.useRef(0);
|
|
53
|
+
// `false` while a request is in flight, and for any request that errors or is discarded as
|
|
54
|
+
// stale. Lets the mount effect tell "rows are already displayed" from "the fetch never landed".
|
|
55
|
+
const rowsAreUpToDate = React.useRef(false);
|
|
56
|
+
// Requests that are still running and will apply their response when they settle.
|
|
57
|
+
const pendingRequestCount = React.useRef(0);
|
|
50
58
|
const pollingIntervalRef = React.useRef(null);
|
|
51
59
|
const onDataSourceErrorProp = props.onDataSourceError;
|
|
52
60
|
const revalidateMs = props.dataSourceRevalidateMs;
|
|
@@ -72,6 +80,9 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
72
80
|
} = _ref,
|
|
73
81
|
getRowsParams = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
|
|
74
82
|
const fetchParams = (0, _extends2.default)({}, (0, _gridDataSourceSelector.gridGetRowsParamsSelector)(apiRef), apiRef.current.unstable_applyPipeProcessors('getRowsParams', {}), getRowsParams);
|
|
83
|
+
// The selector prunes the incomplete items, but a caller passing its own `filterModel`
|
|
84
|
+
// overrides it, so prune again on the merged params.
|
|
85
|
+
fetchParams.filterModel = (0, _gridFilterUtils.removeIncompleteFilterItems)(fetchParams.filterModel, (0, _columns.gridColumnLookupSelector)(apiRef));
|
|
75
86
|
if (parentId && parentId !== _gridRowsUtils.GRID_ROOT_GROUP_ID && props.signature !== 'DataGrid') {
|
|
76
87
|
options.fetchRowChildren?.([parentId], [fetchParams], showChildrenLoading);
|
|
77
88
|
return;
|
|
@@ -91,6 +102,7 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
91
102
|
keepChildrenExpanded
|
|
92
103
|
}
|
|
93
104
|
});
|
|
105
|
+
rowsAreUpToDate.current = true;
|
|
94
106
|
if (standardRowsUpdateStrategyActive) {
|
|
95
107
|
apiRef.current.setLoading(false);
|
|
96
108
|
}
|
|
@@ -103,6 +115,8 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
103
115
|
}
|
|
104
116
|
const requestId = lastRequestId.current + 1;
|
|
105
117
|
lastRequestId.current = requestId;
|
|
118
|
+
rowsAreUpToDate.current = false;
|
|
119
|
+
pendingRequestCount.current += 1;
|
|
106
120
|
try {
|
|
107
121
|
const getRowsResponse = await getRows(fetchParams);
|
|
108
122
|
const cacheResponses = cacheChunkManager.splitResponse(fetchParams, getRowsResponse);
|
|
@@ -116,6 +130,7 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
116
130
|
keepChildrenExpanded
|
|
117
131
|
}
|
|
118
132
|
});
|
|
133
|
+
rowsAreUpToDate.current = true;
|
|
119
134
|
}
|
|
120
135
|
} catch (originalError) {
|
|
121
136
|
if (lastRequestId.current === requestId) {
|
|
@@ -138,6 +153,7 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
138
153
|
}
|
|
139
154
|
}
|
|
140
155
|
} finally {
|
|
156
|
+
pendingRequestCount.current -= 1;
|
|
141
157
|
if (standardRowsUpdateStrategyActive && lastRequestId.current === requestId) {
|
|
142
158
|
apiRef.current.setLoading(false);
|
|
143
159
|
}
|
|
@@ -290,6 +306,13 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
290
306
|
stopPolling();
|
|
291
307
|
debouncedFetchRows();
|
|
292
308
|
}, [apiRef, props.dataSourceKeepPreviousData, stopPolling, debouncedFetchRows]);
|
|
309
|
+
const hasFilterModelChanged = (0, _useGridDataSourceFilterModelChange.useGridDataSourceFilterModelChange)(apiRef);
|
|
310
|
+
const handleFetchRowsOnFilterModelChange = React.useCallback(newFilterModel => {
|
|
311
|
+
if (!hasFilterModelChanged(newFilterModel)) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
handleFetchRowsOnParamsChange();
|
|
315
|
+
}, [hasFilterModelChanged, handleFetchRowsOnParamsChange]);
|
|
293
316
|
const isFirstRender = React.useRef(true);
|
|
294
317
|
React.useEffect(() => {
|
|
295
318
|
if (isFirstRender.current) {
|
|
@@ -313,12 +336,34 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
313
336
|
}
|
|
314
337
|
}, [revalidateMs, stopPolling]);
|
|
315
338
|
React.useEffect(() => stopPolling, [stopPolling]);
|
|
339
|
+
const lastApiRef = React.useRef(apiRef);
|
|
340
|
+
const lastStrategy = React.useRef(currentStrategy);
|
|
341
|
+
const lastDataSource = React.useRef(props.dataSource);
|
|
316
342
|
React.useEffect(() => {
|
|
343
|
+
// `<Activity mode="hidden">` leaves the root element in the document, a real unmount does not.
|
|
344
|
+
// Only discard the in-flight response in the latter case, so hiding lets the request land.
|
|
345
|
+
const rootElement = apiRef.current?.rootElementRef?.current ?? null;
|
|
346
|
+
const ignoreInFlightRequest = () => {
|
|
347
|
+
if (!rootElement?.isConnected) {
|
|
348
|
+
lastRequestId.current += 1;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
317
352
|
// Return early if the proper strategy isn't set yet
|
|
318
353
|
// Context: https://github.com/mui/mui-x/issues/19650
|
|
319
354
|
if (currentStrategy !== _utils2.DataSourceRowsUpdateStrategy.Default && currentStrategy !== _utils2.DataSourceRowsUpdateStrategy.LazyLoading && currentStrategy !== _utils2.DataSourceRowsUpdateStrategy.GroupedData && currentStrategy !== _utils2.DataSourceRowsUpdateStrategy.LazyLoadedGroupedData) {
|
|
320
355
|
return undefined;
|
|
321
356
|
}
|
|
357
|
+
const dependenciesChanged = lastApiRef.current !== apiRef || lastStrategy.current !== currentStrategy || lastDataSource.current !== props.dataSource;
|
|
358
|
+
lastApiRef.current = apiRef;
|
|
359
|
+
lastStrategy.current = currentStrategy;
|
|
360
|
+
lastDataSource.current = props.dataSource;
|
|
361
|
+
|
|
362
|
+
// Re-mounting the effect (`<Activity />` becoming visible again, for instance) must not
|
|
363
|
+
// re-fetch data that is already displayed.
|
|
364
|
+
if (!dependenciesChanged && (rowsAreUpToDate.current || pendingRequestCount.current > 0)) {
|
|
365
|
+
return ignoreInFlightRequest;
|
|
366
|
+
}
|
|
322
367
|
if (props.dataSource) {
|
|
323
368
|
stopPolling();
|
|
324
369
|
// `dataSourceKeepPreviousData` only applies to the flat `Default` strategy (mirroring
|
|
@@ -332,10 +377,7 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
332
377
|
apiRef.current.dataSource.cache.clear();
|
|
333
378
|
apiRef.current.dataSource.fetchRows();
|
|
334
379
|
}
|
|
335
|
-
return
|
|
336
|
-
// ignore the current request on unmount
|
|
337
|
-
lastRequestId.current += 1;
|
|
338
|
-
};
|
|
380
|
+
return ignoreInFlightRequest;
|
|
339
381
|
}, [apiRef, props.dataSource, props.dataSourceKeepPreviousData, currentStrategy, stopPolling]);
|
|
340
382
|
React.useEffect(() => {
|
|
341
383
|
// `dataSourceKeepPreviousData` is a no-op for tree data and row grouping: those
|
|
@@ -363,7 +405,7 @@ const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
363
405
|
events: {
|
|
364
406
|
strategyAvailabilityChange: handleStrategyActivityChange,
|
|
365
407
|
sortModelChange: (0, _utils.runIf)(standardRowsUpdateStrategyActive, handleFetchRowsOnParamsChange),
|
|
366
|
-
filterModelChange: (0, _utils.runIf)(standardRowsUpdateStrategyActive,
|
|
408
|
+
filterModelChange: (0, _utils.runIf)(standardRowsUpdateStrategyActive, handleFetchRowsOnFilterModelChange),
|
|
367
409
|
paginationModelChange: (0, _utils.runIf)(standardRowsUpdateStrategyActive, handleFetchRowsOnParamsChange)
|
|
368
410
|
}
|
|
369
411
|
};
|
|
@@ -15,7 +15,10 @@ import { GridStrategyGroup } from "../../core/strategyProcessing/index.mjs";
|
|
|
15
15
|
import { useGridSelector } from "../../utils/useGridSelector.mjs";
|
|
16
16
|
import { gridPaginationModelSelector, gridVisibleRowsSelector } from "../pagination/gridPaginationSelector.mjs";
|
|
17
17
|
import { gridRowTreeSelector } from "../rows/gridRowsSelector.mjs";
|
|
18
|
+
import { gridColumnLookupSelector } from "../columns/index.mjs";
|
|
19
|
+
import { removeIncompleteFilterItems } from "../filter/gridFilterUtils.mjs";
|
|
18
20
|
import { gridGetRowsParamsSelector } from "./gridDataSourceSelector.mjs";
|
|
21
|
+
import { useGridDataSourceFilterModelChange } from "./useGridDataSourceFilterModelChange.mjs";
|
|
19
22
|
import { CacheChunkManager, DataSourceRowsUpdateStrategy } from "./utils.mjs";
|
|
20
23
|
import { GridDataSourceCacheDefault } from "./cache.mjs";
|
|
21
24
|
import { GridGetRowsError, GridUpdateRowError } from "./gridDataSourceError.mjs";
|
|
@@ -40,6 +43,11 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
40
43
|
}, [currentStrategy]);
|
|
41
44
|
const paginationModel = useGridSelector(apiRef, gridPaginationModelSelector);
|
|
42
45
|
const lastRequestId = React.useRef(0);
|
|
46
|
+
// `false` while a request is in flight, and for any request that errors or is discarded as
|
|
47
|
+
// stale. Lets the mount effect tell "rows are already displayed" from "the fetch never landed".
|
|
48
|
+
const rowsAreUpToDate = React.useRef(false);
|
|
49
|
+
// Requests that are still running and will apply their response when they settle.
|
|
50
|
+
const pendingRequestCount = React.useRef(0);
|
|
43
51
|
const pollingIntervalRef = React.useRef(null);
|
|
44
52
|
const onDataSourceErrorProp = props.onDataSourceError;
|
|
45
53
|
const revalidateMs = props.dataSourceRevalidateMs;
|
|
@@ -65,6 +73,9 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
65
73
|
} = _ref,
|
|
66
74
|
getRowsParams = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
67
75
|
const fetchParams = _extends({}, gridGetRowsParamsSelector(apiRef), apiRef.current.unstable_applyPipeProcessors('getRowsParams', {}), getRowsParams);
|
|
76
|
+
// The selector prunes the incomplete items, but a caller passing its own `filterModel`
|
|
77
|
+
// overrides it, so prune again on the merged params.
|
|
78
|
+
fetchParams.filterModel = removeIncompleteFilterItems(fetchParams.filterModel, gridColumnLookupSelector(apiRef));
|
|
68
79
|
if (parentId && parentId !== GRID_ROOT_GROUP_ID && props.signature !== 'DataGrid') {
|
|
69
80
|
options.fetchRowChildren?.([parentId], [fetchParams], showChildrenLoading);
|
|
70
81
|
return;
|
|
@@ -84,6 +95,7 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
84
95
|
keepChildrenExpanded
|
|
85
96
|
}
|
|
86
97
|
});
|
|
98
|
+
rowsAreUpToDate.current = true;
|
|
87
99
|
if (standardRowsUpdateStrategyActive) {
|
|
88
100
|
apiRef.current.setLoading(false);
|
|
89
101
|
}
|
|
@@ -96,6 +108,8 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
96
108
|
}
|
|
97
109
|
const requestId = lastRequestId.current + 1;
|
|
98
110
|
lastRequestId.current = requestId;
|
|
111
|
+
rowsAreUpToDate.current = false;
|
|
112
|
+
pendingRequestCount.current += 1;
|
|
99
113
|
try {
|
|
100
114
|
const getRowsResponse = await getRows(fetchParams);
|
|
101
115
|
const cacheResponses = cacheChunkManager.splitResponse(fetchParams, getRowsResponse);
|
|
@@ -109,6 +123,7 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
109
123
|
keepChildrenExpanded
|
|
110
124
|
}
|
|
111
125
|
});
|
|
126
|
+
rowsAreUpToDate.current = true;
|
|
112
127
|
}
|
|
113
128
|
} catch (originalError) {
|
|
114
129
|
if (lastRequestId.current === requestId) {
|
|
@@ -131,6 +146,7 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
131
146
|
}
|
|
132
147
|
}
|
|
133
148
|
} finally {
|
|
149
|
+
pendingRequestCount.current -= 1;
|
|
134
150
|
if (standardRowsUpdateStrategyActive && lastRequestId.current === requestId) {
|
|
135
151
|
apiRef.current.setLoading(false);
|
|
136
152
|
}
|
|
@@ -283,6 +299,13 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
283
299
|
stopPolling();
|
|
284
300
|
debouncedFetchRows();
|
|
285
301
|
}, [apiRef, props.dataSourceKeepPreviousData, stopPolling, debouncedFetchRows]);
|
|
302
|
+
const hasFilterModelChanged = useGridDataSourceFilterModelChange(apiRef);
|
|
303
|
+
const handleFetchRowsOnFilterModelChange = React.useCallback(newFilterModel => {
|
|
304
|
+
if (!hasFilterModelChanged(newFilterModel)) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
handleFetchRowsOnParamsChange();
|
|
308
|
+
}, [hasFilterModelChanged, handleFetchRowsOnParamsChange]);
|
|
286
309
|
const isFirstRender = React.useRef(true);
|
|
287
310
|
React.useEffect(() => {
|
|
288
311
|
if (isFirstRender.current) {
|
|
@@ -306,12 +329,34 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
306
329
|
}
|
|
307
330
|
}, [revalidateMs, stopPolling]);
|
|
308
331
|
React.useEffect(() => stopPolling, [stopPolling]);
|
|
332
|
+
const lastApiRef = React.useRef(apiRef);
|
|
333
|
+
const lastStrategy = React.useRef(currentStrategy);
|
|
334
|
+
const lastDataSource = React.useRef(props.dataSource);
|
|
309
335
|
React.useEffect(() => {
|
|
336
|
+
// `<Activity mode="hidden">` leaves the root element in the document, a real unmount does not.
|
|
337
|
+
// Only discard the in-flight response in the latter case, so hiding lets the request land.
|
|
338
|
+
const rootElement = apiRef.current?.rootElementRef?.current ?? null;
|
|
339
|
+
const ignoreInFlightRequest = () => {
|
|
340
|
+
if (!rootElement?.isConnected) {
|
|
341
|
+
lastRequestId.current += 1;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
310
345
|
// Return early if the proper strategy isn't set yet
|
|
311
346
|
// Context: https://github.com/mui/mui-x/issues/19650
|
|
312
347
|
if (currentStrategy !== DataSourceRowsUpdateStrategy.Default && currentStrategy !== DataSourceRowsUpdateStrategy.LazyLoading && currentStrategy !== DataSourceRowsUpdateStrategy.GroupedData && currentStrategy !== DataSourceRowsUpdateStrategy.LazyLoadedGroupedData) {
|
|
313
348
|
return undefined;
|
|
314
349
|
}
|
|
350
|
+
const dependenciesChanged = lastApiRef.current !== apiRef || lastStrategy.current !== currentStrategy || lastDataSource.current !== props.dataSource;
|
|
351
|
+
lastApiRef.current = apiRef;
|
|
352
|
+
lastStrategy.current = currentStrategy;
|
|
353
|
+
lastDataSource.current = props.dataSource;
|
|
354
|
+
|
|
355
|
+
// Re-mounting the effect (`<Activity />` becoming visible again, for instance) must not
|
|
356
|
+
// re-fetch data that is already displayed.
|
|
357
|
+
if (!dependenciesChanged && (rowsAreUpToDate.current || pendingRequestCount.current > 0)) {
|
|
358
|
+
return ignoreInFlightRequest;
|
|
359
|
+
}
|
|
315
360
|
if (props.dataSource) {
|
|
316
361
|
stopPolling();
|
|
317
362
|
// `dataSourceKeepPreviousData` only applies to the flat `Default` strategy (mirroring
|
|
@@ -325,10 +370,7 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
325
370
|
apiRef.current.dataSource.cache.clear();
|
|
326
371
|
apiRef.current.dataSource.fetchRows();
|
|
327
372
|
}
|
|
328
|
-
return
|
|
329
|
-
// ignore the current request on unmount
|
|
330
|
-
lastRequestId.current += 1;
|
|
331
|
-
};
|
|
373
|
+
return ignoreInFlightRequest;
|
|
332
374
|
}, [apiRef, props.dataSource, props.dataSourceKeepPreviousData, currentStrategy, stopPolling]);
|
|
333
375
|
React.useEffect(() => {
|
|
334
376
|
// `dataSourceKeepPreviousData` is a no-op for tree data and row grouping: those
|
|
@@ -356,7 +398,7 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
|
|
|
356
398
|
events: {
|
|
357
399
|
strategyAvailabilityChange: handleStrategyActivityChange,
|
|
358
400
|
sortModelChange: runIf(standardRowsUpdateStrategyActive, handleFetchRowsOnParamsChange),
|
|
359
|
-
filterModelChange: runIf(standardRowsUpdateStrategyActive,
|
|
401
|
+
filterModelChange: runIf(standardRowsUpdateStrategyActive, handleFetchRowsOnFilterModelChange),
|
|
360
402
|
paginationModelChange: runIf(standardRowsUpdateStrategyActive, handleFetchRowsOnParamsChange)
|
|
361
403
|
}
|
|
362
404
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RefObject } from '@mui/x-internals/types';
|
|
2
|
+
import type { GridFilterModel } from "../../../models/gridFilterModel.mjs";
|
|
3
|
+
import type { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Tracks the filter model as the data source sees it, the parts that cannot apply excluded.
|
|
6
|
+
* Returns a predicate telling whether a new model would ask for something else: editing an
|
|
7
|
+
* incomplete item, or flipping a logic operator that has nothing to combine, is a no-op.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useGridDataSourceFilterModelChange: (apiRef: RefObject<GridPrivateApiCommunity>) => (filterModel: GridFilterModel) => boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RefObject } from '@mui/x-internals/types';
|
|
2
|
+
import type { GridFilterModel } from "../../../models/gridFilterModel.js";
|
|
3
|
+
import type { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
4
|
+
/**
|
|
5
|
+
* Tracks the filter model as the data source sees it, the parts that cannot apply excluded.
|
|
6
|
+
* Returns a predicate telling whether a new model would ask for something else: editing an
|
|
7
|
+
* incomplete item, or flipping a logic operator that has nothing to combine, is a no-op.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useGridDataSourceFilterModelChange: (apiRef: RefObject<GridPrivateApiCommunity>) => (filterModel: GridFilterModel) => boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.useGridDataSourceFilterModelChange = void 0;
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
|
|
12
|
+
var _isDeepEqual = require("@mui/x-internals/isDeepEqual");
|
|
13
|
+
var _columns = require("../columns");
|
|
14
|
+
var _gridFilterSelector = require("../filter/gridFilterSelector");
|
|
15
|
+
var _gridFilterState = require("../filter/gridFilterState");
|
|
16
|
+
var _gridFilterUtils = require("../filter/gridFilterUtils");
|
|
17
|
+
/**
|
|
18
|
+
* The parts of a filter model that can change the rows the data source returns, so that a
|
|
19
|
+
* change to the rest is not mistaken for a new query. A logic operator needs two operands to
|
|
20
|
+
* mean anything, and quick filter values only apply once one of them is truthy
|
|
21
|
+
* (`buildAggregatedQuickFilterApplier` returns `null` otherwise).
|
|
22
|
+
* Falsy values are kept when another one applies: `passFilterLogic` runs the whole array
|
|
23
|
+
* through its logic operator, so `['a', '']` and `['a']` do not match the same rows.
|
|
24
|
+
*/
|
|
25
|
+
const getApplicableFilterModel = (model, columnsLookup) => {
|
|
26
|
+
const defaultModel = (0, _gridFilterState.getDefaultGridFilterModel)();
|
|
27
|
+
const {
|
|
28
|
+
items
|
|
29
|
+
} = (0, _gridFilterUtils.removeIncompleteFilterItems)(model, columnsLookup);
|
|
30
|
+
const appliesQuickFilter = model.quickFilterValues?.some(Boolean) ?? false;
|
|
31
|
+
const quickFilterValues = appliesQuickFilter ? model.quickFilterValues ?? [] : [];
|
|
32
|
+
return {
|
|
33
|
+
items,
|
|
34
|
+
logicOperator: items.length > 1 ? model.logicOperator ?? defaultModel.logicOperator : null,
|
|
35
|
+
quickFilterValues,
|
|
36
|
+
quickFilterLogicOperator: quickFilterValues.length > 1 ? model.quickFilterLogicOperator ?? defaultModel.quickFilterLogicOperator : null,
|
|
37
|
+
quickFilterExcludeHiddenColumns: appliesQuickFilter ? model.quickFilterExcludeHiddenColumns ?? defaultModel.quickFilterExcludeHiddenColumns : null
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tracks the filter model as the data source sees it, the parts that cannot apply excluded.
|
|
43
|
+
* Returns a predicate telling whether a new model would ask for something else: editing an
|
|
44
|
+
* incomplete item, or flipping a logic operator that has nothing to combine, is a no-op.
|
|
45
|
+
*/
|
|
46
|
+
const useGridDataSourceFilterModelChange = apiRef => {
|
|
47
|
+
const lastFetchedFilterModel = (0, _useLazyRef.default)(() => getApplicableFilterModel((0, _gridFilterSelector.gridFilterModelSelector)(apiRef), (0, _columns.gridColumnLookupSelector)(apiRef)));
|
|
48
|
+
return React.useCallback(filterModel => {
|
|
49
|
+
const applicableFilterModel = getApplicableFilterModel(filterModel, (0, _columns.gridColumnLookupSelector)(apiRef));
|
|
50
|
+
if ((0, _isDeepEqual.isDeepEqual)(applicableFilterModel, lastFetchedFilterModel.current)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
lastFetchedFilterModel.current = applicableFilterModel;
|
|
54
|
+
return true;
|
|
55
|
+
}, [apiRef, lastFetchedFilterModel]);
|
|
56
|
+
};
|
|
57
|
+
exports.useGridDataSourceFilterModelChange = useGridDataSourceFilterModelChange;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import useLazyRef from '@mui/utils/useLazyRef';
|
|
5
|
+
import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
|
|
6
|
+
import { gridColumnLookupSelector } from "../columns/index.mjs";
|
|
7
|
+
import { gridFilterModelSelector } from "../filter/gridFilterSelector.mjs";
|
|
8
|
+
import { getDefaultGridFilterModel } from "../filter/gridFilterState.mjs";
|
|
9
|
+
import { removeIncompleteFilterItems } from "../filter/gridFilterUtils.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* The parts of a filter model that can change the rows the data source returns, so that a
|
|
12
|
+
* change to the rest is not mistaken for a new query. A logic operator needs two operands to
|
|
13
|
+
* mean anything, and quick filter values only apply once one of them is truthy
|
|
14
|
+
* (`buildAggregatedQuickFilterApplier` returns `null` otherwise).
|
|
15
|
+
* Falsy values are kept when another one applies: `passFilterLogic` runs the whole array
|
|
16
|
+
* through its logic operator, so `['a', '']` and `['a']` do not match the same rows.
|
|
17
|
+
*/
|
|
18
|
+
const getApplicableFilterModel = (model, columnsLookup) => {
|
|
19
|
+
const defaultModel = getDefaultGridFilterModel();
|
|
20
|
+
const {
|
|
21
|
+
items
|
|
22
|
+
} = removeIncompleteFilterItems(model, columnsLookup);
|
|
23
|
+
const appliesQuickFilter = model.quickFilterValues?.some(Boolean) ?? false;
|
|
24
|
+
const quickFilterValues = appliesQuickFilter ? model.quickFilterValues ?? [] : [];
|
|
25
|
+
return {
|
|
26
|
+
items,
|
|
27
|
+
logicOperator: items.length > 1 ? model.logicOperator ?? defaultModel.logicOperator : null,
|
|
28
|
+
quickFilterValues,
|
|
29
|
+
quickFilterLogicOperator: quickFilterValues.length > 1 ? model.quickFilterLogicOperator ?? defaultModel.quickFilterLogicOperator : null,
|
|
30
|
+
quickFilterExcludeHiddenColumns: appliesQuickFilter ? model.quickFilterExcludeHiddenColumns ?? defaultModel.quickFilterExcludeHiddenColumns : null
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Tracks the filter model as the data source sees it, the parts that cannot apply excluded.
|
|
36
|
+
* Returns a predicate telling whether a new model would ask for something else: editing an
|
|
37
|
+
* incomplete item, or flipping a logic operator that has nothing to combine, is a no-op.
|
|
38
|
+
*/
|
|
39
|
+
export const useGridDataSourceFilterModelChange = apiRef => {
|
|
40
|
+
const lastFetchedFilterModel = useLazyRef(() => getApplicableFilterModel(gridFilterModelSelector(apiRef), gridColumnLookupSelector(apiRef)));
|
|
41
|
+
return React.useCallback(filterModel => {
|
|
42
|
+
const applicableFilterModel = getApplicableFilterModel(filterModel, gridColumnLookupSelector(apiRef));
|
|
43
|
+
if (isDeepEqual(applicableFilterModel, lastFetchedFilterModel.current)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
lastFetchedFilterModel.current = applicableFilterModel;
|
|
47
|
+
return true;
|
|
48
|
+
}, [apiRef, lastFetchedFilterModel]);
|
|
49
|
+
};
|
|
@@ -18,6 +18,7 @@ var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedE
|
|
|
18
18
|
var _isDeepEqual = require("@mui/x-internals/isDeepEqual");
|
|
19
19
|
var _useGridEvent = require("../../utils/useGridEvent");
|
|
20
20
|
var _gridEditRowModel = require("../../../models/gridEditRowModel");
|
|
21
|
+
var _getPublicApiRef = require("../../../utils/getPublicApiRef");
|
|
21
22
|
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
22
23
|
var _gridEditingSelectors = require("./gridEditingSelectors");
|
|
23
24
|
var _keyboardUtils = require("../../../utils/keyboardUtils");
|
|
@@ -195,7 +196,8 @@ const useGridCellEditing = (apiRef, props) => {
|
|
|
195
196
|
const isNewModelDifferentFromProp = newModel !== props.cellModesModel;
|
|
196
197
|
if (onCellModesModelChange && isNewModelDifferentFromProp) {
|
|
197
198
|
onCellModesModelChange(newModel, {
|
|
198
|
-
api: apiRef.current
|
|
199
|
+
api: apiRef.current,
|
|
200
|
+
apiRef: (0, _getPublicApiRef.getPublicApiRef)(apiRef)
|
|
199
201
|
});
|
|
200
202
|
}
|
|
201
203
|
if (props.cellModesModel && isNewModelDifferentFromProp) {
|