@mui/x-data-grid-premium 8.11.2 → 8.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 +231 -0
- package/DataGridPremium/DataGridPremium.js +29 -1
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
- package/DataGridPremium/useDataGridPremiumComponent.js +5 -2
- package/DataGridPremium/useDataGridPremiumProps.js +2 -1
- package/components/GridPremiumColumnMenu.d.ts +4 -4
- package/components/GridPremiumColumnMenu.js +6 -6
- package/components/GridPremiumToolbar.js +11 -0
- package/components/chartsIntegration/GridChartsIntegrationContext.d.ts +2 -0
- package/components/chartsIntegration/GridChartsIntegrationContext.js +11 -0
- package/components/chartsPanel/ChartsPanelTrigger.d.ts +33 -0
- package/components/chartsPanel/ChartsPanelTrigger.js +92 -0
- package/components/chartsPanel/GridChartsPanel.d.ts +21 -0
- package/components/chartsPanel/GridChartsPanel.js +243 -0
- package/components/chartsPanel/chart/GridChartsPanelChart.d.ts +12 -0
- package/components/chartsPanel/chart/GridChartsPanelChart.js +111 -0
- package/components/chartsPanel/customize/GridChartsPanelCustomize.d.ts +8 -0
- package/components/chartsPanel/customize/GridChartsPanelCustomize.js +147 -0
- package/components/chartsPanel/data/GridChartsPanelData.d.ts +4 -0
- package/components/chartsPanel/data/GridChartsPanelData.js +23 -0
- package/components/chartsPanel/data/GridChartsPanelDataBody.d.ts +12 -0
- package/components/chartsPanel/data/GridChartsPanelDataBody.js +380 -0
- package/components/chartsPanel/data/GridChartsPanelDataField.d.ts +25 -0
- package/components/chartsPanel/data/GridChartsPanelDataField.js +334 -0
- package/components/chartsPanel/data/GridChartsPanelDataFieldMenu.d.ts +11 -0
- package/components/chartsPanel/data/GridChartsPanelDataFieldMenu.js +179 -0
- package/components/chartsPanel/data/GridChartsPanelDataHeader.d.ts +7 -0
- package/components/chartsPanel/data/GridChartsPanelDataHeader.js +24 -0
- package/components/chartsPanel/data/GridChartsPanelDataSearch.d.ts +7 -0
- package/components/chartsPanel/data/GridChartsPanelDataSearch.js +80 -0
- package/components/chartsPanel/index.d.ts +2 -0
- package/components/chartsPanel/index.js +27 -0
- package/components/collapsible/Collapsible.d.ts +3 -1
- package/components/collapsible/Collapsible.js +4 -3
- package/components/{GridColumnMenuAggregationItem.js → columnMenu/menuItems/GridColumnMenuAggregationItem.js} +4 -4
- package/components/columnMenu/menuItems/GridColumnMenuChartsItem.d.ts +3 -0
- package/components/columnMenu/menuItems/GridColumnMenuChartsItem.js +36 -0
- package/components/columnMenu/menuItems/GridColumnMenuManagePanelItem.d.ts +4 -0
- package/components/columnMenu/menuItems/GridColumnMenuManagePanelItem.js +18 -0
- package/{esm/components → components/columnMenu/menuItems}/GridColumnMenuPivotItem.d.ts +1 -1
- package/components/{GridColumnMenuPivotItem.js → columnMenu/menuItems/GridColumnMenuPivotItem.js} +7 -4
- package/components/{GridColumnMenuRowGroupItem.js → columnMenu/menuItems/GridColumnMenuRowGroupItem.js} +4 -4
- package/components/{GridColumnMenuRowUngroupItem.js → columnMenu/menuItems/GridColumnMenuRowUngroupItem.js} +3 -3
- package/components/index.d.ts +3 -2
- package/components/index.js +13 -1
- package/components/pivotPanel/GridPivotPanelField.js +14 -2
- package/components/pivotPanel/GridPivotPanelHeader.js +1 -0
- package/components/pivotPanel/GridPivotPanelSearch.js +3 -0
- package/components/promptField/PromptFieldControl.js +1 -1
- package/constants/columnGroups.d.ts +1 -0
- package/constants/columnGroups.js +7 -0
- package/constants/dataGridPremiumDefaultSlotsComponents.js +1 -0
- package/context/GridChartsIntegrationContextProvider.d.ts +7 -0
- package/context/GridChartsIntegrationContextProvider.js +35 -0
- package/context/GridChartsRendererProxy.d.ts +34 -0
- package/context/GridChartsRendererProxy.js +77 -0
- package/context/index.d.ts +2 -0
- package/context/index.js +27 -0
- package/esm/DataGridPremium/DataGridPremium.js +30 -2
- package/esm/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
- package/esm/DataGridPremium/useDataGridPremiumComponent.js +5 -2
- package/esm/DataGridPremium/useDataGridPremiumProps.js +2 -1
- package/esm/components/GridPremiumColumnMenu.d.ts +4 -4
- package/esm/components/GridPremiumColumnMenu.js +6 -6
- package/esm/components/GridPremiumToolbar.js +11 -0
- package/esm/components/chartsIntegration/GridChartsIntegrationContext.d.ts +2 -0
- package/esm/components/chartsIntegration/GridChartsIntegrationContext.js +5 -0
- package/esm/components/chartsPanel/ChartsPanelTrigger.d.ts +33 -0
- package/esm/components/chartsPanel/ChartsPanelTrigger.js +85 -0
- package/esm/components/chartsPanel/GridChartsPanel.d.ts +21 -0
- package/esm/components/chartsPanel/GridChartsPanel.js +237 -0
- package/esm/components/chartsPanel/chart/GridChartsPanelChart.d.ts +12 -0
- package/esm/components/chartsPanel/chart/GridChartsPanelChart.js +104 -0
- package/esm/components/chartsPanel/customize/GridChartsPanelCustomize.d.ts +8 -0
- package/esm/components/chartsPanel/customize/GridChartsPanelCustomize.js +139 -0
- package/esm/components/chartsPanel/data/GridChartsPanelData.d.ts +4 -0
- package/esm/components/chartsPanel/data/GridChartsPanelData.js +18 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataBody.d.ts +12 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataBody.js +374 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataField.d.ts +25 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataField.js +327 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataFieldMenu.d.ts +11 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataFieldMenu.js +173 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataHeader.d.ts +7 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataHeader.js +18 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataSearch.d.ts +7 -0
- package/esm/components/chartsPanel/data/GridChartsPanelDataSearch.js +73 -0
- package/esm/components/chartsPanel/index.d.ts +2 -0
- package/esm/components/chartsPanel/index.js +2 -0
- package/esm/components/collapsible/Collapsible.d.ts +3 -1
- package/esm/components/collapsible/Collapsible.js +4 -3
- package/esm/components/{GridColumnMenuAggregationItem.js → columnMenu/menuItems/GridColumnMenuAggregationItem.js} +4 -4
- package/esm/components/columnMenu/menuItems/GridColumnMenuChartsItem.d.ts +3 -0
- package/esm/components/columnMenu/menuItems/GridColumnMenuChartsItem.js +29 -0
- package/esm/components/columnMenu/menuItems/GridColumnMenuManagePanelItem.d.ts +4 -0
- package/esm/components/columnMenu/menuItems/GridColumnMenuManagePanelItem.js +11 -0
- package/{components → esm/components/columnMenu/menuItems}/GridColumnMenuPivotItem.d.ts +1 -1
- package/esm/components/{GridColumnMenuPivotItem.js → columnMenu/menuItems/GridColumnMenuPivotItem.js} +7 -4
- package/esm/components/{GridColumnMenuRowGroupItem.js → columnMenu/menuItems/GridColumnMenuRowGroupItem.js} +4 -4
- package/esm/components/{GridColumnMenuRowUngroupItem.js → columnMenu/menuItems/GridColumnMenuRowUngroupItem.js} +3 -3
- package/esm/components/index.d.ts +3 -2
- package/esm/components/index.js +3 -2
- package/esm/components/pivotPanel/GridPivotPanelField.js +15 -3
- package/esm/components/pivotPanel/GridPivotPanelHeader.js +1 -0
- package/esm/components/pivotPanel/GridPivotPanelSearch.js +3 -0
- package/esm/components/promptField/PromptFieldControl.js +1 -1
- package/esm/constants/columnGroups.d.ts +1 -0
- package/esm/constants/columnGroups.js +1 -0
- package/esm/constants/dataGridPremiumDefaultSlotsComponents.js +1 -0
- package/esm/context/GridChartsIntegrationContextProvider.d.ts +7 -0
- package/esm/context/GridChartsIntegrationContextProvider.js +28 -0
- package/esm/context/GridChartsRendererProxy.d.ts +34 -0
- package/esm/context/GridChartsRendererProxy.js +71 -0
- package/esm/context/index.d.ts +2 -0
- package/esm/context/index.js +2 -0
- package/esm/hooks/features/aggregation/createAggregationLookup.js +5 -3
- package/esm/hooks/features/aggregation/gridAggregationInterfaces.d.ts +1 -0
- package/esm/hooks/features/aggregation/gridAggregationSelectors.d.ts +1 -0
- package/esm/hooks/features/aggregation/gridAggregationSelectors.js +3 -0
- package/esm/hooks/features/aggregation/useGridAggregation.js +13 -1
- package/esm/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +2 -1
- package/esm/hooks/features/aggregation/wrapColumnWithAggregation.js +1 -45
- package/esm/hooks/features/chartsIntegration/gridChartsIntegrationInterfaces.d.ts +65 -0
- package/esm/hooks/features/chartsIntegration/gridChartsIntegrationInterfaces.js +1 -0
- package/esm/hooks/features/chartsIntegration/gridChartsIntegrationSelectors.d.ts +17 -0
- package/esm/hooks/features/chartsIntegration/gridChartsIntegrationSelectors.js +24 -0
- package/esm/hooks/features/chartsIntegration/useGridChartsIntegration.d.ts +8 -0
- package/esm/hooks/features/chartsIntegration/useGridChartsIntegration.js +525 -0
- package/esm/hooks/features/chartsIntegration/utils.d.ts +5 -0
- package/esm/hooks/features/chartsIntegration/utils.js +32 -0
- package/esm/hooks/features/pivoting/useGridPivoting.js +1 -1
- package/esm/hooks/features/pivoting/utils.js +9 -7
- package/esm/hooks/features/rowGrouping/createGroupingColDef.js +3 -1
- package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +1 -0
- package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +3 -2
- package/esm/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +1 -0
- package/esm/hooks/features/sidebar/gridSidebarInterfaces.d.ts +1 -0
- package/esm/hooks/features/sidebar/gridSidebarInterfaces.js +1 -0
- package/esm/hooks/utils/index.d.ts +2 -1
- package/esm/hooks/utils/index.js +2 -1
- package/esm/hooks/utils/useGridChartIntegration.d.ts +2 -0
- package/esm/hooks/utils/useGridChartIntegration.js +9 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -1
- package/esm/material/icons.d.ts +4 -1
- package/esm/material/icons.js +16 -2
- package/esm/material/index.d.ts +11 -0
- package/esm/material/index.js +13 -2
- package/esm/models/dataGridPremiumProps.d.ts +22 -1
- package/esm/models/gridApiPremium.d.ts +3 -2
- package/esm/models/gridChartsIntegration.d.ts +17 -0
- package/esm/models/gridChartsIntegration.js +1 -0
- package/esm/models/gridPremiumIconSlotsComponent.d.ts +55 -0
- package/esm/models/gridPremiumSlotProps.d.ts +8 -0
- package/esm/models/gridPremiumSlotProps.js +1 -0
- package/esm/models/gridPremiumSlotsComponent.d.ts +6 -0
- package/esm/models/gridStatePremium.d.ts +5 -2
- package/esm/typeOverloads/modules.d.ts +20 -0
- package/hooks/features/aggregation/createAggregationLookup.js +5 -3
- package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +1 -0
- package/hooks/features/aggregation/gridAggregationSelectors.d.ts +1 -0
- package/hooks/features/aggregation/gridAggregationSelectors.js +3 -0
- package/hooks/features/aggregation/useGridAggregation.js +12 -0
- package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +2 -1
- package/hooks/features/aggregation/wrapColumnWithAggregation.js +0 -44
- package/hooks/features/chartsIntegration/gridChartsIntegrationInterfaces.d.ts +65 -0
- package/hooks/features/chartsIntegration/gridChartsIntegrationInterfaces.js +5 -0
- package/hooks/features/chartsIntegration/gridChartsIntegrationSelectors.d.ts +17 -0
- package/hooks/features/chartsIntegration/gridChartsIntegrationSelectors.js +30 -0
- package/hooks/features/chartsIntegration/useGridChartsIntegration.d.ts +8 -0
- package/hooks/features/chartsIntegration/useGridChartsIntegration.js +534 -0
- package/hooks/features/chartsIntegration/utils.d.ts +5 -0
- package/hooks/features/chartsIntegration/utils.js +40 -0
- package/hooks/features/pivoting/useGridPivoting.js +1 -1
- package/hooks/features/pivoting/utils.js +9 -7
- package/hooks/features/rowGrouping/createGroupingColDef.js +3 -1
- package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +1 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +3 -2
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +1 -0
- package/hooks/features/sidebar/gridSidebarInterfaces.d.ts +1 -0
- package/hooks/features/sidebar/gridSidebarInterfaces.js +1 -0
- package/hooks/utils/index.d.ts +2 -1
- package/hooks/utils/index.js +11 -0
- package/hooks/utils/useGridChartIntegration.d.ts +2 -0
- package/hooks/utils/useGridChartIntegration.js +17 -0
- package/index.d.ts +1 -0
- package/index.js +13 -1
- package/material/icons.d.ts +4 -1
- package/material/icons.js +16 -2
- package/material/index.d.ts +11 -0
- package/material/index.js +12 -1
- package/models/dataGridPremiumProps.d.ts +22 -1
- package/models/gridApiPremium.d.ts +3 -2
- package/models/gridChartsIntegration.d.ts +17 -0
- package/models/gridChartsIntegration.js +5 -0
- package/models/gridPremiumIconSlotsComponent.d.ts +55 -0
- package/models/gridPremiumSlotProps.d.ts +8 -0
- package/models/gridPremiumSlotProps.js +5 -0
- package/models/gridPremiumSlotsComponent.d.ts +6 -0
- package/models/gridStatePremium.d.ts +5 -2
- package/package.json +5 -5
- package/typeOverloads/modules.d.ts +20 -0
- /package/components/{GridColumnMenuAggregationItem.d.ts → columnMenu/menuItems/GridColumnMenuAggregationItem.d.ts} +0 -0
- /package/components/{GridColumnMenuRowGroupItem.d.ts → columnMenu/menuItems/GridColumnMenuRowGroupItem.d.ts} +0 -0
- /package/components/{GridColumnMenuRowUngroupItem.d.ts → columnMenu/menuItems/GridColumnMenuRowUngroupItem.d.ts} +0 -0
- /package/esm/components/{GridColumnMenuAggregationItem.d.ts → columnMenu/menuItems/GridColumnMenuAggregationItem.d.ts} +0 -0
- /package/esm/components/{GridColumnMenuRowGroupItem.d.ts → columnMenu/menuItems/GridColumnMenuRowGroupItem.d.ts} +0 -0
- /package/esm/components/{GridColumnMenuRowUngroupItem.d.ts → columnMenu/menuItems/GridColumnMenuRowUngroupItem.d.ts} +0 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.useGridChartsIntegration = exports.chartsIntegrationStateInitializer = exports.EMPTY_CHART_INTEGRATION_CONTEXT_STATE = void 0;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
var React = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _debounce = _interopRequireDefault(require("@mui/utils/debounce"));
|
|
13
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
14
|
+
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
15
|
+
var _gridRowGroupingUtils = require("../rowGrouping/gridRowGroupingUtils");
|
|
16
|
+
var _gridChartsIntegrationSelectors = require("./gridChartsIntegrationSelectors");
|
|
17
|
+
var _useGridChartIntegration = require("../../utils/useGridChartIntegration");
|
|
18
|
+
var _utils = require("./utils");
|
|
19
|
+
var _gridRowGroupingSelector = require("../rowGrouping/gridRowGroupingSelector");
|
|
20
|
+
var _sidebar = require("../sidebar");
|
|
21
|
+
var _gridAggregationUtils = require("../aggregation/gridAggregationUtils");
|
|
22
|
+
var _gridAggregationSelectors = require("../aggregation/gridAggregationSelectors");
|
|
23
|
+
var _gridPivotingSelectors = require("../pivoting/gridPivotingSelectors");
|
|
24
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
|
+
const chartsIntegrationStateInitializer = (state, props) => {
|
|
26
|
+
if (!props.chartsIntegration || !props.experimentalFeatures?.charts) {
|
|
27
|
+
return (0, _extends2.default)({}, state, {
|
|
28
|
+
chartsIntegration: {
|
|
29
|
+
activeChartId: '',
|
|
30
|
+
charts: {}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const rowGroupingModel = (state.rowGrouping?.model ?? []).filter(item => item !== undefined);
|
|
35
|
+
const pivotModel = state.pivoting?.active ? state.pivoting?.model : undefined;
|
|
36
|
+
const columnsLookup = state.columns?.lookup ?? {};
|
|
37
|
+
const charts = Object.fromEntries(Object.entries(props.initialState?.chartsIntegration?.charts || {}).map(([chartId, chart]) => [chartId, {
|
|
38
|
+
dimensions: (chart.dimensions || []).map(dimension => typeof dimension === 'string' ? {
|
|
39
|
+
field: dimension,
|
|
40
|
+
hidden: false
|
|
41
|
+
} : dimension).filter(dimension => columnsLookup[dimension.field]?.chartable === true && !(0, _utils.isBlockedForSection)(columnsLookup[dimension.field], 'dimensions', rowGroupingModel, pivotModel)),
|
|
42
|
+
values: (chart.values || []).map(value => typeof value === 'string' ? {
|
|
43
|
+
field: value,
|
|
44
|
+
hidden: false
|
|
45
|
+
} : value).filter(value => columnsLookup[value.field]?.chartable === true && !(0, _utils.isBlockedForSection)(columnsLookup[value.field], 'values', rowGroupingModel, pivotModel))
|
|
46
|
+
}]));
|
|
47
|
+
return (0, _extends2.default)({}, state, {
|
|
48
|
+
chartsIntegration: {
|
|
49
|
+
activeChartId: props.activeChartId ?? props.initialState?.chartsIntegration?.activeChartId ?? '',
|
|
50
|
+
charts
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.chartsIntegrationStateInitializer = chartsIntegrationStateInitializer;
|
|
55
|
+
const EMPTY_CHART_INTEGRATION_CONTEXT = {
|
|
56
|
+
chartStateLookup: {},
|
|
57
|
+
setChartState: () => {}
|
|
58
|
+
};
|
|
59
|
+
const EMPTY_CHART_INTEGRATION_CONTEXT_STATE = exports.EMPTY_CHART_INTEGRATION_CONTEXT_STATE = {
|
|
60
|
+
synced: true,
|
|
61
|
+
dimensions: [],
|
|
62
|
+
values: [],
|
|
63
|
+
type: '',
|
|
64
|
+
configuration: {}
|
|
65
|
+
};
|
|
66
|
+
const useGridChartsIntegration = (apiRef, props) => {
|
|
67
|
+
const visibleDimensions = React.useRef({});
|
|
68
|
+
const visibleValues = React.useRef({});
|
|
69
|
+
const schema = React.useMemo(() => props.slotProps?.chartsPanel?.schema || {}, [props.slotProps?.chartsPanel?.schema]);
|
|
70
|
+
const context = (0, _useGridChartIntegration.useGridChartsIntegrationContext)(true);
|
|
71
|
+
const isChartsIntegrationAvailable = !!props.chartsIntegration && !!props.experimentalFeatures?.charts && !!context;
|
|
72
|
+
const activeChartId = (0, _gridChartsIntegrationSelectors.gridChartsIntegrationActiveChartIdSelector)(apiRef);
|
|
73
|
+
const orderedFields = (0, _internals.gridColumnFieldsSelector)(apiRef);
|
|
74
|
+
const aggregationModel = (0, _gridAggregationSelectors.gridAggregationModelSelector)(apiRef);
|
|
75
|
+
const pivotActive = (0, _internals.gridPivotActiveSelector)(apiRef);
|
|
76
|
+
const pivotModel = (0, _gridPivotingSelectors.gridPivotModelSelector)(apiRef);
|
|
77
|
+
const {
|
|
78
|
+
chartStateLookup,
|
|
79
|
+
setChartState
|
|
80
|
+
} = context || EMPTY_CHART_INTEGRATION_CONTEXT;
|
|
81
|
+
const availableChartIds = React.useMemo(() => {
|
|
82
|
+
const ids = Object.keys(chartStateLookup);
|
|
83
|
+
// cleanup visibleDimensions and visibleValues references
|
|
84
|
+
Object.keys(visibleDimensions.current).forEach(chartId => {
|
|
85
|
+
if (!ids.includes(chartId)) {
|
|
86
|
+
delete visibleDimensions.current[chartId];
|
|
87
|
+
delete visibleValues.current[chartId];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return ids;
|
|
91
|
+
}, [chartStateLookup]);
|
|
92
|
+
const syncedChartIds = React.useMemo(() => availableChartIds.filter(chartId => chartStateLookup[chartId].synced !== false), [availableChartIds, chartStateLookup]);
|
|
93
|
+
const getColumnName = React.useCallback(field => {
|
|
94
|
+
const customFieldName = props.slotProps?.chartsPanel?.getColumnName?.(field);
|
|
95
|
+
if (customFieldName) {
|
|
96
|
+
return customFieldName;
|
|
97
|
+
}
|
|
98
|
+
const columns = (0, _internals.gridColumnLookupSelector)(apiRef);
|
|
99
|
+
const columnGroupPath = (0, _xDataGridPro.gridColumnGroupsUnwrappedModelSelector)(apiRef)[field] ?? [];
|
|
100
|
+
const columnGroupLookup = (0, _xDataGridPro.gridColumnGroupsLookupSelector)(apiRef);
|
|
101
|
+
const column = columns[field];
|
|
102
|
+
const columnName = column?.headerName || field;
|
|
103
|
+
if (!pivotActive || !columnGroupPath) {
|
|
104
|
+
return columnName;
|
|
105
|
+
}
|
|
106
|
+
const groupNames = columnGroupPath.map(group => columnGroupLookup[group].headerName || group);
|
|
107
|
+
return [columnName, ...groupNames].join(' - ');
|
|
108
|
+
}, [apiRef, pivotActive, props.slotProps?.chartsPanel]);
|
|
109
|
+
|
|
110
|
+
// Adds aggregation function label to the column name
|
|
111
|
+
const getValueDatasetLabel = React.useCallback(field => {
|
|
112
|
+
const customFieldName = props.slotProps?.chartsPanel?.getColumnName?.(field);
|
|
113
|
+
if (customFieldName) {
|
|
114
|
+
return customFieldName;
|
|
115
|
+
}
|
|
116
|
+
const columnName = getColumnName(field);
|
|
117
|
+
const fieldAggregation = (0, _gridAggregationSelectors.gridAggregationModelSelector)(apiRef)[field];
|
|
118
|
+
const suffix = fieldAggregation ? ` (${(0, _gridAggregationUtils.getAggregationFunctionLabel)({
|
|
119
|
+
apiRef,
|
|
120
|
+
aggregationRule: {
|
|
121
|
+
aggregationFunctionName: fieldAggregation,
|
|
122
|
+
aggregationFunction: props.aggregationFunctions[fieldAggregation] || {}
|
|
123
|
+
}
|
|
124
|
+
})})` : '';
|
|
125
|
+
return `${columnName}${suffix}`;
|
|
126
|
+
}, [apiRef, props.aggregationFunctions, props.slotProps?.chartsPanel, getColumnName]);
|
|
127
|
+
apiRef.current.registerControlState({
|
|
128
|
+
stateId: 'activeChartId',
|
|
129
|
+
propModel: props.activeChartId,
|
|
130
|
+
propOnChange: props.onActiveChartIdChange,
|
|
131
|
+
stateSelector: _gridChartsIntegrationSelectors.gridChartsIntegrationActiveChartIdSelector,
|
|
132
|
+
changeEvent: 'activeChartIdChange'
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// sometimes, updates made to the chart dimensions and values require updating other models
|
|
136
|
+
// for example, if we are adding more than one dimension, we need to set the new grouping model
|
|
137
|
+
// if we are adding new value dataset to the grouped data, we need to set the aggregation model, otherwise the values will be undefined
|
|
138
|
+
const updateOtherModels = React.useCallback(() => {
|
|
139
|
+
const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
|
|
140
|
+
if (visibleDimensions.current[activeChartId]?.length > 0 && (
|
|
141
|
+
// if there was row grouping or if we are adding more than one dimension, set the new grouping model
|
|
142
|
+
rowGroupingModel.length > 0 || visibleDimensions.current[activeChartId].length > 1) &&
|
|
143
|
+
// if row grouping model starts with dimensions in the same order, we don't have to do anything
|
|
144
|
+
visibleDimensions.current[activeChartId].some((item, index) => item.field !== rowGroupingModel[index])) {
|
|
145
|
+
// if pivoting is enabled, then the row grouping model is driven by the pivoting rows
|
|
146
|
+
const newGroupingModel = visibleDimensions.current[activeChartId].map(item => item.field);
|
|
147
|
+
if (pivotActive) {
|
|
148
|
+
apiRef.current.setPivotModel(prev => (0, _extends2.default)({}, prev, {
|
|
149
|
+
rows: newGroupingModel.map(item => ({
|
|
150
|
+
field: item,
|
|
151
|
+
hidden: false
|
|
152
|
+
}))
|
|
153
|
+
}));
|
|
154
|
+
} else {
|
|
155
|
+
apiRef.current.setRowGroupingModel(newGroupingModel);
|
|
156
|
+
apiRef.current.setColumnVisibilityModel((0, _extends2.default)({}, apiRef.current.state.columns.columnVisibilityModel, Object.fromEntries(rowGroupingModel.map(item => [item, true])), Object.fromEntries(newGroupingModel.map(item => [item, false]))));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!pivotActive && visibleValues.current[activeChartId] && rowGroupingModel.length > 0) {
|
|
160
|
+
// with row grouping add the aggregation model to the newly added value dataset
|
|
161
|
+
const aggregatedFields = Object.keys(aggregationModel);
|
|
162
|
+
visibleValues.current[activeChartId].forEach(item => {
|
|
163
|
+
const hasAggregation = aggregatedFields.includes(item.field);
|
|
164
|
+
if (!hasAggregation) {
|
|
165
|
+
apiRef.current.setAggregationModel((0, _extends2.default)({}, aggregationModel, {
|
|
166
|
+
// use the first available aggregation function
|
|
167
|
+
[item.field]: (0, _gridAggregationUtils.getAvailableAggregationFunctions)({
|
|
168
|
+
aggregationFunctions: props.aggregationFunctions,
|
|
169
|
+
colDef: item,
|
|
170
|
+
isDataSource: !!props.dataSource
|
|
171
|
+
})[0]
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}, [apiRef, props.aggregationFunctions, props.dataSource, activeChartId, pivotActive, aggregationModel]);
|
|
177
|
+
const handleRowDataUpdate = React.useCallback(chartIds => {
|
|
178
|
+
if (chartIds.length === 0 || chartIds.some(chartId => !visibleDimensions.current[chartId] || !visibleValues.current[chartId])) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
|
|
182
|
+
const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
|
|
183
|
+
const rowsPerDepth = (0, _internals.gridFilteredSortedDepthRowEntriesSelector)(apiRef);
|
|
184
|
+
const defaultDepth = Math.max(0, (visibleDimensions.current[activeChartId]?.length ?? 0) - 1);
|
|
185
|
+
const rowsAtDefaultDepth = (rowsPerDepth[defaultDepth] ?? []).length;
|
|
186
|
+
|
|
187
|
+
// keep only unique columns and transform the grouped column to carry the correct field name to get the grouped value
|
|
188
|
+
const dataColumns = [...new Set([...Object.values(visibleDimensions.current).flat(), ...Object.values(visibleValues.current).flat()])].map(column => {
|
|
189
|
+
const isColumnGrouped = rowGroupingModel.includes(column.field);
|
|
190
|
+
if (isColumnGrouped) {
|
|
191
|
+
const groupedFieldName = isColumnGrouped ? (0, _gridRowGroupingUtils.getRowGroupingFieldFromGroupingCriteria)(orderedFields.includes(_internals.GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD) ? null : column.field) : column.field;
|
|
192
|
+
const columnDefinition = apiRef.current.getColumn(groupedFieldName);
|
|
193
|
+
return (0, _extends2.default)({}, columnDefinition, {
|
|
194
|
+
dataFieldName: column.field,
|
|
195
|
+
depth: rowGroupingModel.indexOf(column.field)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return (0, _extends2.default)({}, column, {
|
|
199
|
+
dataFieldName: column.field,
|
|
200
|
+
depth: defaultDepth
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// go through the data only once and collect everything that will be needed
|
|
205
|
+
const data = Object.fromEntries(dataColumns.map(column => [column.dataFieldName, []]));
|
|
206
|
+
const dataColumnsCount = dataColumns.length;
|
|
207
|
+
for (let i = 0; i < rowsAtDefaultDepth; i += 1) {
|
|
208
|
+
for (let j = 0; j < dataColumnsCount; j += 1) {
|
|
209
|
+
// if multiple columns are grouped, we need to get the value from the parent to properly create dimension groups
|
|
210
|
+
let targetRow = rowsPerDepth[defaultDepth][i].model;
|
|
211
|
+
// if we are not at the same depth as the column we are currently processing change the target to the parent at the correct depth
|
|
212
|
+
for (let d = defaultDepth; d > dataColumns[j].depth; d -= 1) {
|
|
213
|
+
const rowId = (0, _xDataGridPro.gridRowIdSelector)(apiRef, targetRow);
|
|
214
|
+
targetRow = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, rowTree[rowId].parent);
|
|
215
|
+
}
|
|
216
|
+
const value = apiRef.current.getRowValue(targetRow, dataColumns[j]);
|
|
217
|
+
if (value !== null) {
|
|
218
|
+
data[dataColumns[j].dataFieldName].push(typeof value === 'object' && 'label' in value ? value.label : value);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
chartIds.forEach(chartId => {
|
|
223
|
+
setChartState(chartId, {
|
|
224
|
+
dimensions: visibleDimensions.current[chartId].map(dimension => ({
|
|
225
|
+
id: dimension.field,
|
|
226
|
+
label: getColumnName(dimension.field),
|
|
227
|
+
data: data[dimension.field] || []
|
|
228
|
+
})),
|
|
229
|
+
values: visibleValues.current[chartId].map(value => ({
|
|
230
|
+
id: value.field,
|
|
231
|
+
label: getValueDatasetLabel(value.field),
|
|
232
|
+
data: data[value.field] || []
|
|
233
|
+
}))
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
}, [apiRef, activeChartId, orderedFields, getColumnName, getValueDatasetLabel, setChartState]);
|
|
237
|
+
const debouncedHandleRowDataUpdate = React.useMemo(() => (0, _debounce.default)(handleRowDataUpdate, 0), [handleRowDataUpdate]);
|
|
238
|
+
const handleColumnDataUpdate = React.useCallback((chartIds, updatedChartStateLookup) => {
|
|
239
|
+
// if there are no charts, skip the data processing
|
|
240
|
+
if (chartIds.length === 0) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
|
|
244
|
+
const chartableColumns = (0, _gridChartsIntegrationSelectors.gridChartableColumnsSelector)(apiRef);
|
|
245
|
+
const selectedFields = chartIds.reduce((acc, chartId) => {
|
|
246
|
+
const values = (0, _gridChartsIntegrationSelectors.gridChartsValuesSelector)(apiRef, chartId);
|
|
247
|
+
const dimensions = (0, _gridChartsIntegrationSelectors.gridChartsDimensionsSelector)(apiRef, chartId);
|
|
248
|
+
return (0, _extends2.default)({}, acc, {
|
|
249
|
+
[chartId]: {
|
|
250
|
+
values,
|
|
251
|
+
dimensions
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}, {});
|
|
255
|
+
const values = {};
|
|
256
|
+
const dimensions = {};
|
|
257
|
+
chartIds.forEach(chartId => {
|
|
258
|
+
dimensions[chartId] = [];
|
|
259
|
+
values[chartId] = [];
|
|
260
|
+
|
|
261
|
+
// loop through dimensions and values datasets either through their length or to the max limit
|
|
262
|
+
// if the current selection is greater than the max limit, the state will be updated
|
|
263
|
+
const chartState = updatedChartStateLookup?.[chartId] || chartStateLookup[chartId];
|
|
264
|
+
const dimensionsSize = chartState?.maxDimensions ? Math.min(chartState.maxDimensions, selectedFields[chartId].dimensions.length) : selectedFields[chartId].dimensions.length;
|
|
265
|
+
const valuesSize = chartState?.maxValues ? Math.min(chartState.maxValues, selectedFields[chartId].values.length) : selectedFields[chartId].values.length;
|
|
266
|
+
|
|
267
|
+
// sanitize selectedDimensions and selectedValues while maintaining their order
|
|
268
|
+
for (let i = 0; i < valuesSize; i += 1) {
|
|
269
|
+
if (chartableColumns[selectedFields[chartId].values[i].field] && !(0, _utils.isBlockedForSection)(chartableColumns[selectedFields[chartId].values[i].field], 'values', rowGroupingModel, pivotActive ? pivotModel : undefined)) {
|
|
270
|
+
if (!values[chartId]) {
|
|
271
|
+
values[chartId] = [];
|
|
272
|
+
}
|
|
273
|
+
values[chartId].push(selectedFields[chartId].values[i]);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// dimensions cannot contain fields that are already in values
|
|
278
|
+
for (let i = 0; i < dimensionsSize; i += 1) {
|
|
279
|
+
const item = selectedFields[chartId].dimensions[i];
|
|
280
|
+
if (!selectedFields[chartId].values.some(valueItem => valueItem.field === item.field) && chartableColumns[item.field] && !(0, _utils.isBlockedForSection)(chartableColumns[item.field], 'dimensions', rowGroupingModel, pivotActive ? pivotModel : undefined)) {
|
|
281
|
+
if (!dimensions[chartId]) {
|
|
282
|
+
dimensions[chartId] = [];
|
|
283
|
+
}
|
|
284
|
+
dimensions[chartId].push(item);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// we can compare the lengths, because this function is called after the state was updated.
|
|
289
|
+
// different lengths will occur only if some items were removed during the checks above
|
|
290
|
+
if (dimensions[chartId] && selectedFields[chartId].dimensions.length !== dimensions[chartId].length) {
|
|
291
|
+
apiRef.current.updateChartDimensionsData(chartId, dimensions[chartId]);
|
|
292
|
+
}
|
|
293
|
+
if (values[chartId] && selectedFields[chartId].values.length !== values[chartId].length) {
|
|
294
|
+
apiRef.current.updateChartValuesData(chartId, values[chartId]);
|
|
295
|
+
}
|
|
296
|
+
visibleDimensions.current[chartId] = dimensions[chartId].filter(dimension => dimension.hidden !== true).map(dimension => chartableColumns[dimension.field]);
|
|
297
|
+
visibleValues.current[chartId] = values[chartId].filter(value => value.hidden !== true).map(value => chartableColumns[value.field]);
|
|
298
|
+
|
|
299
|
+
// we need to have both dimensions and values to be able to display the chart
|
|
300
|
+
if (visibleDimensions.current[chartId].length === 0 || visibleValues.current[chartId].length === 0) {
|
|
301
|
+
visibleDimensions.current[chartId] = [];
|
|
302
|
+
visibleValues.current[chartId] = [];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
updateOtherModels();
|
|
306
|
+
handleRowDataUpdate(chartIds);
|
|
307
|
+
}, [apiRef, chartStateLookup, pivotActive, pivotModel, handleRowDataUpdate, updateOtherModels]);
|
|
308
|
+
const debouncedHandleColumnDataUpdate = React.useMemo(() => (0, _debounce.default)(handleColumnDataUpdate, 0), [handleColumnDataUpdate]);
|
|
309
|
+
const setChartsPanelOpen = React.useCallback(callback => {
|
|
310
|
+
if (!isChartsIntegrationAvailable) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const panelOpen = (0, _gridChartsIntegrationSelectors.gridChartsPanelOpenSelector)(apiRef);
|
|
314
|
+
const newPanelOpen = typeof callback === 'function' ? callback(panelOpen) : callback;
|
|
315
|
+
if (panelOpen === newPanelOpen) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (newPanelOpen) {
|
|
319
|
+
apiRef.current.showSidebar(_sidebar.GridSidebarValue.Charts);
|
|
320
|
+
} else {
|
|
321
|
+
apiRef.current.hideSidebar();
|
|
322
|
+
}
|
|
323
|
+
}, [apiRef, isChartsIntegrationAvailable]);
|
|
324
|
+
const updateChartDimensionsData = React.useCallback((chartId, dimensions) => {
|
|
325
|
+
if (!isChartsIntegrationAvailable) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
apiRef.current.setState(state => {
|
|
329
|
+
const newDimensions = typeof dimensions === 'function' ? dimensions(state.chartsIntegration.charts[chartId].dimensions) : dimensions;
|
|
330
|
+
return (0, _extends2.default)({}, state, {
|
|
331
|
+
chartsIntegration: (0, _extends2.default)({}, state.chartsIntegration, {
|
|
332
|
+
charts: (0, _extends2.default)({}, state.chartsIntegration.charts, {
|
|
333
|
+
[chartId]: (0, _extends2.default)({}, state.chartsIntegration.charts[chartId], {
|
|
334
|
+
dimensions: newDimensions
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
})
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
debouncedHandleColumnDataUpdate(syncedChartIds);
|
|
341
|
+
}, [apiRef, isChartsIntegrationAvailable, syncedChartIds, debouncedHandleColumnDataUpdate]);
|
|
342
|
+
const updateChartValuesData = React.useCallback((chartId, values) => {
|
|
343
|
+
if (!isChartsIntegrationAvailable) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
apiRef.current.setState(state => {
|
|
347
|
+
const newValues = typeof values === 'function' ? values(state.chartsIntegration.charts[chartId].values) : values;
|
|
348
|
+
return (0, _extends2.default)({}, state, {
|
|
349
|
+
chartsIntegration: (0, _extends2.default)({}, state.chartsIntegration, {
|
|
350
|
+
charts: (0, _extends2.default)({}, state.chartsIntegration.charts, {
|
|
351
|
+
[chartId]: (0, _extends2.default)({}, state.chartsIntegration.charts[chartId], {
|
|
352
|
+
values: newValues
|
|
353
|
+
})
|
|
354
|
+
})
|
|
355
|
+
})
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
debouncedHandleColumnDataUpdate(syncedChartIds);
|
|
359
|
+
}, [apiRef, isChartsIntegrationAvailable, syncedChartIds, debouncedHandleColumnDataUpdate]);
|
|
360
|
+
const setActiveChartId = React.useCallback(chartId => {
|
|
361
|
+
if (!isChartsIntegrationAvailable) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
365
|
+
chartsIntegration: (0, _extends2.default)({}, state.chartsIntegration, {
|
|
366
|
+
activeChartId: chartId
|
|
367
|
+
})
|
|
368
|
+
}));
|
|
369
|
+
}, [apiRef, isChartsIntegrationAvailable]);
|
|
370
|
+
const setChartType = React.useCallback((chartId, type) => {
|
|
371
|
+
if (!isChartsIntegrationAvailable || !chartStateLookup[chartId]) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const stateUpdate = {
|
|
375
|
+
type,
|
|
376
|
+
dimensionsLabel: schema[type]?.dimensionsLabel,
|
|
377
|
+
valuesLabel: schema[type]?.valuesLabel,
|
|
378
|
+
maxDimensions: schema[type]?.maxDimensions,
|
|
379
|
+
maxValues: schema[type]?.maxValues
|
|
380
|
+
};
|
|
381
|
+
const updatedChartStateLookup = (0, _extends2.default)({}, chartStateLookup, {
|
|
382
|
+
[chartId]: (0, _extends2.default)({}, chartStateLookup[chartId], stateUpdate)
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// make sure that the new dimensions and values limits are applied before changing the chart type
|
|
386
|
+
handleColumnDataUpdate([chartId], updatedChartStateLookup);
|
|
387
|
+
setChartState(chartId, stateUpdate);
|
|
388
|
+
}, [isChartsIntegrationAvailable, chartStateLookup, schema, setChartState, handleColumnDataUpdate]);
|
|
389
|
+
const setChartSynchronizationState = React.useCallback((chartId, synced) => {
|
|
390
|
+
if (!isChartsIntegrationAvailable || !chartStateLookup[chartId]) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const stateUpdate = {
|
|
394
|
+
synced
|
|
395
|
+
};
|
|
396
|
+
const updatedChartStateLookup = (0, _extends2.default)({}, chartStateLookup, {
|
|
397
|
+
[chartId]: (0, _extends2.default)({}, chartStateLookup[chartId], stateUpdate)
|
|
398
|
+
});
|
|
399
|
+
setChartState(chartId, stateUpdate);
|
|
400
|
+
apiRef.current.publishEvent('chartSynchronizationStateChange', {
|
|
401
|
+
chartId,
|
|
402
|
+
synced
|
|
403
|
+
});
|
|
404
|
+
if (synced) {
|
|
405
|
+
debouncedHandleColumnDataUpdate([chartId], updatedChartStateLookup);
|
|
406
|
+
}
|
|
407
|
+
}, [apiRef, isChartsIntegrationAvailable, chartStateLookup, setChartState, debouncedHandleColumnDataUpdate]);
|
|
408
|
+
|
|
409
|
+
// called when a column is dragged and dropped to a different section
|
|
410
|
+
const updateDataReference = React.useCallback((field, originSection, targetSection, targetField, placementRelativeToTargetField) => {
|
|
411
|
+
const columns = (0, _internals.gridColumnLookupSelector)(apiRef);
|
|
412
|
+
const dimensions = (0, _gridChartsIntegrationSelectors.gridChartsDimensionsSelector)(apiRef, activeChartId);
|
|
413
|
+
const values = (0, _gridChartsIntegrationSelectors.gridChartsValuesSelector)(apiRef, activeChartId);
|
|
414
|
+
const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
|
|
415
|
+
if (targetSection) {
|
|
416
|
+
if ((0, _utils.isBlockedForSection)(columns[field], targetSection, rowGroupingModel, pivotActive ? pivotModel : undefined)) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const currentTargetItems = targetSection === 'dimensions' ? dimensions : values;
|
|
420
|
+
const currentMaxItems = targetSection === 'dimensions' ? chartStateLookup[activeChartId]?.maxDimensions : chartStateLookup[activeChartId]?.maxValues;
|
|
421
|
+
if (currentMaxItems && currentTargetItems.length >= currentMaxItems) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
let hidden;
|
|
426
|
+
if (originSection) {
|
|
427
|
+
const method = originSection === 'dimensions' ? updateChartDimensionsData : updateChartValuesData;
|
|
428
|
+
const currentItems = originSection === 'dimensions' ? [...dimensions] : [...values];
|
|
429
|
+
const fieldIndex = currentItems.findIndex(item => item.field === field);
|
|
430
|
+
if (fieldIndex !== -1) {
|
|
431
|
+
hidden = currentItems[fieldIndex].hidden;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// if the target is another section, remove the field from the origin section
|
|
435
|
+
if (targetSection !== originSection) {
|
|
436
|
+
currentItems.splice(fieldIndex, 1);
|
|
437
|
+
method(activeChartId, currentItems);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (targetSection) {
|
|
441
|
+
const method = targetSection === 'dimensions' ? updateChartDimensionsData : updateChartValuesData;
|
|
442
|
+
const currentItems = targetSection === 'dimensions' ? dimensions : values;
|
|
443
|
+
const remainingItems = targetSection === originSection ? currentItems.filter(item => item.field !== field) : [...currentItems];
|
|
444
|
+
|
|
445
|
+
// with row grouping add the aggregation model to the newly added values dataset
|
|
446
|
+
if (rowGroupingModel.length > 0 && targetSection === 'values') {
|
|
447
|
+
const hasAggregation = Object.keys(aggregationModel).includes(field);
|
|
448
|
+
if (!hasAggregation) {
|
|
449
|
+
apiRef.current.setAggregationModel((0, _extends2.default)({}, aggregationModel, {
|
|
450
|
+
[field]: (0, _gridAggregationUtils.getAvailableAggregationFunctions)({
|
|
451
|
+
aggregationFunctions: props.aggregationFunctions,
|
|
452
|
+
colDef: columns[field],
|
|
453
|
+
isDataSource: !!props.dataSource
|
|
454
|
+
})[0]
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (targetField) {
|
|
459
|
+
const targetFieldIndex = remainingItems.findIndex(item => item.field === targetField);
|
|
460
|
+
const targetIndex = placementRelativeToTargetField === 'top' ? targetFieldIndex : targetFieldIndex + 1;
|
|
461
|
+
remainingItems.splice(targetIndex, 0, {
|
|
462
|
+
field,
|
|
463
|
+
hidden
|
|
464
|
+
});
|
|
465
|
+
method(activeChartId, remainingItems);
|
|
466
|
+
} else {
|
|
467
|
+
method(activeChartId, [...remainingItems, {
|
|
468
|
+
field,
|
|
469
|
+
hidden
|
|
470
|
+
}]);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}, [apiRef, props.aggregationFunctions, props.dataSource, activeChartId, chartStateLookup, updateChartDimensionsData, updateChartValuesData, aggregationModel, pivotActive, pivotModel]);
|
|
474
|
+
const addColumnMenuButton = React.useCallback(menuItems => {
|
|
475
|
+
if (isChartsIntegrationAvailable) {
|
|
476
|
+
return [...menuItems, 'columnMenuManagePanelItem'];
|
|
477
|
+
}
|
|
478
|
+
return menuItems;
|
|
479
|
+
}, [isChartsIntegrationAvailable]);
|
|
480
|
+
(0, _internals.useGridRegisterPipeProcessor)(apiRef, 'columnMenu', addColumnMenuButton);
|
|
481
|
+
const addChartsPanel = React.useCallback((initialValue, value) => {
|
|
482
|
+
if (props.slots.chartsPanel && isChartsIntegrationAvailable && value === _sidebar.GridSidebarValue.Charts) {
|
|
483
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(props.slots.chartsPanel, (0, _extends2.default)({}, props.slotProps?.chartsPanel));
|
|
484
|
+
}
|
|
485
|
+
return initialValue;
|
|
486
|
+
}, [props, isChartsIntegrationAvailable]);
|
|
487
|
+
(0, _internals.useGridRegisterPipeProcessor)(apiRef, 'sidebar', addChartsPanel);
|
|
488
|
+
(0, _internals.useGridApiMethod)(apiRef, {
|
|
489
|
+
chartsIntegration: {
|
|
490
|
+
updateDataReference,
|
|
491
|
+
getColumnName
|
|
492
|
+
}
|
|
493
|
+
}, 'private');
|
|
494
|
+
(0, _internals.useGridApiMethod)(apiRef, props.experimentalFeatures?.charts ? {
|
|
495
|
+
setChartsPanelOpen,
|
|
496
|
+
setActiveChartId,
|
|
497
|
+
setChartType,
|
|
498
|
+
setChartSynchronizationState,
|
|
499
|
+
updateChartDimensionsData,
|
|
500
|
+
updateChartValuesData
|
|
501
|
+
} : {}, 'public');
|
|
502
|
+
(0, _internals.useGridEvent)(apiRef, 'columnsChange', (0, _internals.runIf)(isChartsIntegrationAvailable, () => debouncedHandleColumnDataUpdate(syncedChartIds)));
|
|
503
|
+
(0, _internals.useGridEvent)(apiRef, 'pivotModeChange', (0, _internals.runIf)(isChartsIntegrationAvailable, () => debouncedHandleColumnDataUpdate(syncedChartIds)));
|
|
504
|
+
(0, _internals.useGridEvent)(apiRef, 'filteredRowsSet', (0, _internals.runIf)(isChartsIntegrationAvailable, () => debouncedHandleRowDataUpdate(syncedChartIds)));
|
|
505
|
+
(0, _internals.useGridEvent)(apiRef, 'sortedRowsSet', (0, _internals.runIf)(isChartsIntegrationAvailable, () => debouncedHandleRowDataUpdate(syncedChartIds)));
|
|
506
|
+
React.useEffect(() => {
|
|
507
|
+
if (!activeChartId && availableChartIds.length > 0) {
|
|
508
|
+
setActiveChartId(availableChartIds[0]);
|
|
509
|
+
}
|
|
510
|
+
}, [availableChartIds, activeChartId, setActiveChartId]);
|
|
511
|
+
const isInitialized = React.useRef(false);
|
|
512
|
+
React.useEffect(() => {
|
|
513
|
+
if (isInitialized.current) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (availableChartIds.length === 0) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
isInitialized.current = true;
|
|
520
|
+
availableChartIds.forEach(chartId => {
|
|
521
|
+
const chartType = props.initialState?.chartsIntegration?.charts?.[chartId]?.chartType || '';
|
|
522
|
+
setChartState(chartId, {
|
|
523
|
+
type: chartType,
|
|
524
|
+
maxDimensions: schema[chartType]?.maxDimensions,
|
|
525
|
+
maxValues: schema[chartType]?.maxValues,
|
|
526
|
+
dimensionsLabel: schema[chartType]?.dimensionsLabel,
|
|
527
|
+
valuesLabel: schema[chartType]?.valuesLabel,
|
|
528
|
+
configuration: props.initialState?.chartsIntegration?.charts?.[chartId]?.configuration || {}
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
debouncedHandleColumnDataUpdate(syncedChartIds);
|
|
532
|
+
}, [schema, availableChartIds, syncedChartIds, props.initialState?.chartsIntegration?.charts, setChartState, debouncedHandleColumnDataUpdate]);
|
|
533
|
+
};
|
|
534
|
+
exports.useGridChartsIntegration = useGridChartsIntegration;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GridColDef } from '@mui/x-data-grid-pro';
|
|
2
|
+
import { GridRowGroupingModel } from "../rowGrouping/gridRowGroupingInterfaces.js";
|
|
3
|
+
import { GridPivotModel } from "../pivoting/gridPivotingInterfaces.js";
|
|
4
|
+
export declare const getBlockedSections: (column: GridColDef, rowGroupingModel: GridRowGroupingModel, pivotModel: GridPivotModel | undefined) => string[];
|
|
5
|
+
export declare const isBlockedForSection: (column: GridColDef, section: string, rowGroupingModel: GridRowGroupingModel, pivotModel: GridPivotModel | undefined) => boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isBlockedForSection = exports.getBlockedSections = void 0;
|
|
7
|
+
var _columnGroups = require("../../../constants/columnGroups");
|
|
8
|
+
const getBlockedSections = (column, rowGroupingModel, pivotModel) => {
|
|
9
|
+
// with pivoting, columns that are pivot values can only be added to the chart values
|
|
10
|
+
// grid columns that are pivot rows can only be added to the chart dimensions
|
|
11
|
+
// the rest of the columns can be added anywhere
|
|
12
|
+
// pivoting columns are already filtered out by the chartable columns selector
|
|
13
|
+
if (pivotModel) {
|
|
14
|
+
const sections = [];
|
|
15
|
+
const rows = pivotModel.rows.filter(item => item.hidden !== true).map(item => item.field);
|
|
16
|
+
const values = pivotModel.values.filter(item => item.hidden !== true).map(item => item.field);
|
|
17
|
+
|
|
18
|
+
// field names in the values contain the group path. We are comparing the last part of it (the actual field name used for the value)
|
|
19
|
+
const unwrappedFieldName = column.field.split(_columnGroups.COLUMN_GROUP_ID_SEPARATOR).pop();
|
|
20
|
+
if (values.includes(unwrappedFieldName)) {
|
|
21
|
+
sections.push('dimensions');
|
|
22
|
+
}
|
|
23
|
+
if (rows.includes(column.field)) {
|
|
24
|
+
sections.push('values');
|
|
25
|
+
}
|
|
26
|
+
return sections;
|
|
27
|
+
}
|
|
28
|
+
// field that is already used for grouping cannot be added to the values
|
|
29
|
+
if (rowGroupingModel.length > 0) {
|
|
30
|
+
return rowGroupingModel.includes(column.field) ? ['values'] : [];
|
|
31
|
+
}
|
|
32
|
+
// without pivoting and row grouping the only constraint is that non-number columns cannot be added to the values
|
|
33
|
+
if (column.type !== 'number') {
|
|
34
|
+
return ['values'];
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
};
|
|
38
|
+
exports.getBlockedSections = getBlockedSections;
|
|
39
|
+
const isBlockedForSection = (column, section, rowGroupingModel, pivotModel) => getBlockedSections(column, rowGroupingModel, pivotModel).includes(section);
|
|
40
|
+
exports.isBlockedForSection = isBlockedForSection;
|
|
@@ -278,7 +278,7 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
|
|
|
278
278
|
}, [apiRef, isPivotingAvailable]);
|
|
279
279
|
const addColumnMenuButton = React.useCallback(menuItems => {
|
|
280
280
|
if (isPivotingAvailable) {
|
|
281
|
-
return [...menuItems, '
|
|
281
|
+
return [...menuItems, 'columnMenuManagePanelItem'];
|
|
282
282
|
}
|
|
283
283
|
return menuItems;
|
|
284
284
|
}, [isPivotingAvailable]);
|
|
@@ -8,9 +8,9 @@ exports.isPivotingAvailable = exports.getPivotedData = exports.getInitialColumns
|
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
10
10
|
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
11
|
+
var _columnGroups = require("../../../constants/columnGroups");
|
|
11
12
|
var _rowGrouping = require("../rowGrouping");
|
|
12
13
|
var _gridAggregationUtils = require("../aggregation/gridAggregationUtils");
|
|
13
|
-
const columnGroupIdSeparator = '>->';
|
|
14
14
|
const isPivotingAvailable = props => {
|
|
15
15
|
return !props.disablePivoting;
|
|
16
16
|
};
|
|
@@ -162,7 +162,7 @@ const getPivotedData = ({
|
|
|
162
162
|
}
|
|
163
163
|
const formattedHeaderName = apiRef.current.getRowFormattedValue(row, column) || colValue;
|
|
164
164
|
columnGroupPath.push(colValue);
|
|
165
|
-
const groupId = columnGroupPath.join(
|
|
165
|
+
const groupId = columnGroupPath.join(_columnGroups.COLUMN_GROUP_ID_SEPARATOR);
|
|
166
166
|
if (!columnGroupingModelLookup.has(groupId)) {
|
|
167
167
|
const columnGroup = {
|
|
168
168
|
groupId,
|
|
@@ -174,7 +174,7 @@ const getPivotedData = ({
|
|
|
174
174
|
if (depth === 0) {
|
|
175
175
|
columnGroupingModel.push(columnGroup);
|
|
176
176
|
} else {
|
|
177
|
-
const parentGroupId = columnGroupPath.slice(0, -1).join(
|
|
177
|
+
const parentGroupId = columnGroupPath.slice(0, -1).join(_columnGroups.COLUMN_GROUP_ID_SEPARATOR);
|
|
178
178
|
const parentGroup = columnGroupingModelLookup.get(parentGroupId);
|
|
179
179
|
if (parentGroup) {
|
|
180
180
|
parentGroup.children.push(columnGroup);
|
|
@@ -189,7 +189,7 @@ const getPivotedData = ({
|
|
|
189
189
|
if (!originalColumn) {
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
|
-
const valueKey = `${columnGroupPath.join(
|
|
192
|
+
const valueKey = `${columnGroupPath.join(_columnGroups.COLUMN_GROUP_ID_SEPARATOR)}${_columnGroups.COLUMN_GROUP_ID_SEPARATOR}${valueField}`;
|
|
193
193
|
newRow[valueKey] = apiRef.current.getRowValue(row, originalColumn);
|
|
194
194
|
});
|
|
195
195
|
}
|
|
@@ -209,7 +209,7 @@ const getPivotedData = ({
|
|
|
209
209
|
if (visibleValues.length === 0) {
|
|
210
210
|
// If there are no visible values, there are no actual columns added to the data grid, which leads to column groups not being visible.
|
|
211
211
|
// Adding an empty column to each column group ensures that the column groups are visible.
|
|
212
|
-
const emptyColumnField = `${columnGroup.groupId}${
|
|
212
|
+
const emptyColumnField = `${columnGroup.groupId}${_columnGroups.COLUMN_GROUP_ID_SEPARATOR}empty`;
|
|
213
213
|
const emptyColumn = {
|
|
214
214
|
field: emptyColumnField,
|
|
215
215
|
headerName: '',
|
|
@@ -229,11 +229,13 @@ const getPivotedData = ({
|
|
|
229
229
|
} else {
|
|
230
230
|
visibleValues.forEach(pivotValue => {
|
|
231
231
|
const valueField = pivotValue.field;
|
|
232
|
-
const mapValueKey = `${columnGroup.groupId}${
|
|
233
|
-
const overrides = typeof pivotingColDef === 'function' ? pivotingColDef(valueField, columnGroup.groupId.split(
|
|
232
|
+
const mapValueKey = `${columnGroup.groupId}${_columnGroups.COLUMN_GROUP_ID_SEPARATOR}${valueField}`;
|
|
233
|
+
const overrides = typeof pivotingColDef === 'function' ? pivotingColDef(valueField, columnGroup.groupId.split(_columnGroups.COLUMN_GROUP_ID_SEPARATOR)) : pivotingColDef;
|
|
234
234
|
const column = (0, _extends2.default)({
|
|
235
235
|
headerName: String(valueField)
|
|
236
236
|
}, getAttributesFromInitialColumn(pivotValue.field), overrides, {
|
|
237
|
+
// pivoting values are always numbers
|
|
238
|
+
type: 'number',
|
|
237
239
|
field: mapValueKey,
|
|
238
240
|
aggregable: false,
|
|
239
241
|
groupable: false,
|
|
@@ -22,7 +22,9 @@ const _excluded = ["leafField", "mainGroupingCriteria", "hideDescendantCount"],
|
|
|
22
22
|
_excluded2 = ["leafField", "mainGroupingCriteria", "hideDescendantCount"];
|
|
23
23
|
const GROUPING_COL_DEF_DEFAULT_PROPERTIES = (0, _extends2.default)({}, _xDataGridPro.GRID_STRING_COL_DEF, {
|
|
24
24
|
type: 'custom',
|
|
25
|
-
disableReorder: true
|
|
25
|
+
disableReorder: true,
|
|
26
|
+
chartable: false,
|
|
27
|
+
aggregable: false
|
|
26
28
|
});
|
|
27
29
|
const GROUPING_COL_DEF_FORCED_PROPERTIES_DEFAULT = {
|
|
28
30
|
editable: false,
|