@mui/x-data-grid-premium 5.13.1 → 5.14.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 +44 -1
- package/DataGridPremium/DataGridPremium.js +47 -0
- package/DataGridPremium/useDataGridPremiumComponent.js +6 -1
- package/DataGridPremium/useDataGridPremiumProps.js +17 -7
- package/components/GridAggregationColumnMenuItem.d.ts +9 -0
- package/components/GridAggregationColumnMenuItem.js +93 -0
- package/components/GridAggregationHeader.d.ts +4 -0
- package/components/GridAggregationHeader.js +94 -0
- package/components/GridExcelExportMenuItem.js +11 -4
- package/components/GridFooterCell.d.ts +9 -0
- package/components/GridFooterCell.js +51 -0
- package/components/GridGroupingColumnFooterCell.d.ts +4 -0
- package/components/GridGroupingColumnFooterCell.js +29 -0
- package/hooks/features/aggregation/createAggregationLookup.d.ts +10 -0
- package/hooks/features/aggregation/createAggregationLookup.js +128 -0
- package/hooks/features/aggregation/gridAggregationFunctions.d.ts +8 -0
- package/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
- package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +104 -0
- package/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
- package/hooks/features/aggregation/gridAggregationSelectors.d.ts +4 -0
- package/hooks/features/aggregation/gridAggregationSelectors.js +5 -0
- package/hooks/features/aggregation/gridAggregationUtils.d.ts +40 -0
- package/hooks/features/aggregation/gridAggregationUtils.js +177 -0
- package/hooks/features/aggregation/index.d.ts +4 -0
- package/hooks/features/aggregation/index.js +4 -0
- package/hooks/features/aggregation/useGridAggregation.d.ts +6 -0
- package/hooks/features/aggregation/useGridAggregation.js +94 -0
- package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +4 -0
- package/hooks/features/aggregation/useGridAggregationPreProcessors.js +137 -0
- package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +29 -0
- package/hooks/features/aggregation/wrapColumnWithAggregation.js +257 -0
- package/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/hooks/features/rowGrouping/useGridRowGrouping.js +20 -10
- package/index.js +1 -1
- package/legacy/DataGridPremium/DataGridPremium.js +47 -0
- package/legacy/DataGridPremium/useDataGridPremiumComponent.js +6 -1
- package/legacy/DataGridPremium/useDataGridPremiumProps.js +12 -2
- package/legacy/components/GridAggregationColumnMenuItem.js +95 -0
- package/legacy/components/GridAggregationHeader.js +95 -0
- package/legacy/components/GridExcelExportMenuItem.js +11 -4
- package/legacy/components/GridFooterCell.js +63 -0
- package/legacy/components/GridGroupingColumnFooterCell.js +27 -0
- package/legacy/hooks/features/aggregation/createAggregationLookup.js +127 -0
- package/legacy/hooks/features/aggregation/gridAggregationFunctions.js +94 -0
- package/legacy/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
- package/legacy/hooks/features/aggregation/gridAggregationSelectors.js +11 -0
- package/legacy/hooks/features/aggregation/gridAggregationUtils.js +189 -0
- package/legacy/hooks/features/aggregation/index.js +4 -0
- package/legacy/hooks/features/aggregation/useGridAggregation.js +95 -0
- package/legacy/hooks/features/aggregation/useGridAggregationPreProcessors.js +140 -0
- package/legacy/hooks/features/aggregation/wrapColumnWithAggregation.js +262 -0
- package/legacy/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/legacy/hooks/features/index.js +1 -0
- package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +24 -10
- package/legacy/index.js +1 -1
- package/legacy/typeOverloads/index.js +1 -1
- package/legacy/utils/releaseInfo.js +1 -1
- package/models/dataGridPremiumProps.d.ts +46 -1
- package/models/gridApiPremium.d.ts +2 -2
- package/models/gridStatePremium.d.ts +3 -1
- package/modern/DataGridPremium/DataGridPremium.js +47 -0
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +6 -1
- package/modern/DataGridPremium/useDataGridPremiumProps.js +8 -2
- package/modern/components/GridAggregationColumnMenuItem.js +93 -0
- package/modern/components/GridAggregationHeader.js +92 -0
- package/modern/components/GridExcelExportMenuItem.js +11 -4
- package/modern/components/GridFooterCell.js +51 -0
- package/modern/components/GridGroupingColumnFooterCell.js +29 -0
- package/modern/hooks/features/aggregation/createAggregationLookup.js +122 -0
- package/modern/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
- package/modern/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
- package/modern/hooks/features/aggregation/gridAggregationSelectors.js +5 -0
- package/modern/hooks/features/aggregation/gridAggregationUtils.js +175 -0
- package/modern/hooks/features/aggregation/index.js +4 -0
- package/modern/hooks/features/aggregation/useGridAggregation.js +92 -0
- package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +135 -0
- package/modern/hooks/features/aggregation/wrapColumnWithAggregation.js +251 -0
- package/modern/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/modern/hooks/features/index.js +1 -0
- package/modern/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +17 -11
- package/modern/index.js +1 -1
- package/modern/typeOverloads/index.js +1 -1
- package/modern/utils/releaseInfo.js +1 -1
- package/node/DataGridPremium/DataGridPremium.js +47 -0
- package/node/DataGridPremium/useDataGridPremiumComponent.js +8 -1
- package/node/DataGridPremium/useDataGridPremiumProps.js +17 -6
- package/node/components/GridAggregationColumnMenuItem.js +120 -0
- package/node/components/GridAggregationHeader.js +115 -0
- package/node/components/GridExcelExportMenuItem.js +12 -4
- package/node/components/GridFooterCell.js +73 -0
- package/node/components/GridGroupingColumnFooterCell.js +46 -0
- package/node/hooks/features/aggregation/createAggregationLookup.js +139 -0
- package/node/hooks/features/aggregation/gridAggregationFunctions.js +105 -0
- package/node/hooks/features/aggregation/gridAggregationInterfaces.js +5 -0
- package/node/hooks/features/aggregation/gridAggregationSelectors.js +17 -0
- package/node/hooks/features/aggregation/gridAggregationUtils.js +212 -0
- package/node/hooks/features/aggregation/index.js +65 -0
- package/node/hooks/features/aggregation/useGridAggregation.js +118 -0
- package/node/hooks/features/aggregation/useGridAggregationPreProcessors.js +161 -0
- package/node/hooks/features/aggregation/wrapColumnWithAggregation.js +279 -0
- package/node/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/node/hooks/features/index.js +13 -0
- package/node/hooks/features/rowGrouping/createGroupingColDef.js +14 -2
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +19 -10
- package/node/index.js +1 -1
- package/node/typeOverloads/index.js +16 -1
- package/node/utils/releaseInfo.js +1 -1
- package/package.json +4 -4
- package/typeOverloads/index.d.ts +1 -1
- package/typeOverloads/index.js +1 -1
- package/typeOverloads/modules.d.ts +32 -2
- package/utils/releaseInfo.js +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import { capitalize } from '@mui/material';
|
|
5
|
+
import { isDeepEqual } from '@mui/x-data-grid-pro/internals';
|
|
6
|
+
export var PRIVATE_GRID_AGGREGATION_ROOT_FOOTER_ROW_ID = 'auto-generated-group-footer-root'; // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
|
|
8
|
+
export var private_getAggregationFooterRowIdFromGroupId = function private_getAggregationFooterRowIdFromGroupId(groupId) {
|
|
9
|
+
if (groupId == null) {
|
|
10
|
+
return PRIVATE_GRID_AGGREGATION_ROOT_FOOTER_ROW_ID;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return "auto-generated-group-footer-".concat(groupId);
|
|
14
|
+
};
|
|
15
|
+
export var canColumnHaveAggregationFunction = function canColumnHaveAggregationFunction(_ref) {
|
|
16
|
+
var column = _ref.column,
|
|
17
|
+
aggregationFunctionName = _ref.aggregationFunctionName,
|
|
18
|
+
aggregationFunction = _ref.aggregationFunction;
|
|
19
|
+
|
|
20
|
+
if (!column || !column.private_aggregable) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!aggregationFunction) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (column.private_availableAggregationFunctions != null) {
|
|
29
|
+
return column.private_availableAggregationFunctions.includes(aggregationFunctionName);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!aggregationFunction.columnTypes) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return aggregationFunction.columnTypes.includes(column.type);
|
|
37
|
+
};
|
|
38
|
+
export var getAvailableAggregationFunctions = function getAvailableAggregationFunctions(_ref2) {
|
|
39
|
+
var aggregationFunctions = _ref2.aggregationFunctions,
|
|
40
|
+
column = _ref2.column;
|
|
41
|
+
return Object.keys(aggregationFunctions).filter(function (aggregationFunctionName) {
|
|
42
|
+
return canColumnHaveAggregationFunction({
|
|
43
|
+
column: column,
|
|
44
|
+
aggregationFunctionName: aggregationFunctionName,
|
|
45
|
+
aggregationFunction: aggregationFunctions[aggregationFunctionName]
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export var mergeStateWithAggregationModel = function mergeStateWithAggregationModel(aggregationModel) {
|
|
50
|
+
return function (state) {
|
|
51
|
+
return _extends({}, state, {
|
|
52
|
+
private_aggregation: _extends({}, state.private_aggregation, {
|
|
53
|
+
model: aggregationModel
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export var getAggregationRules = function getAggregationRules(_ref3) {
|
|
59
|
+
var columnsLookup = _ref3.columnsLookup,
|
|
60
|
+
aggregationModel = _ref3.aggregationModel,
|
|
61
|
+
aggregationFunctions = _ref3.aggregationFunctions;
|
|
62
|
+
var aggregationRules = {};
|
|
63
|
+
Object.entries(aggregationModel).forEach(function (_ref4) {
|
|
64
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
65
|
+
field = _ref5[0],
|
|
66
|
+
columnItem = _ref5[1];
|
|
67
|
+
|
|
68
|
+
if (columnsLookup[field] && canColumnHaveAggregationFunction({
|
|
69
|
+
column: columnsLookup[field],
|
|
70
|
+
aggregationFunctionName: columnItem,
|
|
71
|
+
aggregationFunction: aggregationFunctions[columnItem]
|
|
72
|
+
})) {
|
|
73
|
+
aggregationRules[field] = {
|
|
74
|
+
aggregationFunctionName: columnItem,
|
|
75
|
+
aggregationFunction: aggregationFunctions[columnItem]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return aggregationRules;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Add a footer for each group that has at least one column with an aggregated value.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
export var addFooterRows = function addFooterRows(_ref6) {
|
|
86
|
+
var groupingParams = _ref6.groupingParams,
|
|
87
|
+
aggregationRules = _ref6.aggregationRules,
|
|
88
|
+
getAggregationPosition = _ref6.getAggregationPosition;
|
|
89
|
+
|
|
90
|
+
if (Object.keys(aggregationRules).length === 0) {
|
|
91
|
+
return groupingParams;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var ids = _toConsumableArray(groupingParams.ids);
|
|
95
|
+
|
|
96
|
+
var idRowsLookup = _extends({}, groupingParams.idRowsLookup);
|
|
97
|
+
|
|
98
|
+
var tree = _extends({}, groupingParams.tree);
|
|
99
|
+
|
|
100
|
+
var addGroupFooter = function addGroupFooter(groupNode) {
|
|
101
|
+
var _groupNode$id;
|
|
102
|
+
|
|
103
|
+
var groupId = (_groupNode$id = groupNode == null ? void 0 : groupNode.id) != null ? _groupNode$id : null;
|
|
104
|
+
|
|
105
|
+
if (getAggregationPosition(groupNode) !== 'footer') {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var footerId = private_getAggregationFooterRowIdFromGroupId(groupId);
|
|
110
|
+
ids.push(footerId);
|
|
111
|
+
idRowsLookup[footerId] = {};
|
|
112
|
+
tree[footerId] = {
|
|
113
|
+
id: footerId,
|
|
114
|
+
isAutoGenerated: true,
|
|
115
|
+
parent: groupId,
|
|
116
|
+
depth: groupNode ? groupNode.depth + 1 : 0,
|
|
117
|
+
groupingKey: null,
|
|
118
|
+
groupingField: null,
|
|
119
|
+
position: 'footer'
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
if (groupId != null) {
|
|
123
|
+
tree[groupId] = _extends({}, tree[groupId], {
|
|
124
|
+
footerId: footerId
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
addGroupFooter(null); // If the tree is flat, we don't need to loop through the rows
|
|
130
|
+
|
|
131
|
+
if (groupingParams.treeDepth > 1) {
|
|
132
|
+
groupingParams.ids.forEach(function (parentId) {
|
|
133
|
+
var parentNode = tree[parentId];
|
|
134
|
+
|
|
135
|
+
if (parentNode.depth === groupingParams.treeDepth - 1) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
addGroupFooter(parentNode);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return _extends({}, groupingParams, {
|
|
144
|
+
ids: ids,
|
|
145
|
+
idRowsLookup: idRowsLookup,
|
|
146
|
+
tree: tree
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Compares two sets of aggregation rules to determine if they are equal or not.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
export var hasAggregationRulesChanged = function hasAggregationRulesChanged(previousValue, newValue) {
|
|
154
|
+
var previousFields = Object.keys(previousValue != null ? previousValue : {});
|
|
155
|
+
var newFields = Object.keys(newValue);
|
|
156
|
+
|
|
157
|
+
if (!isDeepEqual(previousFields, newFields)) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return newFields.some(function (field) {
|
|
162
|
+
var previousRule = previousValue == null ? void 0 : previousValue[field];
|
|
163
|
+
var newRule = newValue[field];
|
|
164
|
+
|
|
165
|
+
if ((previousRule == null ? void 0 : previousRule.aggregationFunction) !== (newRule == null ? void 0 : newRule.aggregationFunction)) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if ((previousRule == null ? void 0 : previousRule.aggregationFunctionName) !== (newRule == null ? void 0 : newRule.aggregationFunctionName)) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return false;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
export var getAggregationFunctionLabel = function getAggregationFunctionLabel(_ref7) {
|
|
177
|
+
var apiRef = _ref7.apiRef,
|
|
178
|
+
aggregationRule = _ref7.aggregationRule;
|
|
179
|
+
|
|
180
|
+
if (aggregationRule.aggregationFunction.label != null) {
|
|
181
|
+
return aggregationRule.aggregationFunction.label;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
return apiRef.current.getLocaleText("aggregationFunctionLabel".concat(capitalize(aggregationRule.aggregationFunctionName)));
|
|
186
|
+
} catch (e) {
|
|
187
|
+
return aggregationRule.aggregationFunctionName;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { gridColumnLookupSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid-pro';
|
|
4
|
+
import { gridAggregationModelSelector } from './gridAggregationSelectors';
|
|
5
|
+
import { getAggregationRules, mergeStateWithAggregationModel, hasAggregationRulesChanged } from './gridAggregationUtils';
|
|
6
|
+
import { createAggregationLookup } from './createAggregationLookup';
|
|
7
|
+
export var aggregationStateInitializer = function aggregationStateInitializer(state, props, apiRef) {
|
|
8
|
+
var _ref, _props$private_aggreg, _props$initialState, _props$initialState$p;
|
|
9
|
+
|
|
10
|
+
apiRef.current.unstable_caches.aggregation = {
|
|
11
|
+
rulesOnLastColumnHydration: {},
|
|
12
|
+
rulesOnLastRowHydration: {}
|
|
13
|
+
};
|
|
14
|
+
return _extends({}, state, {
|
|
15
|
+
private_aggregation: {
|
|
16
|
+
model: (_ref = (_props$private_aggreg = props.private_aggregationModel) != null ? _props$private_aggreg : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$p = _props$initialState.private_aggregation) == null ? void 0 : _props$initialState$p.model) != null ? _ref : {}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export var useGridAggregation = function useGridAggregation(apiRef, props) {
|
|
21
|
+
apiRef.current.unstable_registerControlState({
|
|
22
|
+
stateId: 'aggregation',
|
|
23
|
+
propModel: props.private_aggregationModel,
|
|
24
|
+
propOnChange: props.private_onAggregationModelChange,
|
|
25
|
+
stateSelector: gridAggregationModelSelector,
|
|
26
|
+
changeEvent: 'aggregationModelChange'
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* API METHODS
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
var setAggregationModel = React.useCallback(function (model) {
|
|
33
|
+
var currentModel = gridAggregationModelSelector(apiRef);
|
|
34
|
+
|
|
35
|
+
if (currentModel !== model) {
|
|
36
|
+
apiRef.current.setState(mergeStateWithAggregationModel(model));
|
|
37
|
+
apiRef.current.forceUpdate();
|
|
38
|
+
}
|
|
39
|
+
}, [apiRef]);
|
|
40
|
+
var applyAggregation = React.useCallback(function () {
|
|
41
|
+
var aggregationLookup = createAggregationLookup({
|
|
42
|
+
apiRef: apiRef,
|
|
43
|
+
getAggregationPosition: props.private_getAggregationPosition,
|
|
44
|
+
aggregationFunctions: props.private_aggregationFunctions,
|
|
45
|
+
aggregationRowsScope: props.private_aggregationRowsScope
|
|
46
|
+
});
|
|
47
|
+
apiRef.current.setState(function (state) {
|
|
48
|
+
return _extends({}, state, {
|
|
49
|
+
private_aggregation: _extends({}, state.private_aggregation, {
|
|
50
|
+
lookup: aggregationLookup
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}, [apiRef, props.private_getAggregationPosition, props.private_aggregationFunctions, props.private_aggregationRowsScope]);
|
|
55
|
+
var aggregationApi = {
|
|
56
|
+
private_setAggregationModel: setAggregationModel
|
|
57
|
+
};
|
|
58
|
+
useGridApiMethod(apiRef, aggregationApi, 'GridAggregationApi');
|
|
59
|
+
/**
|
|
60
|
+
* EVENTS
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
var checkAggregationRulesDiff = React.useCallback(function () {
|
|
64
|
+
var _apiRef$current$unsta = apiRef.current.unstable_caches.aggregation,
|
|
65
|
+
rulesOnLastRowHydration = _apiRef$current$unsta.rulesOnLastRowHydration,
|
|
66
|
+
rulesOnLastColumnHydration = _apiRef$current$unsta.rulesOnLastColumnHydration;
|
|
67
|
+
var aggregationRules = props.private_disableAggregation ? {} : getAggregationRules({
|
|
68
|
+
columnsLookup: gridColumnLookupSelector(apiRef),
|
|
69
|
+
aggregationModel: gridAggregationModelSelector(apiRef),
|
|
70
|
+
aggregationFunctions: props.private_aggregationFunctions
|
|
71
|
+
}); // Re-apply the row hydration to add / remove the aggregation footers
|
|
72
|
+
|
|
73
|
+
if (hasAggregationRulesChanged(rulesOnLastRowHydration, aggregationRules)) {
|
|
74
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateRows');
|
|
75
|
+
applyAggregation();
|
|
76
|
+
} // Re-apply the column hydration to wrap / unwrap the aggregated columns
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if (hasAggregationRulesChanged(rulesOnLastColumnHydration, aggregationRules)) {
|
|
80
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
|
|
81
|
+
}
|
|
82
|
+
}, [apiRef, applyAggregation, props.private_aggregationFunctions, props.private_disableAggregation]);
|
|
83
|
+
useGridApiEventHandler(apiRef, 'aggregationModelChange', checkAggregationRulesDiff);
|
|
84
|
+
useGridApiEventHandler(apiRef, 'columnsChange', checkAggregationRulesDiff);
|
|
85
|
+
useGridApiEventHandler(apiRef, 'filteredRowsSet', applyAggregation);
|
|
86
|
+
/**
|
|
87
|
+
* EFFECTS
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
React.useEffect(function () {
|
|
91
|
+
if (props.private_aggregationModel !== undefined) {
|
|
92
|
+
apiRef.current.private_setAggregationModel(props.private_aggregationModel);
|
|
93
|
+
}
|
|
94
|
+
}, [apiRef, props.private_aggregationModel]);
|
|
95
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import MuiDivider from '@mui/material/Divider';
|
|
5
|
+
import { gridColumnLookupSelector } from '@mui/x-data-grid-pro';
|
|
6
|
+
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
|
|
7
|
+
import { getAvailableAggregationFunctions, addFooterRows, getAggregationRules, mergeStateWithAggregationModel } from './gridAggregationUtils';
|
|
8
|
+
import { wrapColumnWithAggregationValue, unwrapColumnFromAggregation } from './wrapColumnWithAggregation';
|
|
9
|
+
import { GridAggregationColumnMenuItem } from '../../../components/GridAggregationColumnMenuItem';
|
|
10
|
+
import { gridAggregationModelSelector } from './gridAggregationSelectors';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
|
|
13
|
+
var Divider = function Divider() {
|
|
14
|
+
return /*#__PURE__*/_jsx(MuiDivider, {
|
|
15
|
+
onClick: function onClick(event) {
|
|
16
|
+
return event.stopPropagation();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export var useGridAggregationPreProcessors = function useGridAggregationPreProcessors(apiRef, props) {
|
|
22
|
+
var updateAggregatedColumns = React.useCallback(function (columnsState) {
|
|
23
|
+
var rulesOnLastColumnHydration = apiRef.current.unstable_caches.aggregation.rulesOnLastColumnHydration;
|
|
24
|
+
var aggregationRules = props.private_disableAggregation ? {} : getAggregationRules({
|
|
25
|
+
columnsLookup: columnsState.lookup,
|
|
26
|
+
aggregationModel: gridAggregationModelSelector(apiRef),
|
|
27
|
+
aggregationFunctions: props.private_aggregationFunctions
|
|
28
|
+
});
|
|
29
|
+
columnsState.all.forEach(function (field) {
|
|
30
|
+
var shouldHaveAggregationValue = !!aggregationRules[field];
|
|
31
|
+
var haveAggregationColumnValue = !!rulesOnLastColumnHydration[field];
|
|
32
|
+
var column = columnsState.lookup[field];
|
|
33
|
+
|
|
34
|
+
if (haveAggregationColumnValue) {
|
|
35
|
+
column = unwrapColumnFromAggregation({
|
|
36
|
+
column: column
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (shouldHaveAggregationValue) {
|
|
41
|
+
column = wrapColumnWithAggregationValue({
|
|
42
|
+
column: column,
|
|
43
|
+
aggregationRule: aggregationRules[field],
|
|
44
|
+
apiRef: apiRef
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
columnsState.lookup[field] = column;
|
|
49
|
+
});
|
|
50
|
+
apiRef.current.unstable_caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
|
|
51
|
+
return columnsState;
|
|
52
|
+
}, [apiRef, props.private_aggregationFunctions, props.private_disableAggregation]);
|
|
53
|
+
var addGroupFooterRows = React.useCallback(function (groupingParams) {
|
|
54
|
+
var newGroupingParams;
|
|
55
|
+
var rulesOnLastRowHydration;
|
|
56
|
+
|
|
57
|
+
if (props.private_disableAggregation) {
|
|
58
|
+
newGroupingParams = groupingParams;
|
|
59
|
+
rulesOnLastRowHydration = {};
|
|
60
|
+
} else {
|
|
61
|
+
var aggregationRules = getAggregationRules({
|
|
62
|
+
columnsLookup: gridColumnLookupSelector(apiRef),
|
|
63
|
+
aggregationModel: gridAggregationModelSelector(apiRef),
|
|
64
|
+
aggregationFunctions: props.private_aggregationFunctions
|
|
65
|
+
});
|
|
66
|
+
rulesOnLastRowHydration = aggregationRules; // If no column have an aggregation rule
|
|
67
|
+
// Then don't create the footer rows
|
|
68
|
+
|
|
69
|
+
if (Object.values(aggregationRules).length === 0) {
|
|
70
|
+
newGroupingParams = groupingParams;
|
|
71
|
+
} else {
|
|
72
|
+
newGroupingParams = addFooterRows({
|
|
73
|
+
groupingParams: groupingParams,
|
|
74
|
+
aggregationRules: aggregationRules,
|
|
75
|
+
getAggregationPosition: props.private_getAggregationPosition
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
apiRef.current.unstable_caches.aggregation.rulesOnLastRowHydration = rulesOnLastRowHydration;
|
|
81
|
+
return newGroupingParams;
|
|
82
|
+
}, [apiRef, props.private_disableAggregation, props.private_getAggregationPosition, props.private_aggregationFunctions]);
|
|
83
|
+
var addColumnMenuButtons = React.useCallback(function (initialValue, column) {
|
|
84
|
+
if (props.private_disableAggregation) {
|
|
85
|
+
return initialValue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var availableAggregationFunctions = getAvailableAggregationFunctions({
|
|
89
|
+
aggregationFunctions: props.private_aggregationFunctions,
|
|
90
|
+
column: column
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (availableAggregationFunctions.length === 0) {
|
|
94
|
+
return initialValue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return [].concat(_toConsumableArray(initialValue), [/*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsx(GridAggregationColumnMenuItem, {
|
|
98
|
+
column: column,
|
|
99
|
+
label: apiRef.current.getLocaleText('aggregationMenuItemHeader'),
|
|
100
|
+
availableAggregationFunctions: availableAggregationFunctions
|
|
101
|
+
})]);
|
|
102
|
+
}, [apiRef, props.private_aggregationFunctions, props.private_disableAggregation]);
|
|
103
|
+
var stateExportPreProcessing = React.useCallback(function (prevState) {
|
|
104
|
+
if (props.private_disableAggregation) {
|
|
105
|
+
return prevState;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var aggregationModelToExport = gridAggregationModelSelector(apiRef);
|
|
109
|
+
|
|
110
|
+
if (Object.values(aggregationModelToExport).length === 0) {
|
|
111
|
+
return prevState;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return _extends({}, prevState, {
|
|
115
|
+
private_aggregation: {
|
|
116
|
+
model: aggregationModelToExport
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}, [apiRef, props.private_disableAggregation]);
|
|
120
|
+
var stateRestorePreProcessing = React.useCallback(function (params, context) {
|
|
121
|
+
var _context$stateToResto;
|
|
122
|
+
|
|
123
|
+
if (props.private_disableAggregation) {
|
|
124
|
+
return params;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
var aggregationModel = (_context$stateToResto = context.stateToRestore.private_aggregation) == null ? void 0 : _context$stateToResto.model;
|
|
128
|
+
|
|
129
|
+
if (aggregationModel != null) {
|
|
130
|
+
apiRef.current.setState(mergeStateWithAggregationModel(aggregationModel));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return params;
|
|
134
|
+
}, [apiRef, props.private_disableAggregation]);
|
|
135
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateAggregatedColumns);
|
|
136
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateRows', addGroupFooterRows);
|
|
137
|
+
useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
138
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
139
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
140
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { gridAggregationLookupSelector } from './gridAggregationSelectors';
|
|
5
|
+
import { GridFooterCell } from '../../../components/GridFooterCell';
|
|
6
|
+
import { GridAggregationHeader } from '../../../components/GridAggregationHeader';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
var AGGREGATION_WRAPPABLE_PROPERTIES = ['valueGetter', 'valueFormatter', 'renderCell', 'renderHeader', 'filterOperators'];
|
|
9
|
+
|
|
10
|
+
var getAggregationValueWrappedValueGetter = function getAggregationValueWrappedValueGetter(_ref) {
|
|
11
|
+
var valueGetter = _ref.value,
|
|
12
|
+
getCellAggregationResult = _ref.getCellAggregationResult;
|
|
13
|
+
|
|
14
|
+
var wrappedValueGetter = function wrappedValueGetter(params) {
|
|
15
|
+
var cellAggregationResult = getCellAggregationResult(params.id, params.field);
|
|
16
|
+
|
|
17
|
+
if (cellAggregationResult != null) {
|
|
18
|
+
var _cellAggregationResul;
|
|
19
|
+
|
|
20
|
+
return (_cellAggregationResul = cellAggregationResult == null ? void 0 : cellAggregationResult.value) != null ? _cellAggregationResul : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (valueGetter) {
|
|
24
|
+
return valueGetter(params);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return params.row[params.field];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return wrappedValueGetter;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var getAggregationValueWrappedValueFormatter = function getAggregationValueWrappedValueFormatter(_ref2) {
|
|
34
|
+
var valueFormatter = _ref2.value,
|
|
35
|
+
aggregationRule = _ref2.aggregationRule,
|
|
36
|
+
getCellAggregationResult = _ref2.getCellAggregationResult;
|
|
37
|
+
|
|
38
|
+
// If neither the inline aggregation function nor the footer aggregation function have a custom value formatter,
|
|
39
|
+
// Then we don't wrap the column value formatter
|
|
40
|
+
if (!aggregationRule.aggregationFunction.valueFormatter) {
|
|
41
|
+
return valueFormatter;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var wrappedValueFormatter = function wrappedValueFormatter(params) {
|
|
45
|
+
if (params.id != null) {
|
|
46
|
+
var cellAggregationResult = getCellAggregationResult(params.id, params.field);
|
|
47
|
+
|
|
48
|
+
if (cellAggregationResult != null) {
|
|
49
|
+
return aggregationRule.aggregationFunction.valueFormatter(params);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (valueFormatter) {
|
|
54
|
+
return valueFormatter(params);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return params.value;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return wrappedValueFormatter;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var getAggregationValueWrappedRenderCell = function getAggregationValueWrappedRenderCell(_ref3) {
|
|
64
|
+
var renderCell = _ref3.value,
|
|
65
|
+
aggregationRule = _ref3.aggregationRule,
|
|
66
|
+
getCellAggregationResult = _ref3.getCellAggregationResult;
|
|
67
|
+
|
|
68
|
+
var wrappedRenderCell = function wrappedRenderCell(params) {
|
|
69
|
+
var cellAggregationResult = getCellAggregationResult(params.id, params.field);
|
|
70
|
+
|
|
71
|
+
if (cellAggregationResult != null) {
|
|
72
|
+
var _aggregationFunction$;
|
|
73
|
+
|
|
74
|
+
if (!renderCell) {
|
|
75
|
+
if (cellAggregationResult.position === 'footer') {
|
|
76
|
+
return /*#__PURE__*/_jsx(GridFooterCell, _extends({}, params));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return params.formattedValue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var aggregationMeta = {
|
|
83
|
+
hasCellUnit: (_aggregationFunction$ = aggregationRule.aggregationFunction.hasCellUnit) != null ? _aggregationFunction$ : true,
|
|
84
|
+
aggregationFunctionName: aggregationRule.aggregationFunctionName
|
|
85
|
+
};
|
|
86
|
+
return renderCell(_extends({}, params, {
|
|
87
|
+
aggregation: aggregationMeta
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!renderCell) {
|
|
92
|
+
return params.formattedValue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return renderCell(params);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return wrappedRenderCell;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Skips the filtering for aggregated rows
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
var getWrappedFilterOperators = function getWrappedFilterOperators(_ref4) {
|
|
106
|
+
var filterOperators = _ref4.value,
|
|
107
|
+
getCellAggregationResult = _ref4.getCellAggregationResult;
|
|
108
|
+
return filterOperators.map(function (operator) {
|
|
109
|
+
return _extends({}, operator, {
|
|
110
|
+
getApplyFilterFn: function getApplyFilterFn(filterItem, column) {
|
|
111
|
+
var originalFn = operator.getApplyFilterFn(filterItem, column);
|
|
112
|
+
|
|
113
|
+
if (!originalFn) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return function (params) {
|
|
118
|
+
if (getCellAggregationResult(params.id, params.field) != null) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return originalFn(params);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Add the aggregation method around the header name
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
var getWrappedRenderHeader = function getWrappedRenderHeader(_ref5) {
|
|
134
|
+
var renderHeader = _ref5.value,
|
|
135
|
+
aggregationRule = _ref5.aggregationRule;
|
|
136
|
+
|
|
137
|
+
var wrappedRenderCell = function wrappedRenderCell(params) {
|
|
138
|
+
var aggregationMeta = {
|
|
139
|
+
aggregationRule: aggregationRule
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
if (!renderHeader) {
|
|
143
|
+
return /*#__PURE__*/_jsx(GridAggregationHeader, _extends({}, params, {
|
|
144
|
+
aggregation: aggregationMeta
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return renderHeader(_extends({}, params, {
|
|
149
|
+
aggregation: aggregationMeta
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return wrappedRenderCell;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Add a wrapper around each wrappable property of the column to customize the behavior of the aggregation cells.
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
export var wrapColumnWithAggregationValue = function wrapColumnWithAggregationValue(_ref6) {
|
|
161
|
+
var column = _ref6.column,
|
|
162
|
+
apiRef = _ref6.apiRef,
|
|
163
|
+
aggregationRule = _ref6.aggregationRule;
|
|
164
|
+
|
|
165
|
+
var getCellAggregationResult = function getCellAggregationResult(id, field) {
|
|
166
|
+
var _parent, _gridAggregationLooku;
|
|
167
|
+
|
|
168
|
+
var cellAggregationPosition = null;
|
|
169
|
+
|
|
170
|
+
if (id.toString().startsWith('auto-generated-row-')) {
|
|
171
|
+
cellAggregationPosition = 'inline';
|
|
172
|
+
} else if (id.toString().startsWith('auto-generated-group-footer-')) {
|
|
173
|
+
cellAggregationPosition = 'footer';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (cellAggregationPosition == null) {
|
|
177
|
+
return null;
|
|
178
|
+
} // TODO: Add custom root id
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
var groupId = cellAggregationPosition === 'inline' ? id : (_parent = apiRef.current.getRowNode(id).parent) != null ? _parent : '';
|
|
182
|
+
var aggregationResult = (_gridAggregationLooku = gridAggregationLookupSelector(apiRef)[groupId]) == null ? void 0 : _gridAggregationLooku[field];
|
|
183
|
+
|
|
184
|
+
if (!aggregationResult || aggregationResult.position !== cellAggregationPosition) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return aggregationResult;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
var aggregationWrappedProperties = {};
|
|
192
|
+
|
|
193
|
+
var wrappedColumn = _extends({}, column, {
|
|
194
|
+
aggregationWrappedProperties: aggregationWrappedProperties
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
var wrapColumnProperty = function wrapColumnProperty(property, wrapper) {
|
|
198
|
+
var originalValue = column[property];
|
|
199
|
+
var wrappedProperty = wrapper({
|
|
200
|
+
apiRef: apiRef,
|
|
201
|
+
value: originalValue,
|
|
202
|
+
colDef: column,
|
|
203
|
+
aggregationRule: aggregationRule,
|
|
204
|
+
getCellAggregationResult: getCellAggregationResult
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (wrappedProperty !== originalValue) {
|
|
208
|
+
aggregationWrappedProperties[property] = {
|
|
209
|
+
original: originalValue,
|
|
210
|
+
wrapped: wrappedProperty
|
|
211
|
+
};
|
|
212
|
+
wrappedColumn[property] = wrappedProperty;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
wrapColumnProperty('valueGetter', getAggregationValueWrappedValueGetter);
|
|
217
|
+
wrapColumnProperty('valueFormatter', getAggregationValueWrappedValueFormatter);
|
|
218
|
+
wrapColumnProperty('renderCell', getAggregationValueWrappedRenderCell);
|
|
219
|
+
wrapColumnProperty('renderHeader', getWrappedRenderHeader);
|
|
220
|
+
wrapColumnProperty('filterOperators', getWrappedFilterOperators);
|
|
221
|
+
|
|
222
|
+
if (Object.keys(aggregationWrappedProperties).length === 0) {
|
|
223
|
+
return column;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return wrappedColumn;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Remove the aggregation wrappers around the wrappable properties of the column.
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
export var unwrapColumnFromAggregation = function unwrapColumnFromAggregation(_ref7) {
|
|
233
|
+
var column = _ref7.column;
|
|
234
|
+
|
|
235
|
+
if (!column.aggregationWrappedProperties) {
|
|
236
|
+
return column;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
var originalProperties = Object.entries(column.aggregationWrappedProperties);
|
|
240
|
+
|
|
241
|
+
if (originalProperties.length === 0) {
|
|
242
|
+
return column;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
var unwrappedColumn = _extends({}, column);
|
|
246
|
+
|
|
247
|
+
originalProperties.forEach(function (_ref8) {
|
|
248
|
+
var _ref9 = _slicedToArray(_ref8, 2),
|
|
249
|
+
propertyName = _ref9[0],
|
|
250
|
+
_ref9$ = _ref9[1],
|
|
251
|
+
original = _ref9$.original,
|
|
252
|
+
wrapped = _ref9$.wrapped;
|
|
253
|
+
|
|
254
|
+
// The value changed since we wrapped it
|
|
255
|
+
if (wrapped !== column[propertyName]) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
unwrappedColumn[propertyName] = original;
|
|
260
|
+
});
|
|
261
|
+
return unwrappedColumn;
|
|
262
|
+
};
|