@mui/x-data-grid-premium 5.13.0 → 5.15.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +156 -6
  2. package/DataGridPremium/DataGridPremium.js +56 -0
  3. package/DataGridPremium/useDataGridPremiumComponent.js +10 -2
  4. package/DataGridPremium/useDataGridPremiumProps.js +17 -7
  5. package/components/GridAggregationColumnMenuItem.d.ts +9 -0
  6. package/components/GridAggregationColumnMenuItem.js +93 -0
  7. package/components/GridAggregationHeader.d.ts +4 -0
  8. package/components/GridAggregationHeader.js +94 -0
  9. package/components/GridExcelExportMenuItem.js +11 -4
  10. package/components/GridFooterCell.d.ts +9 -0
  11. package/components/GridFooterCell.js +51 -0
  12. package/components/GridGroupingColumnFooterCell.d.ts +4 -0
  13. package/components/GridGroupingColumnFooterCell.js +29 -0
  14. package/hooks/features/aggregation/createAggregationLookup.d.ts +10 -0
  15. package/hooks/features/aggregation/createAggregationLookup.js +128 -0
  16. package/hooks/features/aggregation/gridAggregationFunctions.d.ts +8 -0
  17. package/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
  18. package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +103 -0
  19. package/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
  20. package/hooks/features/aggregation/gridAggregationSelectors.d.ts +4 -0
  21. package/hooks/features/aggregation/gridAggregationSelectors.js +4 -0
  22. package/hooks/features/aggregation/gridAggregationUtils.d.ts +41 -0
  23. package/hooks/features/aggregation/gridAggregationUtils.js +188 -0
  24. package/hooks/features/aggregation/index.d.ts +4 -0
  25. package/hooks/features/aggregation/index.js +4 -0
  26. package/hooks/features/aggregation/useGridAggregation.d.ts +6 -0
  27. package/hooks/features/aggregation/useGridAggregation.js +94 -0
  28. package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +4 -0
  29. package/hooks/features/aggregation/useGridAggregationPreProcessors.js +138 -0
  30. package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +29 -0
  31. package/hooks/features/aggregation/wrapColumnWithAggregation.js +257 -0
  32. package/hooks/features/export/serializer/excelSerializer.js +2 -1
  33. package/hooks/features/index.d.ts +1 -0
  34. package/hooks/features/index.js +1 -0
  35. package/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
  36. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  37. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  38. package/hooks/features/rowGrouping/useGridRowGrouping.js +20 -10
  39. package/index.js +1 -1
  40. package/legacy/DataGridPremium/DataGridPremium.js +56 -0
  41. package/legacy/DataGridPremium/useDataGridPremiumComponent.js +10 -2
  42. package/legacy/DataGridPremium/useDataGridPremiumProps.js +12 -2
  43. package/legacy/components/GridAggregationColumnMenuItem.js +95 -0
  44. package/legacy/components/GridAggregationHeader.js +95 -0
  45. package/legacy/components/GridExcelExportMenuItem.js +11 -4
  46. package/legacy/components/GridFooterCell.js +63 -0
  47. package/legacy/components/GridGroupingColumnFooterCell.js +27 -0
  48. package/legacy/hooks/features/aggregation/createAggregationLookup.js +127 -0
  49. package/legacy/hooks/features/aggregation/gridAggregationFunctions.js +94 -0
  50. package/legacy/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
  51. package/legacy/hooks/features/aggregation/gridAggregationSelectors.js +10 -0
  52. package/legacy/hooks/features/aggregation/gridAggregationUtils.js +200 -0
  53. package/legacy/hooks/features/aggregation/index.js +4 -0
  54. package/legacy/hooks/features/aggregation/useGridAggregation.js +95 -0
  55. package/legacy/hooks/features/aggregation/useGridAggregationPreProcessors.js +141 -0
  56. package/legacy/hooks/features/aggregation/wrapColumnWithAggregation.js +262 -0
  57. package/legacy/hooks/features/export/serializer/excelSerializer.js +2 -1
  58. package/legacy/hooks/features/index.js +1 -0
  59. package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
  60. package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  61. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +24 -10
  62. package/legacy/index.js +1 -1
  63. package/legacy/typeOverloads/index.js +1 -1
  64. package/legacy/utils/releaseInfo.js +1 -1
  65. package/models/dataGridPremiumProps.d.ts +40 -1
  66. package/models/gridApiPremium.d.ts +3 -3
  67. package/models/gridStatePremium.d.ts +3 -1
  68. package/modern/DataGridPremium/DataGridPremium.js +56 -0
  69. package/modern/DataGridPremium/useDataGridPremiumComponent.js +10 -2
  70. package/modern/DataGridPremium/useDataGridPremiumProps.js +8 -2
  71. package/modern/components/GridAggregationColumnMenuItem.js +93 -0
  72. package/modern/components/GridAggregationHeader.js +92 -0
  73. package/modern/components/GridExcelExportMenuItem.js +11 -4
  74. package/modern/components/GridFooterCell.js +51 -0
  75. package/modern/components/GridGroupingColumnFooterCell.js +29 -0
  76. package/modern/hooks/features/aggregation/createAggregationLookup.js +122 -0
  77. package/modern/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
  78. package/modern/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
  79. package/modern/hooks/features/aggregation/gridAggregationSelectors.js +4 -0
  80. package/modern/hooks/features/aggregation/gridAggregationUtils.js +186 -0
  81. package/modern/hooks/features/aggregation/index.js +4 -0
  82. package/modern/hooks/features/aggregation/useGridAggregation.js +92 -0
  83. package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +136 -0
  84. package/modern/hooks/features/aggregation/wrapColumnWithAggregation.js +251 -0
  85. package/modern/hooks/features/export/serializer/excelSerializer.js +2 -1
  86. package/modern/hooks/features/index.js +1 -0
  87. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
  88. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  89. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +17 -11
  90. package/modern/index.js +1 -1
  91. package/modern/typeOverloads/index.js +1 -1
  92. package/modern/utils/releaseInfo.js +1 -1
  93. package/node/DataGridPremium/DataGridPremium.js +56 -0
  94. package/node/DataGridPremium/useDataGridPremiumComponent.js +11 -1
  95. package/node/DataGridPremium/useDataGridPremiumProps.js +17 -6
  96. package/node/components/GridAggregationColumnMenuItem.js +120 -0
  97. package/node/components/GridAggregationHeader.js +115 -0
  98. package/node/components/GridExcelExportMenuItem.js +12 -4
  99. package/node/components/GridFooterCell.js +73 -0
  100. package/node/components/GridGroupingColumnFooterCell.js +46 -0
  101. package/node/hooks/features/aggregation/createAggregationLookup.js +139 -0
  102. package/node/hooks/features/aggregation/gridAggregationFunctions.js +105 -0
  103. package/node/hooks/features/aggregation/gridAggregationInterfaces.js +5 -0
  104. package/node/hooks/features/aggregation/gridAggregationSelectors.js +16 -0
  105. package/node/hooks/features/aggregation/gridAggregationUtils.js +223 -0
  106. package/node/hooks/features/aggregation/index.js +65 -0
  107. package/node/hooks/features/aggregation/useGridAggregation.js +118 -0
  108. package/node/hooks/features/aggregation/useGridAggregationPreProcessors.js +162 -0
  109. package/node/hooks/features/aggregation/wrapColumnWithAggregation.js +279 -0
  110. package/node/hooks/features/export/serializer/excelSerializer.js +2 -1
  111. package/node/hooks/features/index.js +13 -0
  112. package/node/hooks/features/rowGrouping/createGroupingColDef.js +14 -2
  113. package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  114. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +19 -10
  115. package/node/index.js +1 -1
  116. package/node/typeOverloads/index.js +16 -1
  117. package/node/utils/releaseInfo.js +1 -1
  118. package/package.json +5 -5
  119. package/typeOverloads/index.d.ts +1 -1
  120. package/typeOverloads/index.js +1 -1
  121. package/typeOverloads/modules.d.ts +32 -2
  122. package/utils/releaseInfo.js +1 -1
