@mui/x-data-grid-premium 5.11.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 +4052 -0
- package/DataGridPremium/DataGridPremium.d.ts +9 -0
- package/DataGridPremium/DataGridPremium.js +986 -0
- package/DataGridPremium/index.d.ts +2 -0
- package/DataGridPremium/index.js +2 -0
- package/DataGridPremium/package.json +6 -0
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +4 -0
- package/DataGridPremium/useDataGridPremiumComponent.js +78 -0
- package/DataGridPremium/useDataGridPremiumProps.d.ts +6 -0
- package/DataGridPremium/useDataGridPremiumProps.js +37 -0
- package/LICENSE +12 -0
- package/README.md +31 -0
- package/components/GridExcelExportMenuItem.d.ts +9 -0
- package/components/GridExcelExportMenuItem.js +32 -0
- package/components/GridGroupingColumnLeafCell.d.ts +4 -0
- package/components/GridGroupingColumnLeafCell.js +22 -0
- package/components/GridGroupingCriteriaCell.d.ts +7 -0
- package/components/GridGroupingCriteriaCell.js +78 -0
- package/components/GridRowGroupableColumnMenuItems.d.ts +11 -0
- package/components/GridRowGroupableColumnMenuItems.js +63 -0
- package/components/GridRowGroupingColumnMenuItems.d.ts +11 -0
- package/components/GridRowGroupingColumnMenuItems.js +58 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/components/package.json +6 -0
- package/hooks/features/export/gridExcelExportInterface.d.ts +58 -0
- package/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/hooks/features/export/index.d.ts +1 -0
- package/hooks/features/export/index.js +1 -0
- package/hooks/features/export/serializer/excelSerializer.d.ts +14 -0
- package/hooks/features/export/serializer/excelSerializer.js +218 -0
- package/hooks/features/export/useGridExcelExport.d.ts +10 -0
- package/hooks/features/export/useGridExcelExport.js +77 -0
- package/hooks/features/index.d.ts +2 -0
- package/hooks/features/index.js +3 -0
- package/hooks/features/rowGrouping/createGroupingColDef.d.ts +42 -0
- package/hooks/features/rowGrouping/createGroupingColDef.js +318 -0
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +37 -0
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +4 -0
- package/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +27 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +139 -0
- package/hooks/features/rowGrouping/index.d.ts +3 -0
- package/hooks/features/rowGrouping/index.js +3 -0
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +11 -0
- package/hooks/features/rowGrouping/useGridRowGrouping.js +200 -0
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +4 -0
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -0
- package/hooks/package.json +6 -0
- package/hooks/utils/index.d.ts +1 -0
- package/hooks/utils/index.js +1 -0
- package/hooks/utils/useGridApiContext.d.ts +4 -0
- package/hooks/utils/useGridApiContext.js +2 -0
- package/hooks/utils/useGridApiRef.d.ts +4 -0
- package/hooks/utils/useGridApiRef.js +2 -0
- package/hooks/utils/useGridRootProps.d.ts +2 -0
- package/hooks/utils/useGridRootProps.js +2 -0
- package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +12 -0
- package/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
- package/index.d.ts +22 -0
- package/index.js +25 -0
- package/legacy/DataGridPremium/DataGridPremium.js +986 -0
- package/legacy/DataGridPremium/index.js +2 -0
- package/legacy/DataGridPremium/useDataGridPremiumComponent.js +78 -0
- package/legacy/DataGridPremium/useDataGridPremiumProps.js +46 -0
- package/legacy/components/GridExcelExportMenuItem.js +30 -0
- package/legacy/components/GridGroupingColumnLeafCell.js +20 -0
- package/legacy/components/GridGroupingCriteriaCell.js +74 -0
- package/legacy/components/GridRowGroupableColumnMenuItems.js +61 -0
- package/legacy/components/GridRowGroupingColumnMenuItems.js +56 -0
- package/legacy/components/index.js +1 -0
- package/legacy/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/legacy/hooks/features/export/index.js +1 -0
- package/legacy/hooks/features/export/serializer/excelSerializer.js +260 -0
- package/legacy/hooks/features/export/useGridExcelExport.js +111 -0
- package/legacy/hooks/features/index.js +3 -0
- package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +319 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingSelector.js +13 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +147 -0
- package/legacy/hooks/features/rowGrouping/index.js +3 -0
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +206 -0
- package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +215 -0
- package/legacy/hooks/index.js +3 -0
- package/legacy/hooks/utils/index.js +1 -0
- package/legacy/hooks/utils/useGridApiContext.js +2 -0
- package/legacy/hooks/utils/useGridApiRef.js +2 -0
- package/legacy/hooks/utils/useGridRootProps.js +2 -0
- package/legacy/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
- package/legacy/index.js +25 -0
- package/legacy/models/dataGridPremiumProps.js +1 -0
- package/legacy/models/gridApiPremium.js +1 -0
- package/legacy/models/gridGroupingValueGetterParams.js +1 -0
- package/legacy/models/gridStatePremium.js +1 -0
- package/legacy/models/index.js +1 -0
- package/legacy/typeOverloads/index.js +1 -0
- package/legacy/typeOverloads/modules.js +33 -0
- package/legacy/typeOverloads/reexports.js +6 -0
- package/legacy/utils/releaseInfo.js +15 -0
- package/models/dataGridPremiumProps.d.ts +64 -0
- package/models/dataGridPremiumProps.js +1 -0
- package/models/gridApiPremium.d.ts +13 -0
- package/models/gridApiPremium.js +1 -0
- package/models/gridGroupingValueGetterParams.d.ts +31 -0
- package/models/gridGroupingValueGetterParams.js +1 -0
- package/models/gridStatePremium.d.ts +14 -0
- package/models/gridStatePremium.js +1 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/models/package.json +6 -0
- package/modern/DataGridPremium/DataGridPremium.js +986 -0
- package/modern/DataGridPremium/index.js +2 -0
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +76 -0
- package/modern/DataGridPremium/useDataGridPremiumProps.js +37 -0
- package/modern/components/GridExcelExportMenuItem.js +32 -0
- package/modern/components/GridGroupingColumnLeafCell.js +20 -0
- package/modern/components/GridGroupingCriteriaCell.js +76 -0
- package/modern/components/GridRowGroupableColumnMenuItems.js +61 -0
- package/modern/components/GridRowGroupingColumnMenuItems.js +56 -0
- package/modern/components/index.js +1 -0
- package/modern/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/modern/hooks/features/export/index.js +1 -0
- package/modern/hooks/features/export/serializer/excelSerializer.js +216 -0
- package/modern/hooks/features/export/useGridExcelExport.js +73 -0
- package/modern/hooks/features/index.js +3 -0
- package/modern/hooks/features/rowGrouping/createGroupingColDef.js +302 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +137 -0
- package/modern/hooks/features/rowGrouping/index.js +3 -0
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +192 -0
- package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
- package/modern/hooks/index.js +3 -0
- package/modern/hooks/utils/index.js +1 -0
- package/modern/hooks/utils/useGridApiContext.js +2 -0
- package/modern/hooks/utils/useGridApiRef.js +2 -0
- package/modern/hooks/utils/useGridRootProps.js +2 -0
- package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +46 -0
- package/modern/index.js +25 -0
- package/modern/models/dataGridPremiumProps.js +1 -0
- package/modern/models/gridApiPremium.js +1 -0
- package/modern/models/gridGroupingValueGetterParams.js +1 -0
- package/modern/models/gridStatePremium.js +1 -0
- package/modern/models/index.js +1 -0
- package/modern/typeOverloads/index.js +1 -0
- package/modern/typeOverloads/modules.js +33 -0
- package/modern/typeOverloads/reexports.js +6 -0
- package/modern/utils/releaseInfo.js +15 -0
- package/node/DataGridPremium/DataGridPremium.js +1009 -0
- package/node/DataGridPremium/index.js +30 -0
- package/node/DataGridPremium/useDataGridPremiumComponent.js +91 -0
- package/node/DataGridPremium/useDataGridPremiumProps.js +57 -0
- package/node/components/GridExcelExportMenuItem.js +49 -0
- package/node/components/GridGroupingColumnLeafCell.js +38 -0
- package/node/components/GridGroupingCriteriaCell.js +99 -0
- package/node/components/GridRowGroupableColumnMenuItems.js +82 -0
- package/node/components/GridRowGroupingColumnMenuItems.js +78 -0
- package/node/components/index.js +18 -0
- package/node/hooks/features/export/gridExcelExportInterface.js +5 -0
- package/node/hooks/features/export/index.js +18 -0
- package/node/hooks/features/export/serializer/excelSerializer.js +233 -0
- package/node/hooks/features/export/useGridExcelExport.js +95 -0
- package/node/hooks/features/index.js +31 -0
- package/node/hooks/features/rowGrouping/createGroupingColDef.js +341 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +5 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingSelector.js +18 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +172 -0
- package/node/hooks/features/rowGrouping/index.js +51 -0
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +228 -0
- package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +223 -0
- package/node/hooks/index.js +31 -0
- package/node/hooks/utils/index.js +18 -0
- package/node/hooks/utils/useGridApiContext.js +11 -0
- package/node/hooks/utils/useGridApiRef.js +11 -0
- package/node/hooks/utils/useGridRootProps.js +11 -0
- package/node/hooks/utils/useKeepGroupedColumnsHidden.js +66 -0
- package/node/index.js +272 -0
- package/node/models/dataGridPremiumProps.js +5 -0
- package/node/models/gridApiPremium.js +5 -0
- package/node/models/gridGroupingValueGetterParams.js +5 -0
- package/node/models/gridStatePremium.js +5 -0
- package/node/models/index.js +18 -0
- package/node/typeOverloads/index.js +3 -0
- package/node/typeOverloads/modules.js +34 -0
- package/node/typeOverloads/reexports.js +29 -0
- package/node/utils/releaseInfo.js +25 -0
- package/package.json +63 -0
- package/typeOverloads/index.d.ts +1 -0
- package/typeOverloads/index.js +1 -0
- package/typeOverloads/modules.d.ts +0 -0
- package/typeOverloads/modules.js +33 -0
- package/typeOverloads/package.json +6 -0
- package/typeOverloads/reexports.d.ts +22 -0
- package/typeOverloads/reexports.js +6 -0
- package/utils/releaseInfo.d.ts +1 -0
- package/utils/releaseInfo.js +15 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useGridRowGrouping = exports.rowGroupingStateInitializer = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var React = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _Divider = _interopRequireDefault(require("@mui/material/Divider"));
|
|
15
|
+
|
|
16
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
17
|
+
|
|
18
|
+
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
19
|
+
|
|
20
|
+
var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
|
|
21
|
+
|
|
22
|
+
var _gridRowGroupingUtils = require("./gridRowGroupingUtils");
|
|
23
|
+
|
|
24
|
+
var _GridRowGroupableColumnMenuItems = require("../../../components/GridRowGroupableColumnMenuItems");
|
|
25
|
+
|
|
26
|
+
var _GridRowGroupingColumnMenuItems = require("../../../components/GridRowGroupingColumnMenuItems");
|
|
27
|
+
|
|
28
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
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 rowGroupingStateInitializer = (state, props) => {
|
|
35
|
+
var _ref, _props$rowGroupingMod, _props$initialState, _props$initialState$r;
|
|
36
|
+
|
|
37
|
+
return (0, _extends2.default)({}, state, {
|
|
38
|
+
rowGrouping: {
|
|
39
|
+
model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : [],
|
|
40
|
+
unstable_sanitizedModelOnLastRowTreeCreation: []
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @requires useGridColumns (state, method) - can be after, async only
|
|
46
|
+
* @requires useGridRows (state, method) - can be after, async only
|
|
47
|
+
* @requires useGridParamsApi (method) - can be after, async only
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
exports.rowGroupingStateInitializer = rowGroupingStateInitializer;
|
|
52
|
+
|
|
53
|
+
const useGridRowGrouping = (apiRef, props) => {
|
|
54
|
+
apiRef.current.unstable_updateControlState({
|
|
55
|
+
stateId: 'rowGrouping',
|
|
56
|
+
propModel: props.rowGroupingModel,
|
|
57
|
+
propOnChange: props.onRowGroupingModelChange,
|
|
58
|
+
stateSelector: _gridRowGroupingSelector.gridRowGroupingModelSelector,
|
|
59
|
+
changeEvent: 'rowGroupingModelChange'
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* API METHODS
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
const setRowGroupingModel = React.useCallback(model => {
|
|
66
|
+
const currentModel = (0, _gridRowGroupingSelector.gridRowGroupingModelSelector)(apiRef);
|
|
67
|
+
|
|
68
|
+
if (currentModel !== model) {
|
|
69
|
+
apiRef.current.setState((0, _gridRowGroupingUtils.mergeStateWithRowGroupingModel)(model));
|
|
70
|
+
(0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping);
|
|
71
|
+
apiRef.current.forceUpdate();
|
|
72
|
+
}
|
|
73
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
74
|
+
const addRowGroupingCriteria = React.useCallback((field, groupingIndex) => {
|
|
75
|
+
const currentModel = (0, _gridRowGroupingSelector.gridRowGroupingModelSelector)(apiRef);
|
|
76
|
+
|
|
77
|
+
if (currentModel.includes(field)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const cleanGroupingIndex = groupingIndex != null ? groupingIndex : currentModel.length;
|
|
82
|
+
const updatedModel = [...currentModel.slice(0, cleanGroupingIndex), field, ...currentModel.slice(cleanGroupingIndex)];
|
|
83
|
+
apiRef.current.setRowGroupingModel(updatedModel);
|
|
84
|
+
}, [apiRef]);
|
|
85
|
+
const removeRowGroupingCriteria = React.useCallback(field => {
|
|
86
|
+
const currentModel = (0, _gridRowGroupingSelector.gridRowGroupingModelSelector)(apiRef);
|
|
87
|
+
|
|
88
|
+
if (!currentModel.includes(field)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
apiRef.current.setRowGroupingModel(currentModel.filter(el => el !== field));
|
|
93
|
+
}, [apiRef]);
|
|
94
|
+
const setRowGroupingCriteriaIndex = React.useCallback((field, targetIndex) => {
|
|
95
|
+
const currentModel = (0, _gridRowGroupingSelector.gridRowGroupingModelSelector)(apiRef);
|
|
96
|
+
const currentTargetIndex = currentModel.indexOf(field);
|
|
97
|
+
|
|
98
|
+
if (currentTargetIndex === -1) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const updatedModel = [...currentModel];
|
|
103
|
+
updatedModel.splice(targetIndex, 0, updatedModel.splice(currentTargetIndex, 1)[0]);
|
|
104
|
+
apiRef.current.setRowGroupingModel(updatedModel);
|
|
105
|
+
}, [apiRef]);
|
|
106
|
+
const rowGroupingApi = {
|
|
107
|
+
setRowGroupingModel,
|
|
108
|
+
addRowGroupingCriteria,
|
|
109
|
+
removeRowGroupingCriteria,
|
|
110
|
+
setRowGroupingCriteriaIndex
|
|
111
|
+
};
|
|
112
|
+
(0, _xDataGridPro.useGridApiMethod)(apiRef, rowGroupingApi, 'GridRowGroupingApi');
|
|
113
|
+
/**
|
|
114
|
+
* PRE-PROCESSING
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
const addColumnMenuButtons = React.useCallback((initialValue, columns) => {
|
|
118
|
+
if (props.disableRowGrouping) {
|
|
119
|
+
return initialValue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let menuItems;
|
|
123
|
+
|
|
124
|
+
if ((0, _gridRowGroupingUtils.isGroupingColumn)(columns.field)) {
|
|
125
|
+
menuItems = /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridRowGroupingColumnMenuItems.GridRowGroupingColumnMenuItems, {});
|
|
126
|
+
} else if (columns.groupable) {
|
|
127
|
+
menuItems = /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridRowGroupableColumnMenuItems.GridRowGroupableColumnMenuItems, {});
|
|
128
|
+
} else {
|
|
129
|
+
menuItems = null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (menuItems == null) {
|
|
133
|
+
return initialValue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return [...initialValue, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {}), menuItems];
|
|
137
|
+
}, [props.disableRowGrouping]);
|
|
138
|
+
const stateExportPreProcessing = React.useCallback(prevState => {
|
|
139
|
+
if (props.disableRowGrouping) {
|
|
140
|
+
return prevState;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const rowGroupingModelToExport = (0, _gridRowGroupingSelector.gridRowGroupingModelSelector)(apiRef);
|
|
144
|
+
|
|
145
|
+
if (rowGroupingModelToExport.length === 0) {
|
|
146
|
+
return prevState;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return (0, _extends2.default)({}, prevState, {
|
|
150
|
+
rowGrouping: {
|
|
151
|
+
model: rowGroupingModelToExport
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
155
|
+
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
156
|
+
var _context$stateToResto;
|
|
157
|
+
|
|
158
|
+
if (props.disableRowGrouping) {
|
|
159
|
+
return params;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const rowGroupingModel = (_context$stateToResto = context.stateToRestore.rowGrouping) == null ? void 0 : _context$stateToResto.model;
|
|
163
|
+
|
|
164
|
+
if (rowGroupingModel != null) {
|
|
165
|
+
apiRef.current.setState((0, _gridRowGroupingUtils.mergeStateWithRowGroupingModel)(rowGroupingModel));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return params;
|
|
169
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
170
|
+
(0, _internals.useGridRegisterPipeProcessor)(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
171
|
+
(0, _internals.useGridRegisterPipeProcessor)(apiRef, 'exportState', stateExportPreProcessing);
|
|
172
|
+
(0, _internals.useGridRegisterPipeProcessor)(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
173
|
+
/**
|
|
174
|
+
* EVENTS
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
178
|
+
const cellParams = apiRef.current.getCellParams(params.id, params.field);
|
|
179
|
+
|
|
180
|
+
if ((0, _gridRowGroupingUtils.isGroupingColumn)(cellParams.field) && event.key === ' ' && !event.shiftKey) {
|
|
181
|
+
var _gridFilteredDescenda;
|
|
182
|
+
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
const filteredDescendantCount = (_gridFilteredDescenda = (0, _xDataGridPro.gridFilteredDescendantCountLookupSelector)(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
|
|
186
|
+
const isOnGroupingCell = props.rowGroupingColumnMode === 'single' || (0, _gridRowGroupingUtils.getRowGroupingFieldFromGroupingCriteria)(params.rowNode.groupingField) === params.field;
|
|
187
|
+
|
|
188
|
+
if (!isOnGroupingCell || filteredDescendantCount === 0) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
apiRef.current.setRowChildrenExpansion(params.id, !params.rowNode.childrenExpanded);
|
|
193
|
+
}
|
|
194
|
+
}, [apiRef, props.rowGroupingColumnMode]);
|
|
195
|
+
const checkGroupingColumnsModelDiff = React.useCallback(() => {
|
|
196
|
+
const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
|
|
197
|
+
const lastGroupingColumnsModelApplied = (0, _gridRowGroupingSelector.gridRowGroupingStateSelector)(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
|
|
198
|
+
|
|
199
|
+
if (!(0, _internals.isDeepEqual)(lastGroupingColumnsModelApplied, rowGroupingModel)) {
|
|
200
|
+
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
201
|
+
rowGrouping: (0, _extends2.default)({}, state.rowGrouping, {
|
|
202
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
203
|
+
})
|
|
204
|
+
}));
|
|
205
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
|
|
206
|
+
(0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
|
|
207
|
+
// TODO: Add a clean way to re-run a strategy processing without publishing a private event
|
|
208
|
+
|
|
209
|
+
if (apiRef.current.unstable_getActiveStrategy('rowTree') === _gridRowGroupingUtils.ROW_GROUPING_STRATEGY) {
|
|
210
|
+
apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
214
|
+
(0, _xDataGridPro.useGridApiEventHandler)(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
215
|
+
(0, _xDataGridPro.useGridApiEventHandler)(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
|
|
216
|
+
(0, _xDataGridPro.useGridApiEventHandler)(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
|
|
217
|
+
/**
|
|
218
|
+
* EFFECTS
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
React.useEffect(() => {
|
|
222
|
+
if (props.rowGroupingModel !== undefined) {
|
|
223
|
+
apiRef.current.setRowGroupingModel(props.rowGroupingModel);
|
|
224
|
+
}
|
|
225
|
+
}, [apiRef, props.rowGroupingModel]);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
exports.useGridRowGrouping = useGridRowGrouping;
|
|
@@ -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.useGridRowGroupingPreProcessors = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var React = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
15
|
+
|
|
16
|
+
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
17
|
+
|
|
18
|
+
var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
|
|
19
|
+
|
|
20
|
+
var _createGroupingColDef = require("./createGroupingColDef");
|
|
21
|
+
|
|
22
|
+
var _gridRowGroupingUtils = require("./gridRowGroupingUtils");
|
|
23
|
+
|
|
24
|
+
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); }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
const useGridRowGroupingPreProcessors = (apiRef, props) => {
|
|
29
|
+
const getGroupingColDefs = React.useCallback(columnsState => {
|
|
30
|
+
if (props.disableRowGrouping) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const groupingColDefProp = props.groupingColDef; // We can't use `gridGroupingRowsSanitizedModelSelector` here because the new columns are not in the state yet
|
|
35
|
+
|
|
36
|
+
const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingModelSelector)(apiRef).filter(field => !!columnsState.lookup[field]);
|
|
37
|
+
|
|
38
|
+
if (rowGroupingModel.length === 0) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
switch (props.rowGroupingColumnMode) {
|
|
43
|
+
case 'single':
|
|
44
|
+
{
|
|
45
|
+
return [(0, _createGroupingColDef.createGroupingColDefForAllGroupingCriteria)({
|
|
46
|
+
apiRef,
|
|
47
|
+
rowGroupingModel,
|
|
48
|
+
colDefOverride: (0, _gridRowGroupingUtils.getColDefOverrides)(groupingColDefProp, rowGroupingModel),
|
|
49
|
+
columnsLookup: columnsState.lookup
|
|
50
|
+
})];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
case 'multiple':
|
|
54
|
+
{
|
|
55
|
+
return rowGroupingModel.map(groupingCriteria => (0, _createGroupingColDef.createGroupingColDefForOneGroupingCriteria)({
|
|
56
|
+
groupingCriteria,
|
|
57
|
+
colDefOverride: (0, _gridRowGroupingUtils.getColDefOverrides)(groupingColDefProp, [groupingCriteria]),
|
|
58
|
+
groupedByColDef: columnsState.lookup[groupingCriteria],
|
|
59
|
+
columnsLookup: columnsState.lookup
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
default:
|
|
64
|
+
{
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, [apiRef, props.groupingColDef, props.rowGroupingColumnMode, props.disableRowGrouping]);
|
|
69
|
+
const updateGroupingColumn = React.useCallback(columnsState => {
|
|
70
|
+
const groupingColDefs = getGroupingColDefs(columnsState);
|
|
71
|
+
let newColumnFields = [];
|
|
72
|
+
const newColumnsLookup = {}; // We only keep the non-grouping columns
|
|
73
|
+
|
|
74
|
+
columnsState.all.forEach(field => {
|
|
75
|
+
if (!(0, _gridRowGroupingUtils.isGroupingColumn)(field)) {
|
|
76
|
+
newColumnFields.push(field);
|
|
77
|
+
newColumnsLookup[field] = columnsState.lookup[field];
|
|
78
|
+
}
|
|
79
|
+
}); // We add the grouping column
|
|
80
|
+
|
|
81
|
+
groupingColDefs.forEach(groupingColDef => {
|
|
82
|
+
const matchingGroupingColDef = columnsState.lookup[groupingColDef.field];
|
|
83
|
+
|
|
84
|
+
if (matchingGroupingColDef) {
|
|
85
|
+
groupingColDef.width = matchingGroupingColDef.width;
|
|
86
|
+
groupingColDef.flex = matchingGroupingColDef.flex;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
newColumnsLookup[groupingColDef.field] = groupingColDef;
|
|
90
|
+
});
|
|
91
|
+
const startIndex = newColumnFields[0] === '__check__' ? 1 : 0;
|
|
92
|
+
newColumnFields = [...newColumnFields.slice(0, startIndex), ...groupingColDefs.map(colDef => colDef.field), ...newColumnFields.slice(startIndex)];
|
|
93
|
+
columnsState.all = newColumnFields;
|
|
94
|
+
columnsState.lookup = newColumnsLookup;
|
|
95
|
+
return columnsState;
|
|
96
|
+
}, [getGroupingColDefs]);
|
|
97
|
+
const createRowTree = React.useCallback(params => {
|
|
98
|
+
const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
|
|
99
|
+
const columnsLookup = (0, _xDataGridPro.gridColumnLookupSelector)(apiRef);
|
|
100
|
+
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
101
|
+
rowGrouping: (0, _extends2.default)({}, state.rowGrouping, {
|
|
102
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
103
|
+
})
|
|
104
|
+
}));
|
|
105
|
+
const distinctValues = Object.fromEntries(rowGroupingModel.map(groupingField => [groupingField, {
|
|
106
|
+
lookup: {},
|
|
107
|
+
list: []
|
|
108
|
+
}]));
|
|
109
|
+
|
|
110
|
+
const getCellGroupingCriteria = ({
|
|
111
|
+
row,
|
|
112
|
+
id,
|
|
113
|
+
colDef
|
|
114
|
+
}) => {
|
|
115
|
+
let key;
|
|
116
|
+
|
|
117
|
+
if (colDef.groupingValueGetter) {
|
|
118
|
+
const groupingValueGetterParams = {
|
|
119
|
+
colDef,
|
|
120
|
+
field: colDef.field,
|
|
121
|
+
value: row[colDef.field],
|
|
122
|
+
id,
|
|
123
|
+
row,
|
|
124
|
+
rowNode: {
|
|
125
|
+
isAutoGenerated: false,
|
|
126
|
+
id
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
key = colDef.groupingValueGetter(groupingValueGetterParams);
|
|
130
|
+
} else {
|
|
131
|
+
key = row[colDef.field];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
key,
|
|
136
|
+
field: colDef.field
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
params.ids.forEach(rowId => {
|
|
141
|
+
const row = params.idRowsLookup[rowId];
|
|
142
|
+
rowGroupingModel.forEach(groupingCriteria => {
|
|
143
|
+
const {
|
|
144
|
+
key
|
|
145
|
+
} = getCellGroupingCriteria({
|
|
146
|
+
row,
|
|
147
|
+
id: rowId,
|
|
148
|
+
colDef: columnsLookup[groupingCriteria]
|
|
149
|
+
});
|
|
150
|
+
const groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
|
|
151
|
+
|
|
152
|
+
if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
|
|
153
|
+
groupingFieldsDistinctKeys.lookup[key.toString()] = true;
|
|
154
|
+
groupingFieldsDistinctKeys.list.push(key);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
const rows = params.ids.map(rowId => {
|
|
159
|
+
const row = params.idRowsLookup[rowId];
|
|
160
|
+
const parentPath = rowGroupingModel.map(groupingField => getCellGroupingCriteria({
|
|
161
|
+
row,
|
|
162
|
+
id: rowId,
|
|
163
|
+
colDef: columnsLookup[groupingField]
|
|
164
|
+
})).filter(cell => cell.key != null);
|
|
165
|
+
const leafGroupingCriteria = {
|
|
166
|
+
key: rowId.toString(),
|
|
167
|
+
field: null
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
path: [...parentPath, leafGroupingCriteria],
|
|
171
|
+
id: rowId
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
return (0, _internals.buildRowTree)((0, _extends2.default)({}, params, {
|
|
175
|
+
rows,
|
|
176
|
+
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
177
|
+
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
178
|
+
groupingName: _gridRowGroupingUtils.ROW_GROUPING_STRATEGY
|
|
179
|
+
}));
|
|
180
|
+
}, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
|
|
181
|
+
const filterRows = React.useCallback(params => {
|
|
182
|
+
const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
|
|
183
|
+
return (0, _gridRowGroupingUtils.filterRowTreeFromGroupingColumns)({
|
|
184
|
+
rowTree,
|
|
185
|
+
isRowMatchingFilters: params.isRowMatchingFilters
|
|
186
|
+
});
|
|
187
|
+
}, [apiRef]);
|
|
188
|
+
const sortRows = React.useCallback(params => {
|
|
189
|
+
const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
|
|
190
|
+
const rowIds = (0, _xDataGridPro.gridRowIdsSelector)(apiRef);
|
|
191
|
+
return (0, _internals.sortRowTree)({
|
|
192
|
+
rowTree,
|
|
193
|
+
rowIds,
|
|
194
|
+
sortRowList: params.sortRowList,
|
|
195
|
+
disableChildrenSorting: false
|
|
196
|
+
});
|
|
197
|
+
}, [apiRef]);
|
|
198
|
+
(0, _internals.useGridRegisterPipeProcessor)(apiRef, 'hydrateColumns', updateGroupingColumn);
|
|
199
|
+
(0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridRowGroupingUtils.ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
|
|
200
|
+
(0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridRowGroupingUtils.ROW_GROUPING_STRATEGY, 'filtering', filterRows);
|
|
201
|
+
(0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridRowGroupingUtils.ROW_GROUPING_STRATEGY, 'sorting', sortRows);
|
|
202
|
+
/**
|
|
203
|
+
* 1ST RENDER
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
(0, _xDataGridPro.useFirstRender)(() => {
|
|
207
|
+
(0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping);
|
|
208
|
+
});
|
|
209
|
+
/**
|
|
210
|
+
* EFFECTS
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
const isFirstRender = React.useRef(true);
|
|
214
|
+
React.useEffect(() => {
|
|
215
|
+
if (!isFirstRender.current) {
|
|
216
|
+
(0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping);
|
|
217
|
+
} else {
|
|
218
|
+
isFirstRender.current = false;
|
|
219
|
+
}
|
|
220
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
exports.useGridRowGroupingPreProcessors = useGridRowGroupingPreProcessors;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _features = require("./features");
|
|
8
|
+
|
|
9
|
+
Object.keys(_features).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _features[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _features[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _utils = require("./utils");
|
|
21
|
+
|
|
22
|
+
Object.keys(_utils).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _utils[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _useKeepGroupedColumnsHidden = require("./useKeepGroupedColumnsHidden");
|
|
8
|
+
|
|
9
|
+
Object.keys(_useKeepGroupedColumnsHidden).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _useKeepGroupedColumnsHidden[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useKeepGroupedColumnsHidden[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useGridApiContext = void 0;
|
|
7
|
+
|
|
8
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
9
|
+
|
|
10
|
+
const useGridApiContext = _xDataGridPro.useGridApiContext;
|
|
11
|
+
exports.useGridApiContext = useGridApiContext;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useGridApiRef = void 0;
|
|
7
|
+
|
|
8
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
9
|
+
|
|
10
|
+
const useGridApiRef = _xDataGridPro.useGridApiRef;
|
|
11
|
+
exports.useGridApiRef = useGridApiRef;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useGridRootProps = void 0;
|
|
7
|
+
|
|
8
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
9
|
+
|
|
10
|
+
const useGridRootProps = _xDataGridPro.useGridRootProps;
|
|
11
|
+
exports.useGridRootProps = useGridRootProps;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useKeepGroupedColumnsHidden = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var React = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
15
|
+
|
|
16
|
+
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); }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
const updateColumnVisibilityModel = (columnVisibilityModel, rowGroupingModel, prevRowGroupingModel) => {
|
|
21
|
+
const newColumnVisibilityModel = (0, _extends2.default)({}, columnVisibilityModel);
|
|
22
|
+
rowGroupingModel == null ? void 0 : rowGroupingModel.forEach(field => {
|
|
23
|
+
if (!(prevRowGroupingModel != null && prevRowGroupingModel.includes(field))) {
|
|
24
|
+
newColumnVisibilityModel[field] = false;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
prevRowGroupingModel == null ? void 0 : prevRowGroupingModel.forEach(field => {
|
|
28
|
+
if (!(rowGroupingModel != null && rowGroupingModel.includes(field))) {
|
|
29
|
+
newColumnVisibilityModel[field] = true;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return newColumnVisibilityModel;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Automatically hide columns when added to the row grouping model and stop hiding them when they are removed.
|
|
36
|
+
* Handles both the `props.initialState.rowGrouping.model` and `props.rowGroupingModel`
|
|
37
|
+
* Does not work when used with the `hide` property of `GridColDef`
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const useKeepGroupedColumnsHidden = props => {
|
|
42
|
+
var _props$rowGroupingMod, _props$initialState, _props$initialState$r;
|
|
43
|
+
|
|
44
|
+
const initialProps = React.useRef(props);
|
|
45
|
+
const rowGroupingModel = React.useRef((_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model);
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
props.apiRef.current.subscribeEvent(_xDataGridPro.GridEvents.rowGroupingModelChange, newModel => {
|
|
48
|
+
const columnVisibilityModel = updateColumnVisibilityModel((0, _xDataGridPro.gridColumnVisibilityModelSelector)(props.apiRef), newModel, rowGroupingModel.current);
|
|
49
|
+
props.apiRef.current.setColumnVisibilityModel(columnVisibilityModel);
|
|
50
|
+
rowGroupingModel.current = newModel;
|
|
51
|
+
});
|
|
52
|
+
}, [props.apiRef]);
|
|
53
|
+
return React.useMemo(() => {
|
|
54
|
+
var _invariantInitialStat;
|
|
55
|
+
|
|
56
|
+
const invariantInitialState = initialProps.current.initialState;
|
|
57
|
+
const columnVisibilityModel = updateColumnVisibilityModel(invariantInitialState == null ? void 0 : (_invariantInitialStat = invariantInitialState.columns) == null ? void 0 : _invariantInitialStat.columnVisibilityModel, rowGroupingModel.current, undefined);
|
|
58
|
+
return (0, _extends2.default)({}, invariantInitialState, {
|
|
59
|
+
columns: (0, _extends2.default)({}, invariantInitialState == null ? void 0 : invariantInitialState.columns, {
|
|
60
|
+
columnVisibilityModel
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}, []);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.useKeepGroupedColumnsHidden = useKeepGroupedColumnsHidden;
|