@mui/x-data-grid-generator 8.0.0-alpha.1 → 8.0.0-alpha.10
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 +1903 -231
- package/hooks/serverUtils.d.ts +9 -5
- package/hooks/serverUtils.js +85 -12
- package/hooks/useDemoData.js +2 -0
- package/hooks/useMockServer.d.ts +2 -1
- package/hooks/useMockServer.js +23 -11
- package/hooks/useQuery.d.ts +3 -3
- package/hooks/useQuery.js +2 -0
- package/index.js +1 -1
- package/modern/hooks/serverUtils.js +85 -12
- package/modern/hooks/useDemoData.js +2 -0
- package/modern/hooks/useMockServer.js +23 -11
- package/modern/hooks/useQuery.js +2 -0
- package/modern/index.js +1 -1
- package/modern/renderer/renderEditProgress.js +2 -0
- package/node/hooks/serverUtils.js +87 -14
- package/node/hooks/useDemoData.js +1 -0
- package/node/hooks/useMockServer.js +23 -12
- package/node/hooks/useQuery.js +1 -0
- package/node/index.js +1 -1
- package/node/renderer/renderEditProgress.js +1 -0
- package/package.json +3 -3
- package/renderer/renderEditProgress.js +2 -0
|
@@ -6,8 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.processTreeDataRows = exports.processRowGroupingRows = exports.loadServerRows = exports.disableDelay = exports.DEFAULT_SERVER_OPTIONS = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
-
var
|
|
9
|
+
var _xDataGridPremium = require("@mui/x-data-grid-premium");
|
|
10
10
|
var _randomGenerator = require("../services/random-generator");
|
|
11
|
+
const getAvailableAggregationFunctions = columnType => {
|
|
12
|
+
const availableAggregationFunctions = new Map();
|
|
13
|
+
Object.keys(_xDataGridPremium.GRID_AGGREGATION_FUNCTIONS).forEach(functionName => {
|
|
14
|
+
const columnTypes = _xDataGridPremium.GRID_AGGREGATION_FUNCTIONS[functionName].columnTypes;
|
|
15
|
+
if (!columnTypes || columnTypes.includes(columnType ?? 'string')) {
|
|
16
|
+
availableAggregationFunctions.set(functionName, _xDataGridPremium.GRID_AGGREGATION_FUNCTIONS[functionName]);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return availableAggregationFunctions;
|
|
20
|
+
};
|
|
11
21
|
const disableDelay = exports.disableDelay = typeof DISABLE_CHANCE_RANDOM !== 'undefined' && DISABLE_CHANCE_RANDOM;
|
|
12
22
|
const DEFAULT_SERVER_OPTIONS = exports.DEFAULT_SERVER_OPTIONS = {
|
|
13
23
|
minDelay: disableDelay ? 0 : 100,
|
|
@@ -117,7 +127,7 @@ const getQuicklyFilteredRows = (rows, filterModel, columnsWithDefaultColDef) =>
|
|
|
117
127
|
if (isRowMatchingQuickFilter) {
|
|
118
128
|
return rows.filter(row => {
|
|
119
129
|
const result = isRowMatchingQuickFilter(row);
|
|
120
|
-
return filterModel.quickFilterLogicOperator ===
|
|
130
|
+
return filterModel.quickFilterLogicOperator === _xDataGridPremium.GridLogicOperator.And ? Object.values(result).every(Boolean) : Object.values(result).some(Boolean);
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
return rows;
|
|
@@ -151,7 +161,7 @@ const getFilteredRows = (rows, filterModel, columnsWithDefaultColDef) => {
|
|
|
151
161
|
value: parsedValue
|
|
152
162
|
}, colDef);
|
|
153
163
|
});
|
|
154
|
-
if (filterModel.logicOperator ===
|
|
164
|
+
if (filterModel.logicOperator === _xDataGridPremium.GridLogicOperator.Or) {
|
|
155
165
|
return rows.filter(row => filterModel.items.some((_, index) => {
|
|
156
166
|
const value = valueGetters[index](row);
|
|
157
167
|
return filterFunctions[index] === null ? true : filterFunctions[index](value);
|
|
@@ -162,6 +172,36 @@ const getFilteredRows = (rows, filterModel, columnsWithDefaultColDef) => {
|
|
|
162
172
|
return filterFunctions[index] === null ? true : filterFunctions[index](value);
|
|
163
173
|
}));
|
|
164
174
|
};
|
|
175
|
+
const applyAggregation = (aggregationModel, colDefs, rows, groupId = 'root') => {
|
|
176
|
+
const columnsToAggregate = Object.keys(aggregationModel);
|
|
177
|
+
if (columnsToAggregate.length === 0) {
|
|
178
|
+
return {};
|
|
179
|
+
}
|
|
180
|
+
const aggregateValues = {};
|
|
181
|
+
columnsToAggregate.forEach(field => {
|
|
182
|
+
const type = colDefs.find(({
|
|
183
|
+
field: f
|
|
184
|
+
}) => f === field)?.type;
|
|
185
|
+
if (!type) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const availableAggregationFunctions = getAvailableAggregationFunctions(type);
|
|
189
|
+
if (!availableAggregationFunctions.has(aggregationModel[field])) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const aggregationFunction = availableAggregationFunctions.get(aggregationModel[field]);
|
|
193
|
+
if (!aggregationFunction) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const values = rows.map(row => row[field]);
|
|
197
|
+
aggregateValues[`${field}Aggregate`] = aggregationFunction.apply({
|
|
198
|
+
values,
|
|
199
|
+
field,
|
|
200
|
+
groupId
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
return aggregateValues;
|
|
204
|
+
};
|
|
165
205
|
|
|
166
206
|
/**
|
|
167
207
|
* Simulates server data loading
|
|
@@ -179,7 +219,9 @@ const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDefaultCol
|
|
|
179
219
|
const {
|
|
180
220
|
cursor,
|
|
181
221
|
page = 0,
|
|
182
|
-
pageSize
|
|
222
|
+
pageSize,
|
|
223
|
+
start,
|
|
224
|
+
end
|
|
183
225
|
} = queryOptions;
|
|
184
226
|
let nextCursor;
|
|
185
227
|
let firstRowIndex;
|
|
@@ -187,28 +229,37 @@ const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDefaultCol
|
|
|
187
229
|
let filteredRows = getFilteredRows(rows, queryOptions.filterModel, columnsWithDefaultColDef);
|
|
188
230
|
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
189
231
|
filteredRows = [...filteredRows].sort(rowComparator);
|
|
232
|
+
let aggregateRow = {};
|
|
233
|
+
if (queryOptions.aggregationModel) {
|
|
234
|
+
aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
|
|
235
|
+
}
|
|
190
236
|
const totalRowCount = filteredRows.length;
|
|
191
|
-
if (
|
|
237
|
+
if (start !== undefined && end !== undefined) {
|
|
238
|
+
firstRowIndex = start;
|
|
239
|
+
lastRowIndex = end;
|
|
240
|
+
} else if (!pageSize) {
|
|
192
241
|
firstRowIndex = 0;
|
|
193
|
-
lastRowIndex = filteredRows.length;
|
|
242
|
+
lastRowIndex = filteredRows.length - 1;
|
|
194
243
|
} else if (useCursorPagination) {
|
|
195
244
|
firstRowIndex = cursor ? filteredRows.findIndex(({
|
|
196
245
|
id
|
|
197
246
|
}) => id === cursor) : 0;
|
|
198
247
|
firstRowIndex = Math.max(firstRowIndex, 0); // if cursor not found return 0
|
|
199
|
-
lastRowIndex = firstRowIndex + pageSize;
|
|
200
|
-
nextCursor = lastRowIndex
|
|
248
|
+
lastRowIndex = firstRowIndex + pageSize - 1;
|
|
249
|
+
nextCursor = filteredRows[lastRowIndex + 1]?.id;
|
|
201
250
|
} else {
|
|
202
251
|
firstRowIndex = page * pageSize;
|
|
203
|
-
lastRowIndex = (page + 1) * pageSize;
|
|
252
|
+
lastRowIndex = (page + 1) * pageSize - 1;
|
|
204
253
|
}
|
|
205
254
|
const hasNextPage = lastRowIndex < filteredRows.length - 1;
|
|
206
|
-
const response = {
|
|
207
|
-
returnedRows: filteredRows.slice(firstRowIndex, lastRowIndex),
|
|
255
|
+
const response = (0, _extends2.default)({
|
|
256
|
+
returnedRows: filteredRows.slice(firstRowIndex, lastRowIndex + 1),
|
|
208
257
|
hasNextPage,
|
|
209
258
|
nextCursor,
|
|
210
259
|
totalRowCount
|
|
211
|
-
}
|
|
260
|
+
}, queryOptions.aggregationModel ? {
|
|
261
|
+
aggregateRow
|
|
262
|
+
} : {});
|
|
212
263
|
return new Promise(resolve => {
|
|
213
264
|
setTimeout(() => {
|
|
214
265
|
resolve(response);
|
|
@@ -319,6 +370,12 @@ const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWithDefau
|
|
|
319
370
|
let childRowsWithDescendantCounts = childRows.map(row => {
|
|
320
371
|
const descendants = findTreeDataRowChildren(filteredRows, row[pathKey], pathKey, -1);
|
|
321
372
|
const descendantCount = descendants.length;
|
|
373
|
+
if (descendantCount > 0 && queryOptions.aggregationModel) {
|
|
374
|
+
// Parent row, compute aggregation
|
|
375
|
+
return (0, _extends2.default)({}, row, {
|
|
376
|
+
descendantCount
|
|
377
|
+
}, applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, descendants, row.id));
|
|
378
|
+
}
|
|
322
379
|
return (0, _extends2.default)({}, row, {
|
|
323
380
|
descendantCount
|
|
324
381
|
});
|
|
@@ -328,6 +385,10 @@ const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWithDefau
|
|
|
328
385
|
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
329
386
|
childRowsWithDescendantCounts = [...childRowsWithDescendantCounts].sort(rowComparator);
|
|
330
387
|
}
|
|
388
|
+
let aggregateRow;
|
|
389
|
+
if (queryOptions.aggregationModel) {
|
|
390
|
+
aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
|
|
391
|
+
}
|
|
331
392
|
if (queryOptions.paginationModel && queryOptions.groupKeys.length === 0) {
|
|
332
393
|
// Only paginate root rows, grid should refetch root rows when `paginationModel` updates
|
|
333
394
|
const {
|
|
@@ -342,7 +403,8 @@ const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWithDefau
|
|
|
342
403
|
setTimeout(() => {
|
|
343
404
|
resolve({
|
|
344
405
|
rows: childRowsWithDescendantCounts,
|
|
345
|
-
rootRowCount
|
|
406
|
+
rootRowCount,
|
|
407
|
+
aggregateRow
|
|
346
408
|
});
|
|
347
409
|
}, delay); // simulate network latency
|
|
348
410
|
});
|
|
@@ -432,6 +494,12 @@ const processRowGroupingRows = (rows, queryOptions, serverOptions, columnsWithDe
|
|
|
432
494
|
id
|
|
433
495
|
}) => typeof id !== 'string' || !id.startsWith('auto-generated-parent-'));
|
|
434
496
|
const descendantCount = descendants.length;
|
|
497
|
+
if (descendantCount > 0 && queryOptions.aggregationModel) {
|
|
498
|
+
// Parent row, compute aggregation
|
|
499
|
+
return (0, _extends2.default)({}, row, {
|
|
500
|
+
descendantCount
|
|
501
|
+
}, applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, descendants, row.id));
|
|
502
|
+
}
|
|
435
503
|
return (0, _extends2.default)({}, row, {
|
|
436
504
|
descendantCount
|
|
437
505
|
});
|
|
@@ -442,6 +510,10 @@ const processRowGroupingRows = (rows, queryOptions, serverOptions, columnsWithDe
|
|
|
442
510
|
const sortedChildRows = [...childRowsWithDescendantCounts].sort(rowComparator);
|
|
443
511
|
childRowsWithDescendantCounts = [...sortedMissingGroups, ...sortedChildRows];
|
|
444
512
|
}
|
|
513
|
+
let aggregateRow;
|
|
514
|
+
if (queryOptions.aggregationModel) {
|
|
515
|
+
aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
|
|
516
|
+
}
|
|
445
517
|
if (queryOptions.paginationModel && queryOptions.groupKeys.length === 0) {
|
|
446
518
|
// Only paginate root rows, grid should refetch root rows when `paginationModel` updates
|
|
447
519
|
const {
|
|
@@ -456,7 +528,8 @@ const processRowGroupingRows = (rows, queryOptions, serverOptions, columnsWithDe
|
|
|
456
528
|
setTimeout(() => {
|
|
457
529
|
resolve({
|
|
458
530
|
rows: childRowsWithDescendantCounts,
|
|
459
|
-
rootRowCount
|
|
531
|
+
rootRowCount,
|
|
532
|
+
aggregateRow
|
|
460
533
|
});
|
|
461
534
|
}, delay); // simulate network latency
|
|
462
535
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
|
|
3
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
5
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
@@ -9,7 +10,7 @@ exports.useMockServer = exports.BASE_URL = void 0;
|
|
|
9
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
11
|
var React = _interopRequireWildcard(require("react"));
|
|
11
12
|
var _lruCache = require("lru-cache");
|
|
12
|
-
var
|
|
13
|
+
var _xDataGridPremium = require("@mui/x-data-grid-premium");
|
|
13
14
|
var _useDemoData = require("./useDemoData");
|
|
14
15
|
var _commodities = require("../columns/commodities.columns");
|
|
15
16
|
var _employees = require("../columns/employees.columns");
|
|
@@ -82,7 +83,7 @@ const getInitialState = (columns, groupingField) => {
|
|
|
82
83
|
}
|
|
83
84
|
};
|
|
84
85
|
};
|
|
85
|
-
const defaultColDef = (0,
|
|
86
|
+
const defaultColDef = (0, _xDataGridPremium.getGridDefaultColumnTypes)();
|
|
86
87
|
function sendEmptyResponse() {
|
|
87
88
|
return new Promise(resolve => {
|
|
88
89
|
resolve({
|
|
@@ -208,38 +209,47 @@ const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail) => {
|
|
|
208
209
|
if (isTreeData) {
|
|
209
210
|
const {
|
|
210
211
|
rows,
|
|
211
|
-
rootRowCount
|
|
212
|
+
rootRowCount,
|
|
213
|
+
aggregateRow
|
|
212
214
|
} = await (0, _serverUtils.processTreeDataRows)(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
213
|
-
getRowsResponse = {
|
|
215
|
+
getRowsResponse = (0, _extends2.default)({
|
|
214
216
|
rows: rows.slice().map(row => (0, _extends2.default)({}, row, {
|
|
215
217
|
path: undefined
|
|
216
218
|
})),
|
|
217
219
|
rowCount: rootRowCount
|
|
218
|
-
}
|
|
220
|
+
}, aggregateRow ? {
|
|
221
|
+
aggregateRow
|
|
222
|
+
} : {});
|
|
219
223
|
} else if (isRowGrouping) {
|
|
220
224
|
const {
|
|
221
225
|
rows,
|
|
222
|
-
rootRowCount
|
|
226
|
+
rootRowCount,
|
|
227
|
+
aggregateRow
|
|
223
228
|
} = await (0, _serverUtils.processRowGroupingRows)(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
224
|
-
getRowsResponse = {
|
|
229
|
+
getRowsResponse = (0, _extends2.default)({
|
|
225
230
|
rows: rows.slice().map(row => (0, _extends2.default)({}, row, {
|
|
226
231
|
path: undefined
|
|
227
232
|
})),
|
|
228
233
|
rowCount: rootRowCount
|
|
229
|
-
}
|
|
234
|
+
}, aggregateRow ? {
|
|
235
|
+
aggregateRow
|
|
236
|
+
} : {});
|
|
230
237
|
} else {
|
|
231
238
|
const {
|
|
232
239
|
returnedRows,
|
|
233
240
|
nextCursor,
|
|
234
|
-
totalRowCount
|
|
241
|
+
totalRowCount,
|
|
242
|
+
aggregateRow
|
|
235
243
|
} = await (0, _serverUtils.loadServerRows)(data?.rows ?? [], (0, _extends2.default)({}, params, params.paginationModel), serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
236
|
-
getRowsResponse = {
|
|
244
|
+
getRowsResponse = (0, _extends2.default)({
|
|
237
245
|
rows: returnedRows,
|
|
238
246
|
rowCount: totalRowCount,
|
|
239
247
|
pageInfo: {
|
|
240
248
|
nextCursor
|
|
241
249
|
}
|
|
242
|
-
}
|
|
250
|
+
}, aggregateRow ? {
|
|
251
|
+
aggregateRow
|
|
252
|
+
} : {});
|
|
243
253
|
}
|
|
244
254
|
return new Promise(resolve => {
|
|
245
255
|
if (verbose) {
|
|
@@ -256,7 +266,8 @@ const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail) => {
|
|
|
256
266
|
fetchRows,
|
|
257
267
|
loadNewData: () => {
|
|
258
268
|
setIndex(oldIndex => oldIndex + 1);
|
|
259
|
-
}
|
|
269
|
+
},
|
|
270
|
+
isReady: Boolean(data?.rows?.length)
|
|
260
271
|
};
|
|
261
272
|
};
|
|
262
273
|
exports.useMockServer = useMockServer;
|
package/node/hooks/useQuery.js
CHANGED
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-data-grid-generator",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.10",
|
|
4
4
|
"description": "Generate fake data for demo purposes only.",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"directory": "packages/x-data-grid-generator"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@babel/runtime": "^7.26.
|
|
26
|
+
"@babel/runtime": "^7.26.7",
|
|
27
27
|
"chance": "^1.1.12",
|
|
28
28
|
"clsx": "^2.1.1",
|
|
29
29
|
"lru-cache": "^11.0.2",
|
|
30
|
-
"@mui/x-data-grid-premium": "8.0.0-alpha.
|
|
30
|
+
"@mui/x-data-grid-premium": "8.0.0-alpha.10"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@emotion/react": "^11.9.0",
|