@@ -0,0 +1,127 @@
1
+ import { gridColumnLookupSelector, gridFilteredRowsLookupSelector, gridRowIdsSelector, gridRowTreeSelector } from '@mui/x-data-grid-pro';
2
+ import { getAggregationRules } from './gridAggregationUtils';
3
+ import { gridAggregationModelSelector } from './gridAggregationSelectors';
4
+
5
+ var getAggregationCellValue = function getAggregationCellValue(_ref) {
6
+ var apiRef = _ref.apiRef,
7
+ groupId = _ref.groupId,
8
+ field = _ref.field,
9
+ aggregationFunction = _ref.aggregationFunction,
10
+ aggregationRowsScope = _ref.aggregationRowsScope;
11
+ var rowTree = gridRowTreeSelector(apiRef);
12
+ var filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
13
+ var rowIds; // TODO: Add custom root id
14
+
15
+ if (groupId === '') {
16
+ rowIds = gridRowIdsSelector(apiRef).filter(function (rowId) {
17
+ return !rowTree[rowId].isAutoGenerated;
18
+ });
19
+ } else {
20
+ rowIds = apiRef.current.getRowGroupChildren({
21
+ groupId: groupId
22
+ });
23
+ }
24
+
25
+ var values = [];
26
+ rowIds.forEach(function (rowId) {
27
+ if (aggregationRowsScope === 'filtered' && filteredRowsLookup[rowId] === false) {
28
+ return;
29
+ }
30
+
31
+ values.push(apiRef.current.getCellValue(rowId, field));
32
+ });
33
+ return aggregationFunction.apply({
34
+ values: values
35
+ });
36
+ };
37
+
38
+ var getGroupAggregatedValue = function getGroupAggregatedValue(_ref2) {
39
+ var groupId = _ref2.groupId,
40
+ apiRef = _ref2.apiRef,
41
+ aggregationRowsScope = _ref2.aggregationRowsScope,
42
+ aggregatedFields = _ref2.aggregatedFields,
43
+ aggregationRules = _ref2.aggregationRules,
44
+ position = _ref2.position;
45
+ var groupAggregationLookup = {};
46
+
47
+ for (var j = 0; j < aggregatedFields.length; j += 1) {
48
+ var aggregatedField = aggregatedFields[j];
49
+ var columnAggregationRules = aggregationRules[aggregatedField];
50
+ groupAggregationLookup[aggregatedField] = {
51
+ position: position,
52
+ value: getAggregationCellValue({
53
+ apiRef: apiRef,
54
+ groupId: groupId,
55
+ field: aggregatedField,
56
+ aggregationFunction: columnAggregationRules.aggregationFunction,
57
+ aggregationRowsScope: aggregationRowsScope
58
+ })
59
+ };
60
+ }
61
+
62
+ return groupAggregationLookup;
63
+ };
64
+
65
+ export var createAggregationLookup = function createAggregationLookup(_ref3) {
66
+ var apiRef = _ref3.apiRef,
67
+ aggregationFunctions = _ref3.aggregationFunctions,
68
+ aggregationRowsScope = _ref3.aggregationRowsScope,
69
+ getAggregationPosition = _ref3.getAggregationPosition;
70
+ var aggregationRules = getAggregationRules({
71
+ columnsLookup: gridColumnLookupSelector(apiRef),
72
+ aggregationModel: gridAggregationModelSelector(apiRef),
73
+ aggregationFunctions: aggregationFunctions
74
+ });
75
+ var aggregatedFields = Object.keys(aggregationRules);
76
+
77
+ if (aggregatedFields.length === 0) {
78
+ return {};
79
+ }
80
+
81
+ var aggregationLookup = {};
82
+ var rowIds = gridRowIdsSelector(apiRef);
83
+ var rowTree = gridRowTreeSelector(apiRef);
84
+
85
+ for (var i = 0; i < rowIds.length; i += 1) {
86
+ var _node$children;
87
+
88
+ var rowId = rowIds[i];
89
+ var node = rowTree[rowId];
90
+ var hasChildren = (_node$children = node.children) == null ? void 0 : _node$children.some(function (childId) {
91
+ var _rowTree$childId$posi;
92
+
93
+ return ((_rowTree$childId$posi = rowTree[childId].position) != null ? _rowTree$childId$posi : 'body') === 'body';
94
+ });
95
+
96
+ if (hasChildren) {
97
+ var _position = getAggregationPosition(node);
98
+
99
+ if (_position != null) {
100
+ aggregationLookup[rowId] = getGroupAggregatedValue({
101
+ groupId: rowId,
102
+ apiRef: apiRef,
103
+ aggregatedFields: aggregatedFields,
104
+ aggregationRowsScope: aggregationRowsScope,
105
+ aggregationRules: aggregationRules,
106
+ position: _position
107
+ });
108
+ }
109
+ }
110
+ } // TODO: Add custom root id
111
+
112
+
113
+ var position = getAggregationPosition(null);
114
+
115
+ if (position != null) {
116
+ aggregationLookup[''] = getGroupAggregatedValue({
117
+ groupId: '',
118
+ apiRef: apiRef,
119
+ aggregatedFields: aggregatedFields,
120
+ aggregationRowsScope: aggregationRowsScope,
121
+ aggregationRules: aggregationRules,
122
+ position: position
123
+ });
124
+ }
125
+
126
+ return aggregationLookup;
127
+ };
@@ -0,0 +1,94 @@
1
+ import { isNumber } from '@mui/x-data-grid-pro/internals';
2
+ var sumAgg = {
3
+ apply: function apply(_ref) {
4
+ var values = _ref.values;
5
+ var sum = 0;
6
+
7
+ for (var i = 0; i < values.length; i += 1) {
8
+ var value = values[i];
9
+
10
+ if (value != null) {
11
+ sum += value;
12
+ }
13
+ }
14
+
15
+ return sum;
16
+ },
17
+ columnTypes: ['number']
18
+ };
19
+ var avgAgg = {
20
+ apply: function apply(params) {
21
+ if (params.values.length === 0) {
22
+ return null;
23
+ }
24
+
25
+ var sum = sumAgg.apply(params);
26
+ return sum / params.values.length;
27
+ },
28
+ columnTypes: ['number']
29
+ };
30
+ var minAgg = {
31
+ apply: function apply(_ref2) {
32
+ var values = _ref2.values;
33
+
34
+ if (values.length === 0) {
35
+ return null;
36
+ }
37
+
38
+ var min = +Infinity;
39
+
40
+ for (var i = 0; i < values.length; i += 1) {
41
+ var value = values[i];
42
+
43
+ if (value != null && value < min) {
44
+ min = value;
45
+ }
46
+ }
47
+
48
+ return min;
49
+ },
50
+ columnTypes: ['number', 'date', 'dateTime']
51
+ };
52
+ var maxAgg = {
53
+ apply: function apply(_ref3) {
54
+ var values = _ref3.values;
55
+
56
+ if (values.length === 0) {
57
+ return null;
58
+ }
59
+
60
+ var max = -Infinity;
61
+
62
+ for (var i = 0; i < values.length; i += 1) {
63
+ var value = values[i];
64
+
65
+ if (value != null && value > max) {
66
+ max = value;
67
+ }
68
+ }
69
+
70
+ return max;
71
+ },
72
+ columnTypes: ['number', 'date', 'dateTime']
73
+ };
74
+ var sizeAgg = {
75
+ apply: function apply(_ref4) {
76
+ var values = _ref4.values;
77
+ return values.length;
78
+ },
79
+ valueFormatter: function valueFormatter(params) {
80
+ if (params.value == null || !isNumber(params.value)) {
81
+ return params.value;
82
+ }
83
+
84
+ return params.value.toLocaleString();
85
+ },
86
+ hasCellUnit: false
87
+ };
88
+ export var GRID_AGGREGATION_FUNCTIONS = {
89
+ sum: sumAgg,
90
+ avg: avgAgg,
91
+ min: minAgg,
92
+ max: maxAgg,
93
+ size: sizeAgg
94
+ };
@@ -0,0 +1,10 @@
1
+ import { createSelector } from '@mui/x-data-grid-pro/internals';
2
+ export var gridAggregationStateSelector = function gridAggregationStateSelector(state) {
3
+ return state.aggregation;
4
+ };
5
+ export var gridAggregationModelSelector = createSelector(gridAggregationStateSelector, function (aggregationState) {
6
+ return aggregationState.model;
7
+ });
8
+ export var gridAggregationLookupSelector = createSelector(gridAggregationStateSelector, function (aggregationState) {
9
+ return aggregationState.lookup;
10
+ });
@@ -0,0 +1,200 @@
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 { addPinnedRow, isDeepEqual } from '@mui/x-data-grid-pro/internals';
6
+ export var GRID_AGGREGATION_ROOT_FOOTER_ROW_ID = 'auto-generated-group-footer-root';
7
+ export var getAggregationFooterRowIdFromGroupId = function getAggregationFooterRowIdFromGroupId(groupId) {
8
+ if (groupId == null) {
9
+ return GRID_AGGREGATION_ROOT_FOOTER_ROW_ID;
10
+ }
11
+
12
+ return "auto-generated-group-footer-".concat(groupId);
13
+ };
14
+ export var canColumnHaveAggregationFunction = function canColumnHaveAggregationFunction(_ref) {
15
+ var column = _ref.column,
16
+ aggregationFunctionName = _ref.aggregationFunctionName,
17
+ aggregationFunction = _ref.aggregationFunction;
18
+
19
+ if (!column || !column.aggregable) {
20
+ return false;
21
+ }
22
+
23
+ if (!aggregationFunction) {
24
+ return false;
25
+ }
26
+
27
+ if (column.availableAggregationFunctions != null) {
28
+ return column.availableAggregationFunctions.includes(aggregationFunctionName);
29
+ }
30
+
31
+ if (!aggregationFunction.columnTypes) {
32
+ return true;
33
+ }
34
+
35
+ return aggregationFunction.columnTypes.includes(column.type);
36
+ };
37
+ export var getAvailableAggregationFunctions = function getAvailableAggregationFunctions(_ref2) {
38
+ var aggregationFunctions = _ref2.aggregationFunctions,
39
+ column = _ref2.column;
40
+ return Object.keys(aggregationFunctions).filter(function (aggregationFunctionName) {
41
+ return canColumnHaveAggregationFunction({
42
+ column: column,
43
+ aggregationFunctionName: aggregationFunctionName,
44
+ aggregationFunction: aggregationFunctions[aggregationFunctionName]
45
+ });
46
+ });
47
+ };
48
+ export var mergeStateWithAggregationModel = function mergeStateWithAggregationModel(aggregationModel) {
49
+ return function (state) {
50
+ return _extends({}, state, {
51
+ aggregation: _extends({}, state.aggregation, {
52
+ model: aggregationModel
53
+ })
54
+ });
55
+ };
56
+ };
57
+ export var getAggregationRules = function getAggregationRules(_ref3) {
58
+ var columnsLookup = _ref3.columnsLookup,
59
+ aggregationModel = _ref3.aggregationModel,
60
+ aggregationFunctions = _ref3.aggregationFunctions;
61
+ var aggregationRules = {};
62
+ Object.entries(aggregationModel).forEach(function (_ref4) {
63
+ var _ref5 = _slicedToArray(_ref4, 2),
64
+ field = _ref5[0],
65
+ columnItem = _ref5[1];
66
+
67
+ if (columnsLookup[field] && canColumnHaveAggregationFunction({
68
+ column: columnsLookup[field],
69
+ aggregationFunctionName: columnItem,
70
+ aggregationFunction: aggregationFunctions[columnItem]
71
+ })) {
72
+ aggregationRules[field] = {
73
+ aggregationFunctionName: columnItem,
74
+ aggregationFunction: aggregationFunctions[columnItem]
75
+ };
76
+ }
77
+ });
78
+ return aggregationRules;
79
+ };
80
+ /**
81
+ * Add a footer for each group that has at least one column with an aggregated value.
82
+ */
83
+
84
+ export var addFooterRows = function addFooterRows(_ref6) {
85
+ var groupingParams = _ref6.groupingParams,
86
+ aggregationRules = _ref6.aggregationRules,
87
+ getAggregationPosition = _ref6.getAggregationPosition,
88
+ apiRef = _ref6.apiRef;
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 = 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
+ }; // If the tree is flat, we don't need to loop through the rows
128
+
129
+
130
+ if (groupingParams.treeDepth > 1) {
131
+ groupingParams.ids.forEach(function (parentId) {
132
+ var parentNode = tree[parentId];
133
+
134
+ if (parentNode.depth === groupingParams.treeDepth - 1) {
135
+ return;
136
+ }
137
+
138
+ addGroupFooter(parentNode);
139
+ });
140
+ }
141
+
142
+ var newGroupingParams = _extends({}, groupingParams, {
143
+ tree: tree,
144
+ idRowsLookup: idRowsLookup,
145
+ ids: ids
146
+ });
147
+
148
+ if (getAggregationPosition(null) === 'footer') {
149
+ newGroupingParams = addPinnedRow({
150
+ groupingParams: newGroupingParams,
151
+ rowModel: {},
152
+ rowId: getAggregationFooterRowIdFromGroupId(null),
153
+ position: 'bottom',
154
+ apiRef: apiRef
155
+ });
156
+ }
157
+
158
+ return _extends({}, groupingParams, newGroupingParams);
159
+ };
160
+ /**
161
+ * Compares two sets of aggregation rules to determine if they are equal or not.
162
+ */
163
+
164
+ export var hasAggregationRulesChanged = function hasAggregationRulesChanged(previousValue, newValue) {
165
+ var previousFields = Object.keys(previousValue != null ? previousValue : {});
166
+ var newFields = Object.keys(newValue);
167
+
168
+ if (!isDeepEqual(previousFields, newFields)) {
169
+ return true;
170
+ }
171
+
172
+ return newFields.some(function (field) {
173
+ var previousRule = previousValue == null ? void 0 : previousValue[field];
174
+ var newRule = newValue[field];
175
+
176
+ if ((previousRule == null ? void 0 : previousRule.aggregationFunction) !== (newRule == null ? void 0 : newRule.aggregationFunction)) {
177
+ return true;
178
+ }
179
+
180
+ if ((previousRule == null ? void 0 : previousRule.aggregationFunctionName) !== (newRule == null ? void 0 : newRule.aggregationFunctionName)) {
181
+ return true;
182
+ }
183
+
184
+ return false;
185
+ });
186
+ };
187
+ export var getAggregationFunctionLabel = function getAggregationFunctionLabel(_ref7) {
188
+ var apiRef = _ref7.apiRef,
189
+ aggregationRule = _ref7.aggregationRule;
190
+
191
+ if (aggregationRule.aggregationFunction.label != null) {
192
+ return aggregationRule.aggregationFunction.label;
193
+ }
194
+
195
+ try {
196
+ return apiRef.current.getLocaleText("aggregationFunctionLabel".concat(capitalize(aggregationRule.aggregationFunctionName)));
197
+ } catch (e) {
198
+ return aggregationRule.aggregationFunctionName;
199
+ }
200
+ };
@@ -0,0 +1,4 @@
1
+ export * from './gridAggregationInterfaces';
2
+ export * from './gridAggregationSelectors';
3
+ export * from './gridAggregationFunctions';
4
+ export { GRID_AGGREGATION_ROOT_FOOTER_ROW_ID, getAggregationFooterRowIdFromGroupId } from './gridAggregationUtils';
@@ -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$aggregationMod, _props$initialState, _props$initialState$a;
9
+
10
+ apiRef.current.unstable_caches.aggregation = {
11
+ rulesOnLastColumnHydration: {},
12
+ rulesOnLastRowHydration: {}
13
+ };
14
+ return _extends({}, state, {
15
+ aggregation: {
16
+ model: (_ref = (_props$aggregationMod = props.aggregationModel) != null ? _props$aggregationMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$a = _props$initialState.aggregation) == null ? void 0 : _props$initialState$a.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.aggregationModel,
24
+ propOnChange: props.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.getAggregationPosition,
44
+ aggregationFunctions: props.aggregationFunctions,
45
+ aggregationRowsScope: props.aggregationRowsScope
46
+ });
47
+ apiRef.current.setState(function (state) {
48
+ return _extends({}, state, {
49
+ aggregation: _extends({}, state.aggregation, {
50
+ lookup: aggregationLookup
51
+ })
52
+ });
53
+ });
54
+ }, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope]);
55
+ var aggregationApi = {
56
+ 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.disableAggregation ? {} : getAggregationRules({
68
+ columnsLookup: gridColumnLookupSelector(apiRef),
69
+ aggregationModel: gridAggregationModelSelector(apiRef),
70
+ aggregationFunctions: props.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.aggregationFunctions, props.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.aggregationModel !== undefined) {
92
+ apiRef.current.setAggregationModel(props.aggregationModel);
93
+ }
94
+ }, [apiRef, props.aggregationModel]);
95
+ };
@@ -0,0 +1,141 @@
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.disableAggregation ? {} : getAggregationRules({
25
+ columnsLookup: columnsState.lookup,
26
+ aggregationModel: gridAggregationModelSelector(apiRef),
27
+ aggregationFunctions: props.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.aggregationFunctions, props.disableAggregation]);
53
+ var addGroupFooterRows = React.useCallback(function (groupingParams) {
54
+ var newGroupingParams;
55
+ var rulesOnLastRowHydration;
56
+
57
+ if (props.disableAggregation) {
58
+ newGroupingParams = groupingParams;
59
+ rulesOnLastRowHydration = {};
60
+ } else {
61
+ var aggregationRules = getAggregationRules({
62
+ columnsLookup: gridColumnLookupSelector(apiRef),
63
+ aggregationModel: gridAggregationModelSelector(apiRef),
64
+ aggregationFunctions: props.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.getAggregationPosition,
76
+ apiRef: apiRef
77
+ });
78
+ }
79
+ }
80
+
81
+ apiRef.current.unstable_caches.aggregation.rulesOnLastRowHydration = rulesOnLastRowHydration;
82
+ return newGroupingParams;
83
+ }, [apiRef, props.disableAggregation, props.getAggregationPosition, props.aggregationFunctions]);
84
+ var addColumnMenuButtons = React.useCallback(function (initialValue, column) {
85
+ if (props.disableAggregation) {
86
+ return initialValue;
87
+ }
88
+
89
+ var availableAggregationFunctions = getAvailableAggregationFunctions({
90
+ aggregationFunctions: props.aggregationFunctions,
91
+ column: column
92
+ });
93
+
94
+ if (availableAggregationFunctions.length === 0) {
95
+ return initialValue;
96
+ }
97
+
98
+ return [].concat(_toConsumableArray(initialValue), [/*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsx(GridAggregationColumnMenuItem, {
99
+ column: column,
100
+ label: apiRef.current.getLocaleText('aggregationMenuItemHeader'),
101
+ availableAggregationFunctions: availableAggregationFunctions
102
+ })]);
103
+ }, [apiRef, props.aggregationFunctions, props.disableAggregation]);
104
+ var stateExportPreProcessing = React.useCallback(function (prevState) {
105
+ if (props.disableAggregation) {
106
+ return prevState;
107
+ }
108
+
109
+ var aggregationModelToExport = gridAggregationModelSelector(apiRef);
110
+
111
+ if (Object.values(aggregationModelToExport).length === 0) {
112
+ return prevState;
113
+ }
114
+
115
+ return _extends({}, prevState, {
116
+ aggregation: {
117
+ model: aggregationModelToExport
118
+ }
119
+ });
120
+ }, [apiRef, props.disableAggregation]);
121
+ var stateRestorePreProcessing = React.useCallback(function (params, context) {
122
+ var _context$stateToResto;
123
+
124
+ if (props.disableAggregation) {
125
+ return params;
126
+ }
127
+
128
+ var aggregationModel = (_context$stateToResto = context.stateToRestore.aggregation) == null ? void 0 : _context$stateToResto.model;
129
+
130
+ if (aggregationModel != null) {
131
+ apiRef.current.setState(mergeStateWithAggregationModel(aggregationModel));
132
+ }
133
+
134
+ return params;
135
+ }, [apiRef, props.disableAggregation]);
136
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateAggregatedColumns);
137
+ useGridRegisterPipeProcessor(apiRef, 'hydrateRows', addGroupFooterRows);
138
+ useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
139
+ useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
140
+ useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
141
+ };