@mui/x-data-grid-premium 5.13.1 → 5.15.1

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 +147 -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 +4 -4
  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,73 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.GridFooterCell = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
13
+
14
+ var React = _interopRequireWildcard(require("react"));
15
+
16
+ var _xDataGrid = require("@mui/x-data-grid");
17
+
18
+ var _styles = require("@mui/material/styles");
19
+
20
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
21
+
22
+ var _material = require("@mui/material");
23
+
24
+ var _useGridRootProps = require("../hooks/utils/useGridRootProps");
25
+
26
+ var _jsxRuntime = require("react/jsx-runtime");
27
+
28
+ const _excluded = ["formattedValue", "colDef", "cellMode", "row", "api", "getValue", "id", "value", "rowNode", "field", "focusElementRef", "hasFocus", "tabIndex", "isEditable"];
29
+
30
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
+
32
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
+
34
+ const GridFooterCellRoot = (0, _styles.styled)(_Box.default, {
35
+ name: 'MuiDataGrid',
36
+ slot: 'FooterCell',
37
+ overridesResolver: (_, styles) => styles.footerCell
38
+ })(({
39
+ theme
40
+ }) => ({
41
+ fontWeight: theme.typography.fontWeightMedium,
42
+ color: theme.palette.primary.dark
43
+ }));
44
+
45
+ const useUtilityClasses = ownerState => {
46
+ const {
47
+ classes
48
+ } = ownerState;
49
+ const slots = {
50
+ root: ['footerCell']
51
+ };
52
+ return (0, _material.unstable_composeClasses)(slots, _xDataGrid.getDataGridUtilityClass, classes);
53
+ };
54
+
55
+ const GridFooterCell = props => {
56
+ const {
57
+ formattedValue
58
+ } = props,
59
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
60
+ const rootProps = (0, _useGridRootProps.useGridRootProps)();
61
+ const ownerState = {
62
+ classes: rootProps.classes
63
+ };
64
+ const classes = useUtilityClasses(ownerState);
65
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridFooterCellRoot, (0, _extends2.default)({
66
+ ownerState: ownerState,
67
+ className: classes.root
68
+ }, other, {
69
+ children: formattedValue
70
+ }));
71
+ };
72
+
73
+ exports.GridFooterCell = GridFooterCell;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.GridGroupingColumnFooterCell = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var React = _interopRequireWildcard(require("react"));
13
+
14
+ var _useGridRootProps = require("../hooks/utils/useGridRootProps");
15
+
16
+ var _GridFooterCell = require("./GridFooterCell");
17
+
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
24
+ const GridGroupingColumnFooterCell = props => {
25
+ const {
26
+ rowNode
27
+ } = props;
28
+ const rootProps = (0, _useGridRootProps.useGridRootProps)();
29
+ let marginLeft;
30
+
31
+ if (rowNode.parent == null) {
32
+ marginLeft = 0;
33
+ } else if (rootProps.rowGroupingColumnMode === 'multiple') {
34
+ marginLeft = 2;
35
+ } else {
36
+ marginLeft = rowNode.depth * 2;
37
+ }
38
+
39
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridFooterCell.GridFooterCell, (0, _extends2.default)({
40
+ sx: {
41
+ ml: marginLeft
42
+ }
43
+ }, props));
44
+ };
45
+
46
+ exports.GridGroupingColumnFooterCell = GridGroupingColumnFooterCell;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createAggregationLookup = void 0;
7
+
8
+ var _xDataGridPro = require("@mui/x-data-grid-pro");
9
+
10
+ var _gridAggregationUtils = require("./gridAggregationUtils");
11
+
12
+ var _gridAggregationSelectors = require("./gridAggregationSelectors");
13
+
14
+ const getAggregationCellValue = ({
15
+ apiRef,
16
+ groupId,
17
+ field,
18
+ aggregationFunction,
19
+ aggregationRowsScope
20
+ }) => {
21
+ const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
22
+ const filteredRowsLookup = (0, _xDataGridPro.gridFilteredRowsLookupSelector)(apiRef);
23
+ let rowIds; // TODO: Add custom root id
24
+
25
+ if (groupId === '') {
26
+ rowIds = (0, _xDataGridPro.gridRowIdsSelector)(apiRef).filter(rowId => !rowTree[rowId].isAutoGenerated);
27
+ } else {
28
+ rowIds = apiRef.current.getRowGroupChildren({
29
+ groupId
30
+ });
31
+ }
32
+
33
+ const values = [];
34
+ rowIds.forEach(rowId => {
35
+ if (aggregationRowsScope === 'filtered' && filteredRowsLookup[rowId] === false) {
36
+ return;
37
+ }
38
+
39
+ values.push(apiRef.current.getCellValue(rowId, field));
40
+ });
41
+ return aggregationFunction.apply({
42
+ values
43
+ });
44
+ };
45
+
46
+ const getGroupAggregatedValue = ({
47
+ groupId,
48
+ apiRef,
49
+ aggregationRowsScope,
50
+ aggregatedFields,
51
+ aggregationRules,
52
+ position
53
+ }) => {
54
+ const groupAggregationLookup = {};
55
+
56
+ for (let j = 0; j < aggregatedFields.length; j += 1) {
57
+ const aggregatedField = aggregatedFields[j];
58
+ const columnAggregationRules = aggregationRules[aggregatedField];
59
+ groupAggregationLookup[aggregatedField] = {
60
+ position,
61
+ value: getAggregationCellValue({
62
+ apiRef,
63
+ groupId,
64
+ field: aggregatedField,
65
+ aggregationFunction: columnAggregationRules.aggregationFunction,
66
+ aggregationRowsScope
67
+ })
68
+ };
69
+ }
70
+
71
+ return groupAggregationLookup;
72
+ };
73
+
74
+ const createAggregationLookup = ({
75
+ apiRef,
76
+ aggregationFunctions,
77
+ aggregationRowsScope,
78
+ getAggregationPosition
79
+ }) => {
80
+ const aggregationRules = (0, _gridAggregationUtils.getAggregationRules)({
81
+ columnsLookup: (0, _xDataGridPro.gridColumnLookupSelector)(apiRef),
82
+ aggregationModel: (0, _gridAggregationSelectors.gridAggregationModelSelector)(apiRef),
83
+ aggregationFunctions
84
+ });
85
+ const aggregatedFields = Object.keys(aggregationRules);
86
+
87
+ if (aggregatedFields.length === 0) {
88
+ return {};
89
+ }
90
+
91
+ const aggregationLookup = {};
92
+ const rowIds = (0, _xDataGridPro.gridRowIdsSelector)(apiRef);
93
+ const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
94
+
95
+ for (let i = 0; i < rowIds.length; i += 1) {
96
+ var _node$children;
97
+
98
+ const rowId = rowIds[i];
99
+ const node = rowTree[rowId];
100
+ const hasChildren = (_node$children = node.children) == null ? void 0 : _node$children.some(childId => {
101
+ var _rowTree$childId$posi;
102
+
103
+ return ((_rowTree$childId$posi = rowTree[childId].position) != null ? _rowTree$childId$posi : 'body') === 'body';
104
+ });
105
+
106
+ if (hasChildren) {
107
+ const position = getAggregationPosition(node);
108
+
109
+ if (position != null) {
110
+ aggregationLookup[rowId] = getGroupAggregatedValue({
111
+ groupId: rowId,
112
+ apiRef,
113
+ aggregatedFields,
114
+ aggregationRowsScope,
115
+ aggregationRules,
116
+ position
117
+ });
118
+ }
119
+ }
120
+ } // TODO: Add custom root id
121
+
122
+
123
+ const position = getAggregationPosition(null);
124
+
125
+ if (position != null) {
126
+ aggregationLookup[''] = getGroupAggregatedValue({
127
+ groupId: '',
128
+ apiRef,
129
+ aggregatedFields,
130
+ aggregationRowsScope,
131
+ aggregationRules,
132
+ position
133
+ });
134
+ }
135
+
136
+ return aggregationLookup;
137
+ };
138
+
139
+ exports.createAggregationLookup = createAggregationLookup;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GRID_AGGREGATION_FUNCTIONS = void 0;
7
+
8
+ var _internals = require("@mui/x-data-grid-pro/internals");
9
+
10
+ const sumAgg = {
11
+ apply: ({
12
+ values
13
+ }) => {
14
+ let sum = 0;
15
+
16
+ for (let i = 0; i < values.length; i += 1) {
17
+ const value = values[i];
18
+
19
+ if (value != null) {
20
+ sum += value;
21
+ }
22
+ }
23
+
24
+ return sum;
25
+ },
26
+ columnTypes: ['number']
27
+ };
28
+ const avgAgg = {
29
+ apply: params => {
30
+ if (params.values.length === 0) {
31
+ return null;
32
+ }
33
+
34
+ const sum = sumAgg.apply(params);
35
+ return sum / params.values.length;
36
+ },
37
+ columnTypes: ['number']
38
+ };
39
+ const minAgg = {
40
+ apply: ({
41
+ values
42
+ }) => {
43
+ if (values.length === 0) {
44
+ return null;
45
+ }
46
+
47
+ let min = +Infinity;
48
+
49
+ for (let i = 0; i < values.length; i += 1) {
50
+ const value = values[i];
51
+
52
+ if (value != null && value < min) {
53
+ min = value;
54
+ }
55
+ }
56
+
57
+ return min;
58
+ },
59
+ columnTypes: ['number', 'date', 'dateTime']
60
+ };
61
+ const maxAgg = {
62
+ apply: ({
63
+ values
64
+ }) => {
65
+ if (values.length === 0) {
66
+ return null;
67
+ }
68
+
69
+ let max = -Infinity;
70
+
71
+ for (let i = 0; i < values.length; i += 1) {
72
+ const value = values[i];
73
+
74
+ if (value != null && value > max) {
75
+ max = value;
76
+ }
77
+ }
78
+
79
+ return max;
80
+ },
81
+ columnTypes: ['number', 'date', 'dateTime']
82
+ };
83
+ const sizeAgg = {
84
+ apply: ({
85
+ values
86
+ }) => {
87
+ return values.length;
88
+ },
89
+ valueFormatter: params => {
90
+ if (params.value == null || !(0, _internals.isNumber)(params.value)) {
91
+ return params.value;
92
+ }
93
+
94
+ return params.value.toLocaleString();
95
+ },
96
+ hasCellUnit: false
97
+ };
98
+ const GRID_AGGREGATION_FUNCTIONS = {
99
+ sum: sumAgg,
100
+ avg: avgAgg,
101
+ min: minAgg,
102
+ max: maxAgg,
103
+ size: sizeAgg
104
+ };
105
+ exports.GRID_AGGREGATION_FUNCTIONS = GRID_AGGREGATION_FUNCTIONS;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.gridAggregationStateSelector = exports.gridAggregationModelSelector = exports.gridAggregationLookupSelector = void 0;
7
+
8
+ var _internals = require("@mui/x-data-grid-pro/internals");
9
+
10
+ const gridAggregationStateSelector = state => state.aggregation;
11
+
12
+ exports.gridAggregationStateSelector = gridAggregationStateSelector;
13
+ const gridAggregationModelSelector = (0, _internals.createSelector)(gridAggregationStateSelector, aggregationState => aggregationState.model);
14
+ exports.gridAggregationModelSelector = gridAggregationModelSelector;
15
+ const gridAggregationLookupSelector = (0, _internals.createSelector)(gridAggregationStateSelector, aggregationState => aggregationState.lookup);
16
+ exports.gridAggregationLookupSelector = gridAggregationLookupSelector;
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.mergeStateWithAggregationModel = exports.hasAggregationRulesChanged = exports.getAvailableAggregationFunctions = exports.getAggregationRules = exports.getAggregationFunctionLabel = exports.getAggregationFooterRowIdFromGroupId = exports.canColumnHaveAggregationFunction = exports.addFooterRows = exports.GRID_AGGREGATION_ROOT_FOOTER_ROW_ID = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _material = require("@mui/material");
13
+
14
+ var _internals = require("@mui/x-data-grid-pro/internals");
15
+
16
+ const GRID_AGGREGATION_ROOT_FOOTER_ROW_ID = 'auto-generated-group-footer-root';
17
+ exports.GRID_AGGREGATION_ROOT_FOOTER_ROW_ID = GRID_AGGREGATION_ROOT_FOOTER_ROW_ID;
18
+
19
+ const getAggregationFooterRowIdFromGroupId = groupId => {
20
+ if (groupId == null) {
21
+ return GRID_AGGREGATION_ROOT_FOOTER_ROW_ID;
22
+ }
23
+
24
+ return `auto-generated-group-footer-${groupId}`;
25
+ };
26
+
27
+ exports.getAggregationFooterRowIdFromGroupId = getAggregationFooterRowIdFromGroupId;
28
+
29
+ const canColumnHaveAggregationFunction = ({
30
+ column,
31
+ aggregationFunctionName,
32
+ aggregationFunction
33
+ }) => {
34
+ if (!column || !column.aggregable) {
35
+ return false;
36
+ }
37
+
38
+ if (!aggregationFunction) {
39
+ return false;
40
+ }
41
+
42
+ if (column.availableAggregationFunctions != null) {
43
+ return column.availableAggregationFunctions.includes(aggregationFunctionName);
44
+ }
45
+
46
+ if (!aggregationFunction.columnTypes) {
47
+ return true;
48
+ }
49
+
50
+ return aggregationFunction.columnTypes.includes(column.type);
51
+ };
52
+
53
+ exports.canColumnHaveAggregationFunction = canColumnHaveAggregationFunction;
54
+
55
+ const getAvailableAggregationFunctions = ({
56
+ aggregationFunctions,
57
+ column
58
+ }) => Object.keys(aggregationFunctions).filter(aggregationFunctionName => canColumnHaveAggregationFunction({
59
+ column,
60
+ aggregationFunctionName,
61
+ aggregationFunction: aggregationFunctions[aggregationFunctionName]
62
+ }));
63
+
64
+ exports.getAvailableAggregationFunctions = getAvailableAggregationFunctions;
65
+
66
+ const mergeStateWithAggregationModel = aggregationModel => state => (0, _extends2.default)({}, state, {
67
+ aggregation: (0, _extends2.default)({}, state.aggregation, {
68
+ model: aggregationModel
69
+ })
70
+ });
71
+
72
+ exports.mergeStateWithAggregationModel = mergeStateWithAggregationModel;
73
+
74
+ const getAggregationRules = ({
75
+ columnsLookup,
76
+ aggregationModel,
77
+ aggregationFunctions
78
+ }) => {
79
+ const aggregationRules = {};
80
+ Object.entries(aggregationModel).forEach(([field, columnItem]) => {
81
+ if (columnsLookup[field] && canColumnHaveAggregationFunction({
82
+ column: columnsLookup[field],
83
+ aggregationFunctionName: columnItem,
84
+ aggregationFunction: aggregationFunctions[columnItem]
85
+ })) {
86
+ aggregationRules[field] = {
87
+ aggregationFunctionName: columnItem,
88
+ aggregationFunction: aggregationFunctions[columnItem]
89
+ };
90
+ }
91
+ });
92
+ return aggregationRules;
93
+ };
94
+ /**
95
+ * Add a footer for each group that has at least one column with an aggregated value.
96
+ */
97
+
98
+
99
+ exports.getAggregationRules = getAggregationRules;
100
+
101
+ const addFooterRows = ({
102
+ groupingParams,
103
+ aggregationRules,
104
+ getAggregationPosition,
105
+ apiRef
106
+ }) => {
107
+ if (Object.keys(aggregationRules).length === 0) {
108
+ return groupingParams;
109
+ }
110
+
111
+ const ids = [...groupingParams.ids];
112
+ const idRowsLookup = (0, _extends2.default)({}, groupingParams.idRowsLookup);
113
+ const tree = (0, _extends2.default)({}, groupingParams.tree);
114
+
115
+ const addGroupFooter = groupNode => {
116
+ var _groupNode$id;
117
+
118
+ const groupId = (_groupNode$id = groupNode == null ? void 0 : groupNode.id) != null ? _groupNode$id : null;
119
+
120
+ if (getAggregationPosition(groupNode) !== 'footer') {
121
+ return;
122
+ }
123
+
124
+ const footerId = getAggregationFooterRowIdFromGroupId(groupId);
125
+ ids.push(footerId);
126
+ idRowsLookup[footerId] = {};
127
+ tree[footerId] = {
128
+ id: footerId,
129
+ isAutoGenerated: true,
130
+ parent: groupId,
131
+ depth: groupNode ? groupNode.depth + 1 : 0,
132
+ groupingKey: null,
133
+ groupingField: null,
134
+ position: 'footer'
135
+ };
136
+
137
+ if (groupId != null) {
138
+ tree[groupId] = (0, _extends2.default)({}, tree[groupId], {
139
+ footerId
140
+ });
141
+ }
142
+ }; // If the tree is flat, we don't need to loop through the rows
143
+
144
+
145
+ if (groupingParams.treeDepth > 1) {
146
+ groupingParams.ids.forEach(parentId => {
147
+ const parentNode = tree[parentId];
148
+
149
+ if (parentNode.depth === groupingParams.treeDepth - 1) {
150
+ return;
151
+ }
152
+
153
+ addGroupFooter(parentNode);
154
+ });
155
+ }
156
+
157
+ let newGroupingParams = (0, _extends2.default)({}, groupingParams, {
158
+ tree,
159
+ idRowsLookup,
160
+ ids
161
+ });
162
+
163
+ if (getAggregationPosition(null) === 'footer') {
164
+ newGroupingParams = (0, _internals.addPinnedRow)({
165
+ groupingParams: newGroupingParams,
166
+ rowModel: {},
167
+ rowId: getAggregationFooterRowIdFromGroupId(null),
168
+ position: 'bottom',
169
+ apiRef
170
+ });
171
+ }
172
+
173
+ return (0, _extends2.default)({}, groupingParams, newGroupingParams);
174
+ };
175
+ /**
176
+ * Compares two sets of aggregation rules to determine if they are equal or not.
177
+ */
178
+
179
+
180
+ exports.addFooterRows = addFooterRows;
181
+
182
+ const hasAggregationRulesChanged = (previousValue, newValue) => {
183
+ const previousFields = Object.keys(previousValue != null ? previousValue : {});
184
+ const newFields = Object.keys(newValue);
185
+
186
+ if (!(0, _internals.isDeepEqual)(previousFields, newFields)) {
187
+ return true;
188
+ }
189
+
190
+ return newFields.some(field => {
191
+ const previousRule = previousValue == null ? void 0 : previousValue[field];
192
+ const newRule = newValue[field];
193
+
194
+ if ((previousRule == null ? void 0 : previousRule.aggregationFunction) !== (newRule == null ? void 0 : newRule.aggregationFunction)) {
195
+ return true;
196
+ }
197
+
198
+ if ((previousRule == null ? void 0 : previousRule.aggregationFunctionName) !== (newRule == null ? void 0 : newRule.aggregationFunctionName)) {
199
+ return true;
200
+ }
201
+
202
+ return false;
203
+ });
204
+ };
205
+
206
+ exports.hasAggregationRulesChanged = hasAggregationRulesChanged;
207
+
208
+ const getAggregationFunctionLabel = ({
209
+ apiRef,
210
+ aggregationRule
211
+ }) => {
212
+ if (aggregationRule.aggregationFunction.label != null) {
213
+ return aggregationRule.aggregationFunction.label;
214
+ }
215
+
216
+ try {
217
+ return apiRef.current.getLocaleText(`aggregationFunctionLabel${(0, _material.capitalize)(aggregationRule.aggregationFunctionName)}`);
218
+ } catch (e) {
219
+ return aggregationRule.aggregationFunctionName;
220
+ }
221
+ };
222
+
223
+ exports.getAggregationFunctionLabel = getAggregationFunctionLabel;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ GRID_AGGREGATION_ROOT_FOOTER_ROW_ID: true,
8
+ getAggregationFooterRowIdFromGroupId: true
9
+ };
10
+ Object.defineProperty(exports, "GRID_AGGREGATION_ROOT_FOOTER_ROW_ID", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _gridAggregationUtils.GRID_AGGREGATION_ROOT_FOOTER_ROW_ID;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "getAggregationFooterRowIdFromGroupId", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _gridAggregationUtils.getAggregationFooterRowIdFromGroupId;
20
+ }
21
+ });
22
+
23
+ var _gridAggregationInterfaces = require("./gridAggregationInterfaces");
24
+
25
+ Object.keys(_gridAggregationInterfaces).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _gridAggregationInterfaces[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function () {
32
+ return _gridAggregationInterfaces[key];
33
+ }
34
+ });
35
+ });
36
+
37
+ var _gridAggregationSelectors = require("./gridAggregationSelectors");
38
+
39
+ Object.keys(_gridAggregationSelectors).forEach(function (key) {
40
+ if (key === "default" || key === "__esModule") return;
41
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
+ if (key in exports && exports[key] === _gridAggregationSelectors[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _gridAggregationSelectors[key];
47
+ }
48
+ });
49
+ });
50
+
51
+ var _gridAggregationFunctions = require("./gridAggregationFunctions");
52
+
53
+ Object.keys(_gridAggregationFunctions).forEach(function (key) {
54
+ if (key === "default" || key === "__esModule") return;
55
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
56
+ if (key in exports && exports[key] === _gridAggregationFunctions[key]) return;
57
+ Object.defineProperty(exports, key, {
58
+ enumerable: true,
59
+ get: function () {
60
+ return _gridAggregationFunctions[key];
61
+ }
62
+ });
63
+ });
64
+
65
+ var _gridAggregationUtils = require("./gridAggregationUtils");