@mui/x-data-grid-pro 8.0.0-beta.3 → 8.1.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 +388 -96
- package/DataGridPro/DataGridPro.js +8 -7
- package/DataGridPro/useDataGridProComponent.d.ts +2 -2
- package/DataGridPro/useDataGridProComponent.js +2 -3
- package/components/GridDetailPanel.js +1 -2
- package/components/headerFiltering/GridHeaderFilterMenu.js +2 -2
- package/esm/DataGridPro/DataGridPro.js +9 -8
- package/esm/DataGridPro/useDataGridProComponent.d.ts +2 -2
- package/esm/DataGridPro/useDataGridProComponent.js +2 -3
- package/esm/components/GridDetailPanel.js +1 -2
- package/esm/components/headerFiltering/GridHeaderFilterMenu.js +2 -2
- package/esm/hooks/features/dataSource/useGridDataSourceBasePro.d.ts +3 -6
- package/esm/hooks/features/dataSource/useGridDataSourceBasePro.js +36 -8
- package/esm/hooks/features/dataSource/utils.d.ts +3 -2
- package/esm/hooks/features/dataSource/utils.js +13 -1
- package/esm/hooks/features/detailPanel/useGridDetailPanel.js +4 -3
- package/esm/hooks/features/lazyLoader/useGridLazyLoader.d.ts +1 -1
- package/esm/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.d.ts +1 -1
- package/esm/hooks/features/rowPinning/useGridRowPinning.d.ts +1 -1
- package/esm/hooks/features/serverSideLazyLoader/useGridDataSourceLazyLoader.js +38 -1
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +1 -0
- package/esm/internals/index.js +1 -0
- package/esm/material/icons.d.ts +3 -6
- package/esm/material/icons.js +1 -1
- package/esm/material/index.d.ts +2 -2
- package/esm/models/dataGridProProps.d.ts +3 -3
- package/esm/models/gridProIconSlotsComponent.d.ts +6 -3
- package/esm/package.json +1 -1
- package/hooks/features/dataSource/useGridDataSourceBasePro.d.ts +3 -6
- package/hooks/features/dataSource/useGridDataSourceBasePro.js +34 -6
- package/hooks/features/dataSource/utils.d.ts +3 -2
- package/hooks/features/dataSource/utils.js +15 -2
- package/hooks/features/detailPanel/useGridDetailPanel.js +4 -3
- package/hooks/features/lazyLoader/useGridLazyLoader.d.ts +1 -1
- package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.d.ts +1 -1
- package/hooks/features/rowPinning/useGridRowPinning.d.ts +1 -1
- package/hooks/features/serverSideLazyLoader/useGridDataSourceLazyLoader.js +37 -0
- package/index.js +1 -1
- package/internals/index.d.ts +1 -0
- package/internals/index.js +15 -7
- package/material/icons.d.ts +3 -6
- package/material/icons.js +3 -3
- package/material/index.d.ts +2 -2
- package/models/dataGridProProps.d.ts +3 -3
- package/models/gridProIconSlotsComponent.d.ts +6 -3
- package/package.json +8 -14
- package/esm/utils/releaseInfo.d.ts +0 -1
- package/esm/utils/releaseInfo.js +0 -13
- package/modern/DataGridPro/DataGrid.d.ts +0 -8
- package/modern/DataGridPro/DataGrid.js +0 -19
- package/modern/DataGridPro/DataGridPro.d.ts +0 -16
- package/modern/DataGridPro/DataGridPro.js +0 -1020
- package/modern/DataGridPro/index.d.ts +0 -3
- package/modern/DataGridPro/index.js +0 -3
- package/modern/DataGridPro/useDataGridProComponent.d.ts +0 -4
- package/modern/DataGridPro/useDataGridProComponent.js +0 -105
- package/modern/DataGridPro/useDataGridProProps.d.ts +0 -7
- package/modern/DataGridPro/useDataGridProProps.js +0 -54
- package/modern/components/GridColumnHeaders.d.ts +0 -5
- package/modern/components/GridColumnHeaders.js +0 -92
- package/modern/components/GridColumnMenuPinningItem.d.ts +0 -7
- package/modern/components/GridColumnMenuPinningItem.js +0 -77
- package/modern/components/GridDataSourceTreeDataGroupingCell.d.ts +0 -12
- package/modern/components/GridDataSourceTreeDataGroupingCell.js +0 -107
- package/modern/components/GridDetailPanel.d.ts +0 -14
- package/modern/components/GridDetailPanel.js +0 -53
- package/modern/components/GridDetailPanelToggleCell.d.ts +0 -7
- package/modern/components/GridDetailPanelToggleCell.js +0 -121
- package/modern/components/GridDetailPanels.d.ts +0 -3
- package/modern/components/GridDetailPanels.js +0 -67
- package/modern/components/GridPinnedRows.d.ts +0 -6
- package/modern/components/GridPinnedRows.js +0 -40
- package/modern/components/GridProColumnMenu.d.ts +0 -24
- package/modern/components/GridProColumnMenu.js +0 -21
- package/modern/components/GridRowReorderCell.d.ts +0 -8
- package/modern/components/GridRowReorderCell.js +0 -140
- package/modern/components/GridTreeDataGroupingCell.d.ts +0 -15
- package/modern/components/GridTreeDataGroupingCell.js +0 -133
- package/modern/components/headerFiltering/GridHeaderFilterCell.d.ts +0 -26
- package/modern/components/headerFiltering/GridHeaderFilterCell.js +0 -362
- package/modern/components/headerFiltering/GridHeaderFilterClearButton.d.ts +0 -6
- package/modern/components/headerFiltering/GridHeaderFilterClearButton.js +0 -17
- package/modern/components/headerFiltering/GridHeaderFilterMenu.d.ts +0 -30
- package/modern/components/headerFiltering/GridHeaderFilterMenu.js +0 -137
- package/modern/components/headerFiltering/GridHeaderFilterMenuContainer.d.ts +0 -17
- package/modern/components/headerFiltering/GridHeaderFilterMenuContainer.js +0 -138
- package/modern/components/headerFiltering/index.d.ts +0 -3
- package/modern/components/headerFiltering/index.js +0 -3
- package/modern/components/index.d.ts +0 -6
- package/modern/components/index.js +0 -7
- package/modern/components/reexports.d.ts +0 -1
- package/modern/components/reexports.js +0 -1
- package/modern/constants/dataGridProDefaultSlotsComponents.d.ts +0 -2
- package/modern/constants/dataGridProDefaultSlotsComponents.js +0 -17
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +0 -12
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +0 -143
- package/modern/hooks/features/columnPinning/gridColumnPinningInterface.d.ts +0 -40
- package/modern/hooks/features/columnPinning/gridColumnPinningInterface.js +0 -1
- package/modern/hooks/features/columnPinning/index.d.ts +0 -1
- package/modern/hooks/features/columnPinning/index.js +0 -1
- package/modern/hooks/features/columnPinning/useGridColumnPinning.d.ts +0 -6
- package/modern/hooks/features/columnPinning/useGridColumnPinning.js +0 -228
- package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.d.ts +0 -4
- package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +0 -105
- package/modern/hooks/features/columnReorder/columnReorderInterfaces.d.ts +0 -6
- package/modern/hooks/features/columnReorder/columnReorderInterfaces.js +0 -1
- package/modern/hooks/features/columnReorder/columnReorderSelector.d.ts +0 -3
- package/modern/hooks/features/columnReorder/columnReorderSelector.js +0 -3
- package/modern/hooks/features/columnReorder/index.d.ts +0 -2
- package/modern/hooks/features/columnReorder/index.js +0 -2
- package/modern/hooks/features/columnReorder/useGridColumnReorder.d.ts +0 -9
- package/modern/hooks/features/columnReorder/useGridColumnReorder.js +0 -242
- package/modern/hooks/features/dataSource/gridDataSourceSelector.d.ts +0 -7
- package/modern/hooks/features/dataSource/gridDataSourceSelector.js +0 -6
- package/modern/hooks/features/dataSource/models.d.ts +0 -75
- package/modern/hooks/features/dataSource/models.js +0 -1
- package/modern/hooks/features/dataSource/useGridDataSourceBasePro.d.ts +0 -33
- package/modern/hooks/features/dataSource/useGridDataSourceBasePro.js +0 -179
- package/modern/hooks/features/dataSource/useGridDataSourcePro.d.ts +0 -6
- package/modern/hooks/features/dataSource/useGridDataSourcePro.js +0 -35
- package/modern/hooks/features/dataSource/utils.d.ts +0 -29
- package/modern/hooks/features/dataSource/utils.js +0 -82
- package/modern/hooks/features/detailPanel/gridDetailPanelInterface.d.ts +0 -41
- package/modern/hooks/features/detailPanel/gridDetailPanelInterface.js +0 -1
- package/modern/hooks/features/detailPanel/gridDetailPanelSelector.d.ts +0 -14
- package/modern/hooks/features/detailPanel/gridDetailPanelSelector.js +0 -5
- package/modern/hooks/features/detailPanel/gridDetailPanelToggleColDef.d.ts +0 -4
- package/modern/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +0 -34
- package/modern/hooks/features/detailPanel/index.d.ts +0 -3
- package/modern/hooks/features/detailPanel/index.js +0 -3
- package/modern/hooks/features/detailPanel/useGridDetailPanel.d.ts +0 -6
- package/modern/hooks/features/detailPanel/useGridDetailPanel.js +0 -191
- package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.d.ts +0 -4
- package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +0 -43
- package/modern/hooks/features/index.d.ts +0 -7
- package/modern/hooks/features/index.js +0 -8
- package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.d.ts +0 -9
- package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.js +0 -104
- package/modern/hooks/features/lazyLoader/useGridLazyLoader.d.ts +0 -10
- package/modern/hooks/features/lazyLoader/useGridLazyLoader.js +0 -90
- package/modern/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.d.ts +0 -5
- package/modern/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +0 -34
- package/modern/hooks/features/lazyLoader/utils.d.ts +0 -18
- package/modern/hooks/features/lazyLoader/utils.js +0 -34
- package/modern/hooks/features/rowPinning/gridRowPinningInterface.d.ts +0 -17
- package/modern/hooks/features/rowPinning/gridRowPinningInterface.js +0 -1
- package/modern/hooks/features/rowPinning/gridRowPinningSelector.d.ts +0 -1
- package/modern/hooks/features/rowPinning/gridRowPinningSelector.js +0 -1
- package/modern/hooks/features/rowPinning/index.d.ts +0 -1
- package/modern/hooks/features/rowPinning/index.js +0 -1
- package/modern/hooks/features/rowPinning/useGridRowPinning.d.ts +0 -6
- package/modern/hooks/features/rowPinning/useGridRowPinning.js +0 -52
- package/modern/hooks/features/rowPinning/useGridRowPinningPreProcessors.d.ts +0 -38
- package/modern/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +0 -119
- package/modern/hooks/features/rowReorder/gridRowReorderColDef.d.ts +0 -2
- package/modern/hooks/features/rowReorder/gridRowReorderColDef.js +0 -20
- package/modern/hooks/features/rowReorder/index.d.ts +0 -1
- package/modern/hooks/features/rowReorder/index.js +0 -1
- package/modern/hooks/features/rowReorder/useGridRowReorder.d.ts +0 -8
- package/modern/hooks/features/rowReorder/useGridRowReorder.js +0 -141
- package/modern/hooks/features/rowReorder/useGridRowReorderPreProcessors.d.ts +0 -4
- package/modern/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +0 -46
- package/modern/hooks/features/rows/index.d.ts +0 -1
- package/modern/hooks/features/rows/index.js +0 -1
- package/modern/hooks/features/rows/useGridRowAriaAttributes.d.ts +0 -3
- package/modern/hooks/features/rows/useGridRowAriaAttributes.js +0 -37
- package/modern/hooks/features/serverSideLazyLoader/useGridDataSourceLazyLoader.d.ts +0 -10
- package/modern/hooks/features/serverSideLazyLoader/useGridDataSourceLazyLoader.js +0 -325
- package/modern/hooks/features/serverSideTreeData/useGridDataSourceTreeDataPreProcessors.d.ts +0 -4
- package/modern/hooks/features/serverSideTreeData/useGridDataSourceTreeDataPreProcessors.js +0 -148
- package/modern/hooks/features/serverSideTreeData/utils.d.ts +0 -7
- package/modern/hooks/features/serverSideTreeData/utils.js +0 -18
- package/modern/hooks/features/treeData/gridTreeDataGroupColDef.d.ts +0 -8
- package/modern/hooks/features/treeData/gridTreeDataGroupColDef.js +0 -27
- package/modern/hooks/features/treeData/gridTreeDataUtils.d.ts +0 -22
- package/modern/hooks/features/treeData/gridTreeDataUtils.js +0 -95
- package/modern/hooks/features/treeData/index.d.ts +0 -1
- package/modern/hooks/features/treeData/index.js +0 -1
- package/modern/hooks/features/treeData/useGridTreeData.d.ts +0 -4
- package/modern/hooks/features/treeData/useGridTreeData.js +0 -22
- package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.d.ts +0 -4
- package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +0 -148
- package/modern/hooks/index.d.ts +0 -1
- package/modern/hooks/index.js +0 -1
- package/modern/hooks/utils/useGridApiContext.d.ts +0 -4
- package/modern/hooks/utils/useGridApiContext.js +0 -2
- package/modern/hooks/utils/useGridApiRef.d.ts +0 -4
- package/modern/hooks/utils/useGridApiRef.js +0 -2
- package/modern/hooks/utils/useGridAriaAttributes.d.ts +0 -2
- package/modern/hooks/utils/useGridAriaAttributes.js +0 -11
- package/modern/hooks/utils/useGridPrivateApiContext.d.ts +0 -2
- package/modern/hooks/utils/useGridPrivateApiContext.js +0 -2
- package/modern/hooks/utils/useGridRootProps.d.ts +0 -2
- package/modern/hooks/utils/useGridRootProps.js +0 -2
- package/modern/index.d.ts +0 -22
- package/modern/index.js +0 -25
- package/modern/internals/index.d.ts +0 -33
- package/modern/internals/index.js +0 -38
- package/modern/internals/propValidation.d.ts +0 -3
- package/modern/internals/propValidation.js +0 -2
- package/modern/locales.d.ts +0 -1
- package/modern/locales.js +0 -1
- package/modern/material/icons.d.ts +0 -6
- package/modern/material/icons.js +0 -17
- package/modern/material/index.d.ts +0 -5
- package/modern/material/index.js +0 -8
- package/modern/models/dataGridProProps.d.ts +0 -222
- package/modern/models/dataGridProProps.js +0 -1
- package/modern/models/gridApiPro.d.ts +0 -11
- package/modern/models/gridApiPro.js +0 -1
- package/modern/models/gridFetchRowsParams.d.ts +0 -22
- package/modern/models/gridFetchRowsParams.js +0 -1
- package/modern/models/gridGroupingColDefOverride.d.ts +0 -30
- package/modern/models/gridGroupingColDefOverride.js +0 -1
- package/modern/models/gridProIconSlotsComponent.d.ts +0 -13
- package/modern/models/gridProIconSlotsComponent.js +0 -1
- package/modern/models/gridProSlotProps.d.ts +0 -8
- package/modern/models/gridProSlotProps.js +0 -1
- package/modern/models/gridProSlotsComponent.d.ts +0 -18
- package/modern/models/gridProSlotsComponent.js +0 -1
- package/modern/models/gridRowOrderChangeParams.d.ts +0 -18
- package/modern/models/gridRowOrderChangeParams.js +0 -1
- package/modern/models/gridRowScrollEndParams.d.ts +0 -18
- package/modern/models/gridRowScrollEndParams.js +0 -1
- package/modern/models/gridStatePro.d.ts +0 -19
- package/modern/models/gridStatePro.js +0 -1
- package/modern/models/index.d.ts +0 -7
- package/modern/models/index.js +0 -7
- package/modern/package.json +0 -1
- package/modern/themeAugmentation/index.d.ts +0 -2
- package/modern/themeAugmentation/index.js +0 -4
- package/modern/themeAugmentation/overrides.d.ts +0 -7
- package/modern/themeAugmentation/overrides.js +0 -1
- package/modern/themeAugmentation/props.d.ts +0 -15
- package/modern/themeAugmentation/props.js +0 -1
- package/modern/typeOverloads/index.d.ts +0 -1
- package/modern/typeOverloads/index.js +0 -1
- package/modern/typeOverloads/modules.d.ts +0 -70
- package/modern/typeOverloads/modules.js +0 -1
- package/modern/typeOverloads/reexports.d.ts +0 -17
- package/modern/typeOverloads/reexports.js +0 -15
- package/modern/utils/index.d.ts +0 -1
- package/modern/utils/index.js +0 -1
- package/modern/utils/releaseInfo.d.ts +0 -1
- package/modern/utils/releaseInfo.js +0 -13
- package/modern/utils/tree/createRowTree.d.ts +0 -17
- package/modern/utils/tree/createRowTree.js +0 -37
- package/modern/utils/tree/index.d.ts +0 -1
- package/modern/utils/tree/index.js +0 -1
- package/modern/utils/tree/insertDataRowInTree.d.ts +0 -69
- package/modern/utils/tree/insertDataRowInTree.js +0 -141
- package/modern/utils/tree/models.d.ts +0 -14
- package/modern/utils/tree/models.js +0 -1
- package/modern/utils/tree/removeDataRowFromTree.d.ts +0 -45
- package/modern/utils/tree/removeDataRowFromTree.js +0 -94
- package/modern/utils/tree/sortRowTree.d.ts +0 -15
- package/modern/utils/tree/sortRowTree.js +0 -114
- package/modern/utils/tree/updateRowTree.d.ts +0 -20
- package/modern/utils/tree/updateRowTree.js +0 -88
- package/modern/utils/tree/utils.d.ts +0 -54
- package/modern/utils/tree/utils.js +0 -197
- package/tsconfig.build.tsbuildinfo +0 -1
- package/utils/releaseInfo.d.ts +0 -1
- package/utils/releaseInfo.js +0 -20
- /package/esm/{locales.d.ts → locales/index.d.ts} +0 -0
- /package/esm/{locales.js → locales/index.js} +0 -0
- /package/{locales.d.ts → locales/index.d.ts} +0 -0
- /package/{locales.js → locales/index.js} +0 -0
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import useLazyRef from '@mui/utils/useLazyRef';
|
|
4
|
-
import { useGridSelector, GridGetRowsError } from '@mui/x-data-grid';
|
|
5
|
-
import { gridRowGroupsToFetchSelector, useGridDataSourceBase, CacheChunkManager, gridGetRowsParamsSelector, DataSourceRowsUpdateStrategy, GridStrategyGroup } from '@mui/x-data-grid/internals';
|
|
6
|
-
import { warnOnce } from '@mui/x-internals/warning';
|
|
7
|
-
import { NestedDataManager, RequestStatus } from "./utils.js";
|
|
8
|
-
import { gridDataSourceErrorsSelector } from "./gridDataSourceSelector.js";
|
|
9
|
-
export const INITIAL_STATE = {
|
|
10
|
-
loading: {},
|
|
11
|
-
errors: {}
|
|
12
|
-
};
|
|
13
|
-
export const useGridDataSourceBasePro = (apiRef, props, options = {}) => {
|
|
14
|
-
const groupsToAutoFetch = useGridSelector(apiRef, gridRowGroupsToFetchSelector);
|
|
15
|
-
const nestedDataManager = useLazyRef(() => new NestedDataManager(apiRef)).current;
|
|
16
|
-
const scheduledGroups = React.useRef(0);
|
|
17
|
-
const clearDataSourceState = React.useCallback(() => {
|
|
18
|
-
nestedDataManager.clear();
|
|
19
|
-
scheduledGroups.current = 0;
|
|
20
|
-
const dataSourceState = apiRef.current.state.dataSource;
|
|
21
|
-
if (dataSourceState !== INITIAL_STATE) {
|
|
22
|
-
apiRef.current.resetDataSourceState();
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}, [apiRef, nestedDataManager]);
|
|
26
|
-
const {
|
|
27
|
-
api,
|
|
28
|
-
strategyProcessor,
|
|
29
|
-
events,
|
|
30
|
-
cacheChunkManager,
|
|
31
|
-
cache
|
|
32
|
-
} = useGridDataSourceBase(apiRef, props, _extends({}, options, {
|
|
33
|
-
fetchRowChildren: nestedDataManager.queue,
|
|
34
|
-
clearDataSourceState
|
|
35
|
-
}));
|
|
36
|
-
const setStrategyAvailability = React.useCallback(() => {
|
|
37
|
-
apiRef.current.setStrategyAvailability(GridStrategyGroup.DataSource, DataSourceRowsUpdateStrategy.Default, props.dataSource && !props.lazyLoading ? () => true : () => false);
|
|
38
|
-
}, [apiRef, props.dataSource, props.lazyLoading]);
|
|
39
|
-
const onDataSourceErrorProp = props.onDataSourceError;
|
|
40
|
-
const fetchRowChildren = React.useCallback(async id => {
|
|
41
|
-
const pipedParams = apiRef.current.unstable_applyPipeProcessors('getRowsParams', {});
|
|
42
|
-
if (!props.treeData && (pipedParams.groupFields?.length ?? 0) === 0) {
|
|
43
|
-
nestedDataManager.clearPendingRequest(id);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const getRows = props.dataSource?.getRows;
|
|
47
|
-
if (!getRows) {
|
|
48
|
-
nestedDataManager.clearPendingRequest(id);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const rowNode = apiRef.current.getRowNode(id);
|
|
52
|
-
if (!rowNode) {
|
|
53
|
-
nestedDataManager.clearPendingRequest(id);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const fetchParams = _extends({}, gridGetRowsParamsSelector(apiRef), pipedParams, {
|
|
57
|
-
groupKeys: rowNode.path
|
|
58
|
-
});
|
|
59
|
-
const cacheKeys = cacheChunkManager.getCacheKeys(fetchParams);
|
|
60
|
-
const responses = cacheKeys.map(cacheKey => cache.get(cacheKey));
|
|
61
|
-
const cachedData = responses.some(response => response === undefined) ? undefined : CacheChunkManager.mergeResponses(responses);
|
|
62
|
-
if (cachedData !== undefined) {
|
|
63
|
-
const rows = cachedData.rows;
|
|
64
|
-
nestedDataManager.setRequestSettled(id);
|
|
65
|
-
apiRef.current.updateServerRows(rows, rowNode.path);
|
|
66
|
-
apiRef.current.setRowCount(cachedData.rowCount === undefined ? -1 : cachedData.rowCount);
|
|
67
|
-
apiRef.current.setRowChildrenExpansion(id, true);
|
|
68
|
-
apiRef.current.dataSource.setChildrenLoading(id, false);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const existingError = gridDataSourceErrorsSelector(apiRef)[id] ?? null;
|
|
72
|
-
if (existingError) {
|
|
73
|
-
apiRef.current.dataSource.setChildrenFetchError(id, null);
|
|
74
|
-
}
|
|
75
|
-
try {
|
|
76
|
-
const getRowsResponse = await getRows(fetchParams);
|
|
77
|
-
if (!apiRef.current.getRowNode(id)) {
|
|
78
|
-
// The row has been removed from the grid
|
|
79
|
-
nestedDataManager.clearPendingRequest(id);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (nestedDataManager.getRequestStatus(id) === RequestStatus.UNKNOWN) {
|
|
83
|
-
apiRef.current.dataSource.setChildrenLoading(id, false);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
nestedDataManager.setRequestSettled(id);
|
|
87
|
-
const cacheResponses = cacheChunkManager.splitResponse(fetchParams, getRowsResponse);
|
|
88
|
-
cacheResponses.forEach((response, key) => {
|
|
89
|
-
cache.set(key, response);
|
|
90
|
-
});
|
|
91
|
-
apiRef.current.setRowCount(getRowsResponse.rowCount === undefined ? -1 : getRowsResponse.rowCount);
|
|
92
|
-
apiRef.current.updateServerRows(getRowsResponse.rows, rowNode.path);
|
|
93
|
-
apiRef.current.setRowChildrenExpansion(id, true);
|
|
94
|
-
} catch (error) {
|
|
95
|
-
const childrenFetchError = error;
|
|
96
|
-
apiRef.current.dataSource.setChildrenFetchError(id, childrenFetchError);
|
|
97
|
-
if (typeof onDataSourceErrorProp === 'function') {
|
|
98
|
-
onDataSourceErrorProp(new GridGetRowsError({
|
|
99
|
-
message: childrenFetchError.message,
|
|
100
|
-
params: fetchParams,
|
|
101
|
-
cause: childrenFetchError
|
|
102
|
-
}));
|
|
103
|
-
} else if (process.env.NODE_ENV !== 'production') {
|
|
104
|
-
warnOnce(['MUI X: A call to `dataSource.getRows()` threw an error which was not handled because `unstable_onDataSourceError()` is missing.', 'To handle the error pass a callback to the `onDataSourceError` prop, for example `<DataGrid unstable_onDataSourceError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/server-side-data/#error-handling.'], 'error');
|
|
105
|
-
}
|
|
106
|
-
} finally {
|
|
107
|
-
apiRef.current.dataSource.setChildrenLoading(id, false);
|
|
108
|
-
nestedDataManager.setRequestSettled(id);
|
|
109
|
-
}
|
|
110
|
-
}, [nestedDataManager, cacheChunkManager, cache, onDataSourceErrorProp, apiRef, props.treeData, props.dataSource?.getRows]);
|
|
111
|
-
const setChildrenLoading = React.useCallback((parentId, isLoading) => {
|
|
112
|
-
apiRef.current.setState(state => {
|
|
113
|
-
if (!state.dataSource.loading[parentId] && isLoading === false) {
|
|
114
|
-
return state;
|
|
115
|
-
}
|
|
116
|
-
const newLoadingState = _extends({}, state.dataSource.loading);
|
|
117
|
-
if (isLoading === false) {
|
|
118
|
-
delete newLoadingState[parentId];
|
|
119
|
-
} else {
|
|
120
|
-
newLoadingState[parentId] = isLoading;
|
|
121
|
-
}
|
|
122
|
-
return _extends({}, state, {
|
|
123
|
-
dataSource: _extends({}, state.dataSource, {
|
|
124
|
-
loading: newLoadingState
|
|
125
|
-
})
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
}, [apiRef]);
|
|
129
|
-
const setChildrenFetchError = React.useCallback((parentId, error) => {
|
|
130
|
-
apiRef.current.setState(state => {
|
|
131
|
-
const newErrorsState = _extends({}, state.dataSource.errors);
|
|
132
|
-
if (error === null && newErrorsState[parentId] !== undefined) {
|
|
133
|
-
delete newErrorsState[parentId];
|
|
134
|
-
} else {
|
|
135
|
-
newErrorsState[parentId] = error;
|
|
136
|
-
}
|
|
137
|
-
return _extends({}, state, {
|
|
138
|
-
dataSource: _extends({}, state.dataSource, {
|
|
139
|
-
errors: newErrorsState
|
|
140
|
-
})
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}, [apiRef]);
|
|
144
|
-
const resetDataSourceState = React.useCallback(() => {
|
|
145
|
-
apiRef.current.setState(state => {
|
|
146
|
-
return _extends({}, state, {
|
|
147
|
-
dataSource: INITIAL_STATE
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
}, [apiRef]);
|
|
151
|
-
const dataSourceApi = {
|
|
152
|
-
dataSource: _extends({}, api.public.dataSource, {
|
|
153
|
-
setChildrenLoading,
|
|
154
|
-
setChildrenFetchError
|
|
155
|
-
})
|
|
156
|
-
};
|
|
157
|
-
const dataSourcePrivateApi = {
|
|
158
|
-
fetchRowChildren,
|
|
159
|
-
resetDataSourceState
|
|
160
|
-
};
|
|
161
|
-
React.useEffect(() => {
|
|
162
|
-
if (groupsToAutoFetch && groupsToAutoFetch.length && scheduledGroups.current < groupsToAutoFetch.length) {
|
|
163
|
-
const groupsToSchedule = groupsToAutoFetch.slice(scheduledGroups.current);
|
|
164
|
-
nestedDataManager.queue(groupsToSchedule);
|
|
165
|
-
scheduledGroups.current = groupsToAutoFetch.length;
|
|
166
|
-
}
|
|
167
|
-
}, [apiRef, nestedDataManager, groupsToAutoFetch]);
|
|
168
|
-
return {
|
|
169
|
-
api: {
|
|
170
|
-
public: dataSourceApi,
|
|
171
|
-
private: dataSourcePrivateApi
|
|
172
|
-
},
|
|
173
|
-
strategyProcessor,
|
|
174
|
-
events,
|
|
175
|
-
setStrategyAvailability,
|
|
176
|
-
cacheChunkManager,
|
|
177
|
-
cache
|
|
178
|
-
};
|
|
179
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import { GridStateInitializer } from '@mui/x-data-grid/internals';
|
|
3
|
-
import { GridPrivateApiPro } from "../../../models/gridApiPro.js";
|
|
4
|
-
import { DataGridProProcessedProps } from "../../../models/dataGridProProps.js";
|
|
5
|
-
export declare const dataSourceStateInitializer: GridStateInitializer;
|
|
6
|
-
export declare const useGridDataSourcePro: (apiRef: RefObject<GridPrivateApiPro>, props: DataGridProProcessedProps) => void;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { useGridEvent as addEventHandler, useGridApiMethod } from '@mui/x-data-grid';
|
|
4
|
-
import { useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
|
|
5
|
-
import { INITIAL_STATE, useGridDataSourceBasePro } from "./useGridDataSourceBasePro.js";
|
|
6
|
-
function getKeyPro(params) {
|
|
7
|
-
return JSON.stringify([params.filterModel, params.sortModel, params.groupKeys, params.start, params.end]);
|
|
8
|
-
}
|
|
9
|
-
export const dataSourceStateInitializer = state => {
|
|
10
|
-
return _extends({}, state, {
|
|
11
|
-
dataSource: INITIAL_STATE
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
const options = {
|
|
15
|
-
cacheOptions: {
|
|
16
|
-
getKey: getKeyPro
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
export const useGridDataSourcePro = (apiRef, props) => {
|
|
20
|
-
const {
|
|
21
|
-
api,
|
|
22
|
-
strategyProcessor,
|
|
23
|
-
events,
|
|
24
|
-
setStrategyAvailability
|
|
25
|
-
} = useGridDataSourceBasePro(apiRef, props, options);
|
|
26
|
-
useGridApiMethod(apiRef, api.public, 'public');
|
|
27
|
-
useGridApiMethod(apiRef, api.private, 'private');
|
|
28
|
-
useGridRegisterStrategyProcessor(apiRef, strategyProcessor.strategyName, strategyProcessor.group, strategyProcessor.processor);
|
|
29
|
-
Object.entries(events).forEach(([event, handler]) => {
|
|
30
|
-
addEventHandler(apiRef, event, handler);
|
|
31
|
-
});
|
|
32
|
-
React.useEffect(() => {
|
|
33
|
-
setStrategyAvailability();
|
|
34
|
-
}, [setStrategyAvailability]);
|
|
35
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import { GridRowId } from '@mui/x-data-grid';
|
|
3
|
-
import { GridPrivateApiPro } from "../../../models/index.js";
|
|
4
|
-
export declare enum RequestStatus {
|
|
5
|
-
QUEUED = 0,
|
|
6
|
-
PENDING = 1,
|
|
7
|
-
SETTLED = 2,
|
|
8
|
-
UNKNOWN = 3,
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Fetches row children from the server with option to limit the number of concurrent requests
|
|
12
|
-
* Determines the status of a request based on the enum `RequestStatus`
|
|
13
|
-
* Uses `GridRowId` to uniquely identify a request
|
|
14
|
-
*/
|
|
15
|
-
export declare class NestedDataManager {
|
|
16
|
-
private pendingRequests;
|
|
17
|
-
private queuedRequests;
|
|
18
|
-
private settledRequests;
|
|
19
|
-
private api;
|
|
20
|
-
private maxConcurrentRequests;
|
|
21
|
-
constructor(privateApiRef: RefObject<GridPrivateApiPro>, maxConcurrentRequests?: number);
|
|
22
|
-
private processQueue;
|
|
23
|
-
queue: (ids: GridRowId[]) => Promise<void>;
|
|
24
|
-
setRequestSettled: (id: GridRowId) => void;
|
|
25
|
-
clear: () => void;
|
|
26
|
-
clearPendingRequest: (id: GridRowId) => void;
|
|
27
|
-
getRequestStatus: (id: GridRowId) => RequestStatus;
|
|
28
|
-
getActiveRequestsCount: () => number;
|
|
29
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
const MAX_CONCURRENT_REQUESTS = Infinity;
|
|
3
|
-
export let RequestStatus = /*#__PURE__*/function (RequestStatus) {
|
|
4
|
-
RequestStatus[RequestStatus["QUEUED"] = 0] = "QUEUED";
|
|
5
|
-
RequestStatus[RequestStatus["PENDING"] = 1] = "PENDING";
|
|
6
|
-
RequestStatus[RequestStatus["SETTLED"] = 2] = "SETTLED";
|
|
7
|
-
RequestStatus[RequestStatus["UNKNOWN"] = 3] = "UNKNOWN";
|
|
8
|
-
return RequestStatus;
|
|
9
|
-
}({});
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Fetches row children from the server with option to limit the number of concurrent requests
|
|
13
|
-
* Determines the status of a request based on the enum `RequestStatus`
|
|
14
|
-
* Uses `GridRowId` to uniquely identify a request
|
|
15
|
-
*/
|
|
16
|
-
export class NestedDataManager {
|
|
17
|
-
constructor(privateApiRef, maxConcurrentRequests = MAX_CONCURRENT_REQUESTS) {
|
|
18
|
-
this.pendingRequests = new Set();
|
|
19
|
-
this.queuedRequests = new Set();
|
|
20
|
-
this.settledRequests = new Set();
|
|
21
|
-
this.api = void 0;
|
|
22
|
-
this.maxConcurrentRequests = void 0;
|
|
23
|
-
this.processQueue = async () => {
|
|
24
|
-
if (this.queuedRequests.size === 0 || this.pendingRequests.size >= this.maxConcurrentRequests) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const loopLength = Math.min(this.maxConcurrentRequests - this.pendingRequests.size, this.queuedRequests.size);
|
|
28
|
-
if (loopLength === 0) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const fetchQueue = Array.from(this.queuedRequests);
|
|
32
|
-
for (let i = 0; i < loopLength; i += 1) {
|
|
33
|
-
const id = fetchQueue[i];
|
|
34
|
-
this.queuedRequests.delete(id);
|
|
35
|
-
this.pendingRequests.add(id);
|
|
36
|
-
this.api.fetchRowChildren(id);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
this.queue = async ids => {
|
|
40
|
-
const loadingIds = {};
|
|
41
|
-
ids.forEach(id => {
|
|
42
|
-
this.queuedRequests.add(id);
|
|
43
|
-
loadingIds[id] = true;
|
|
44
|
-
});
|
|
45
|
-
this.api.setState(state => _extends({}, state, {
|
|
46
|
-
dataSource: _extends({}, state.dataSource, {
|
|
47
|
-
loading: _extends({}, state.dataSource.loading, loadingIds)
|
|
48
|
-
})
|
|
49
|
-
}));
|
|
50
|
-
this.processQueue();
|
|
51
|
-
};
|
|
52
|
-
this.setRequestSettled = id => {
|
|
53
|
-
this.pendingRequests.delete(id);
|
|
54
|
-
this.settledRequests.add(id);
|
|
55
|
-
this.processQueue();
|
|
56
|
-
};
|
|
57
|
-
this.clear = () => {
|
|
58
|
-
this.queuedRequests.clear();
|
|
59
|
-
Array.from(this.pendingRequests).forEach(id => this.clearPendingRequest(id));
|
|
60
|
-
};
|
|
61
|
-
this.clearPendingRequest = id => {
|
|
62
|
-
this.api.dataSource.setChildrenLoading(id, false);
|
|
63
|
-
this.pendingRequests.delete(id);
|
|
64
|
-
this.processQueue();
|
|
65
|
-
};
|
|
66
|
-
this.getRequestStatus = id => {
|
|
67
|
-
if (this.pendingRequests.has(id)) {
|
|
68
|
-
return RequestStatus.PENDING;
|
|
69
|
-
}
|
|
70
|
-
if (this.queuedRequests.has(id)) {
|
|
71
|
-
return RequestStatus.QUEUED;
|
|
72
|
-
}
|
|
73
|
-
if (this.settledRequests.has(id)) {
|
|
74
|
-
return RequestStatus.SETTLED;
|
|
75
|
-
}
|
|
76
|
-
return RequestStatus.UNKNOWN;
|
|
77
|
-
};
|
|
78
|
-
this.getActiveRequestsCount = () => this.pendingRequests.size + this.queuedRequests.size;
|
|
79
|
-
this.api = privateApiRef.current;
|
|
80
|
-
this.maxConcurrentRequests = maxConcurrentRequests;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { GridRowId } from '@mui/x-data-grid';
|
|
3
|
-
type DetailPanelHeightCache = Record<GridRowId, {
|
|
4
|
-
autoHeight: boolean;
|
|
5
|
-
height: number;
|
|
6
|
-
}>;
|
|
7
|
-
/**
|
|
8
|
-
* The master/detail API interface that is available in the grid [[apiRef]].
|
|
9
|
-
*/
|
|
10
|
-
export interface GridDetailPanelApi {
|
|
11
|
-
/**
|
|
12
|
-
* Expands or collapses the detail panel of a row.
|
|
13
|
-
* @param {string} id The row id to toggle the panel.
|
|
14
|
-
*/
|
|
15
|
-
toggleDetailPanel: (id: GridRowId) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Returns the rows whose detail panel is open.
|
|
18
|
-
* @returns {GridRowId[]} An array of row ids.
|
|
19
|
-
*/
|
|
20
|
-
getExpandedDetailPanels: () => Set<GridRowId>;
|
|
21
|
-
/**
|
|
22
|
-
* Changes which rows to expand the detail panel.
|
|
23
|
-
* @param {GridRowId[]} ids The ids of the rows to open the detail panel.
|
|
24
|
-
*/
|
|
25
|
-
setExpandedDetailPanels: (ids: Set<GridRowId>) => void;
|
|
26
|
-
}
|
|
27
|
-
export interface GridDetailPanelPrivateApi {
|
|
28
|
-
/**
|
|
29
|
-
* Stores the panel height measurement and triggers the row height pre-processing.
|
|
30
|
-
* @param {GridRowId} id The id of the row.
|
|
31
|
-
* @param {number} height The new height.
|
|
32
|
-
*/
|
|
33
|
-
storeDetailPanelHeight: (id: GridRowId, height: number) => void;
|
|
34
|
-
}
|
|
35
|
-
export interface GridDetailPanelState {
|
|
36
|
-
expandedRowIds: Set<GridRowId>;
|
|
37
|
-
contentCache: Record<GridRowId, React.ReactNode>;
|
|
38
|
-
heightCache: DetailPanelHeightCache;
|
|
39
|
-
}
|
|
40
|
-
export type GridDetailPanelInitialState = Pick<GridDetailPanelState, 'expandedRowIds'>;
|
|
41
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { GridStatePro } from "../../../models/gridStatePro.js";
|
|
2
|
-
export declare const gridDetailPanelStateSelector: import("@mui/x-data-grid").OutputSelector<GridStatePro, unknown, import("./gridDetailPanelInterface").GridDetailPanelState>;
|
|
3
|
-
export declare const gridDetailPanelExpandedRowIdsSelector: import("@mui/x-data-grid").OutputSelector<GridStatePro, import("./gridDetailPanelInterface").GridDetailPanelState, Set<import("@mui/x-data-grid").GridRowId>>;
|
|
4
|
-
export declare const gridDetailPanelExpandedRowsContentCacheSelector: import("@mui/x-data-grid").OutputSelector<GridStatePro, import("./gridDetailPanelInterface").GridDetailPanelState, Record<import("@mui/x-data-grid").GridRowId, import("react").ReactNode>>;
|
|
5
|
-
export declare const gridDetailPanelRawHeightCacheSelector: import("@mui/x-data-grid").OutputSelector<GridStatePro, import("./gridDetailPanelInterface").GridDetailPanelState, {
|
|
6
|
-
[x: string]: {
|
|
7
|
-
autoHeight: boolean;
|
|
8
|
-
height: number;
|
|
9
|
-
};
|
|
10
|
-
[x: number]: {
|
|
11
|
-
autoHeight: boolean;
|
|
12
|
-
height: number;
|
|
13
|
-
};
|
|
14
|
-
}>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { createSelector, createRootSelector, createSelectorMemoized } from '@mui/x-data-grid/internals';
|
|
2
|
-
export const gridDetailPanelStateSelector = createRootSelector(state => state.detailPanel);
|
|
3
|
-
export const gridDetailPanelExpandedRowIdsSelector = createSelector(gridDetailPanelStateSelector, detailPanelState => detailPanelState.expandedRowIds);
|
|
4
|
-
export const gridDetailPanelExpandedRowsContentCacheSelector = createSelector(gridDetailPanelStateSelector, detailPanelState => detailPanelState.contentCache);
|
|
5
|
-
export const gridDetailPanelRawHeightCacheSelector = createSelectorMemoized(gridDetailPanelStateSelector, detailPanelState => detailPanelState.heightCache);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { GRID_STRING_COL_DEF, gridRowIdSelector } from '@mui/x-data-grid';
|
|
4
|
-
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from '@mui/x-data-grid/internals';
|
|
5
|
-
import { GridDetailPanelToggleCell } from "../../../components/GridDetailPanelToggleCell.js";
|
|
6
|
-
import { gridDetailPanelExpandedRowIdsSelector } from "./gridDetailPanelSelector.js";
|
|
7
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
export { GRID_DETAIL_PANEL_TOGGLE_FIELD };
|
|
9
|
-
export const GRID_DETAIL_PANEL_TOGGLE_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
10
|
-
type: 'custom',
|
|
11
|
-
field: GRID_DETAIL_PANEL_TOGGLE_FIELD,
|
|
12
|
-
editable: false,
|
|
13
|
-
sortable: false,
|
|
14
|
-
filterable: false,
|
|
15
|
-
resizable: false,
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
aggregable: false,
|
|
18
|
-
disableColumnMenu: true,
|
|
19
|
-
disableReorder: true,
|
|
20
|
-
disableExport: true,
|
|
21
|
-
align: 'left',
|
|
22
|
-
width: 40,
|
|
23
|
-
valueGetter: (value, row, column, apiRef) => {
|
|
24
|
-
const rowId = gridRowIdSelector(apiRef, row);
|
|
25
|
-
const expandedRowIds = gridDetailPanelExpandedRowIdsSelector(apiRef);
|
|
26
|
-
return expandedRowIds.has(rowId);
|
|
27
|
-
},
|
|
28
|
-
renderCell: params => /*#__PURE__*/_jsx(GridDetailPanelToggleCell, _extends({}, params)),
|
|
29
|
-
renderHeader: ({
|
|
30
|
-
colDef
|
|
31
|
-
}) => /*#__PURE__*/_jsx("div", {
|
|
32
|
-
"aria-label": colDef.headerName
|
|
33
|
-
})
|
|
34
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import { GridStateInitializer } from '@mui/x-data-grid/internals';
|
|
3
|
-
import { GridPrivateApiPro } from "../../../models/gridApiPro.js";
|
|
4
|
-
import { DataGridProProcessedProps } from "../../../models/dataGridProProps.js";
|
|
5
|
-
export declare const detailPanelStateInitializer: GridStateInitializer<Pick<DataGridProProcessedProps, 'initialState' | 'detailPanelExpandedRowIds'>>;
|
|
6
|
-
export declare const useGridDetailPanel: (apiRef: RefObject<GridPrivateApiPro>, props: Pick<DataGridProProcessedProps, "getDetailPanelContent" | "getDetailPanelHeight" | "detailPanelExpandedRowIds" | "onDetailPanelExpandedRowIdsChange">) => void;
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { useGridSelector, useGridEvent, useGridApiMethod, gridDataRowIdsSelector } from '@mui/x-data-grid';
|
|
4
|
-
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
|
|
5
|
-
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "./gridDetailPanelToggleColDef.js";
|
|
6
|
-
import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelRawHeightCacheSelector } from "./gridDetailPanelSelector.js";
|
|
7
|
-
const emptySet = new Set();
|
|
8
|
-
export const detailPanelStateInitializer = (state, props) => {
|
|
9
|
-
return _extends({}, state, {
|
|
10
|
-
detailPanel: {
|
|
11
|
-
heightCache: {},
|
|
12
|
-
expandedRowIds: props.detailPanelExpandedRowIds ?? props.initialState?.detailPanel?.expandedRowIds ?? emptySet
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight, previousHeightCache) {
|
|
17
|
-
if (typeof getDetailPanelContent !== 'function') {
|
|
18
|
-
return {};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// TODO change to lazy approach using a Proxy
|
|
22
|
-
// only call getDetailPanelContent when asked for an id
|
|
23
|
-
const rowIds = gridDataRowIdsSelector(apiRef);
|
|
24
|
-
const contentCache = {};
|
|
25
|
-
const heightCache = {};
|
|
26
|
-
for (let i = 0; i < rowIds.length; i += 1) {
|
|
27
|
-
const id = rowIds[i];
|
|
28
|
-
const params = apiRef.current.getRowParams(id);
|
|
29
|
-
const content = getDetailPanelContent(params);
|
|
30
|
-
contentCache[id] = content;
|
|
31
|
-
if (content == null) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
const height = getDetailPanelHeight(params);
|
|
35
|
-
const autoHeight = height === 'auto';
|
|
36
|
-
heightCache[id] = {
|
|
37
|
-
autoHeight,
|
|
38
|
-
height: autoHeight ? previousHeightCache[id]?.height : height
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
contentCache,
|
|
43
|
-
heightCache
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export const useGridDetailPanel = (apiRef, props) => {
|
|
47
|
-
const expandedRowIds = useGridSelector(apiRef, gridDetailPanelExpandedRowIdsSelector);
|
|
48
|
-
const contentCache = useGridSelector(apiRef, gridDetailPanelExpandedRowsContentCacheSelector);
|
|
49
|
-
const handleCellClick = React.useCallback((params, event) => {
|
|
50
|
-
if (params.field !== GRID_DETAIL_PANEL_TOGGLE_FIELD || props.getDetailPanelContent == null) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const content = contentCache[params.id];
|
|
54
|
-
if (! /*#__PURE__*/React.isValidElement(content)) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Ignore if the user didn't click specifically in the "i" button
|
|
59
|
-
if (event.target === event.currentTarget) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
apiRef.current.toggleDetailPanel(params.id);
|
|
63
|
-
}, [apiRef, contentCache, props.getDetailPanelContent]);
|
|
64
|
-
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
65
|
-
if (props.getDetailPanelContent == null) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (params.field === GRID_DETAIL_PANEL_TOGGLE_FIELD && event.key === ' ') {
|
|
69
|
-
apiRef.current.toggleDetailPanel(params.id);
|
|
70
|
-
}
|
|
71
|
-
}, [apiRef, props.getDetailPanelContent]);
|
|
72
|
-
useGridEvent(apiRef, 'cellClick', handleCellClick);
|
|
73
|
-
useGridEvent(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
74
|
-
apiRef.current.registerControlState({
|
|
75
|
-
stateId: 'detailPanels',
|
|
76
|
-
propModel: props.detailPanelExpandedRowIds,
|
|
77
|
-
propOnChange: props.onDetailPanelExpandedRowIdsChange,
|
|
78
|
-
stateSelector: gridDetailPanelExpandedRowIdsSelector,
|
|
79
|
-
changeEvent: 'detailPanelsExpandedRowIdsChange'
|
|
80
|
-
});
|
|
81
|
-
const toggleDetailPanel = React.useCallback(id => {
|
|
82
|
-
if (props.getDetailPanelContent == null) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const content = contentCache[id];
|
|
86
|
-
if (! /*#__PURE__*/React.isValidElement(content)) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const ids = apiRef.current.getExpandedDetailPanels();
|
|
90
|
-
const newIds = new Set(ids);
|
|
91
|
-
if (ids.has(id)) {
|
|
92
|
-
newIds.delete(id);
|
|
93
|
-
} else {
|
|
94
|
-
newIds.add(id);
|
|
95
|
-
}
|
|
96
|
-
apiRef.current.setExpandedDetailPanels(newIds);
|
|
97
|
-
}, [apiRef, contentCache, props.getDetailPanelContent]);
|
|
98
|
-
const getExpandedDetailPanels = React.useCallback(() => gridDetailPanelExpandedRowIdsSelector(apiRef), [apiRef]);
|
|
99
|
-
const setExpandedDetailPanels = React.useCallback(ids => {
|
|
100
|
-
apiRef.current.setState(state => {
|
|
101
|
-
return _extends({}, state, {
|
|
102
|
-
detailPanel: _extends({}, state.detailPanel, {
|
|
103
|
-
expandedRowIds: ids
|
|
104
|
-
})
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
}, [apiRef]);
|
|
108
|
-
const storeDetailPanelHeight = React.useCallback((id, height) => {
|
|
109
|
-
const heightCache = gridDetailPanelRawHeightCacheSelector(apiRef);
|
|
110
|
-
if (!heightCache[id] || heightCache[id].height === height) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
apiRef.current.setState(state => {
|
|
114
|
-
return _extends({}, state, {
|
|
115
|
-
detailPanel: _extends({}, state.detailPanel, {
|
|
116
|
-
heightCache: _extends({}, heightCache, {
|
|
117
|
-
[id]: _extends({}, heightCache[id], {
|
|
118
|
-
height
|
|
119
|
-
})
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
apiRef.current.requestPipeProcessorsApplication('rowHeight');
|
|
125
|
-
}, [apiRef]);
|
|
126
|
-
const detailPanelPubicApi = {
|
|
127
|
-
toggleDetailPanel,
|
|
128
|
-
getExpandedDetailPanels,
|
|
129
|
-
setExpandedDetailPanels
|
|
130
|
-
};
|
|
131
|
-
const detailPanelPrivateApi = {
|
|
132
|
-
storeDetailPanelHeight
|
|
133
|
-
};
|
|
134
|
-
useGridApiMethod(apiRef, detailPanelPubicApi, 'public');
|
|
135
|
-
useGridApiMethod(apiRef, detailPanelPrivateApi, 'private');
|
|
136
|
-
React.useEffect(() => {
|
|
137
|
-
if (props.detailPanelExpandedRowIds) {
|
|
138
|
-
const currentModel = gridDetailPanelExpandedRowIdsSelector(apiRef);
|
|
139
|
-
if (currentModel !== props.detailPanelExpandedRowIds) {
|
|
140
|
-
apiRef.current.setExpandedDetailPanels(props.detailPanelExpandedRowIds);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}, [apiRef, props.detailPanelExpandedRowIds]);
|
|
144
|
-
const updateCaches = React.useCallback(() => {
|
|
145
|
-
if (!props.getDetailPanelContent) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
apiRef.current.setState(state => {
|
|
149
|
-
return _extends({}, state, {
|
|
150
|
-
detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight, state.detailPanel.heightCache))
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
}, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
|
|
154
|
-
useGridEvent(apiRef, 'sortedRowsSet', updateCaches);
|
|
155
|
-
const previousGetDetailPanelContentProp = React.useRef(undefined);
|
|
156
|
-
const previousGetDetailPanelHeightProp = React.useRef(undefined);
|
|
157
|
-
const updateCachesIfNeeded = React.useCallback(() => {
|
|
158
|
-
if (props.getDetailPanelContent === previousGetDetailPanelContentProp.current && props.getDetailPanelHeight === previousGetDetailPanelHeightProp.current) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
apiRef.current.setState(state => {
|
|
162
|
-
return _extends({}, state, {
|
|
163
|
-
detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight, state.detailPanel.heightCache))
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
previousGetDetailPanelContentProp.current = props.getDetailPanelContent;
|
|
167
|
-
previousGetDetailPanelHeightProp.current = props.getDetailPanelHeight;
|
|
168
|
-
}, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
|
|
169
|
-
const addDetailHeight = React.useCallback((initialValue, row) => {
|
|
170
|
-
if (!expandedRowIds || expandedRowIds.size === 0 || !expandedRowIds.has(row.id)) {
|
|
171
|
-
initialValue.detail = 0;
|
|
172
|
-
return initialValue;
|
|
173
|
-
}
|
|
174
|
-
updateCachesIfNeeded();
|
|
175
|
-
const heightCache = gridDetailPanelRawHeightCacheSelector(apiRef);
|
|
176
|
-
initialValue.detail = heightCache[row.id].height ?? 0; // Fallback to zero because the cache might not be ready yet (for example page was changed)
|
|
177
|
-
return initialValue;
|
|
178
|
-
}, [apiRef, expandedRowIds, updateCachesIfNeeded]);
|
|
179
|
-
const enabled = props.getDetailPanelContent !== undefined;
|
|
180
|
-
useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight, enabled);
|
|
181
|
-
const isFirstRender = React.useRef(true);
|
|
182
|
-
if (isFirstRender.current) {
|
|
183
|
-
updateCachesIfNeeded();
|
|
184
|
-
}
|
|
185
|
-
React.useEffect(() => {
|
|
186
|
-
if (!isFirstRender.current) {
|
|
187
|
-
updateCachesIfNeeded();
|
|
188
|
-
}
|
|
189
|
-
isFirstRender.current = false;
|
|
190
|
-
}, [apiRef, updateCachesIfNeeded]);
|
|
191
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import { DataGridProProcessedProps } from "../../../models/dataGridProProps.js";
|
|
3
|
-
import { GridPrivateApiPro } from "../../../models/gridApiPro.js";
|
|
4
|
-
export declare const useGridDetailPanelPreProcessors: (privateApiRef: RefObject<GridPrivateApiPro>, props: DataGridProProcessedProps) => void;
|