@mui/x-data-grid-generator 7.21.0 → 7.22.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.
- package/CHANGELOG.md +142 -0
- package/hooks/index.d.ts +2 -1
- package/hooks/index.js +1 -1
- package/hooks/serverUtils.d.ts +9 -6
- package/hooks/serverUtils.js +118 -9
- package/hooks/useMockServer.d.ts +15 -2
- package/hooks/useMockServer.js +73 -17
- package/hooks/useMovieData.d.ts +3 -1
- package/hooks/useMovieData.js +2 -0
- package/hooks/useQuery.js +6 -1
- package/index.js +1 -1
- package/modern/hooks/index.js +1 -1
- package/modern/hooks/serverUtils.js +118 -9
- package/modern/hooks/useMockServer.js +73 -17
- package/modern/hooks/useMovieData.js +2 -0
- package/modern/hooks/useQuery.js +6 -1
- package/modern/index.js +1 -1
- package/node/hooks/index.js +7 -11
- package/node/hooks/serverUtils.js +121 -11
- package/node/hooks/useMockServer.js +72 -16
- package/node/hooks/useMovieData.js +5 -1
- package/node/hooks/useQuery.js +6 -1
- package/node/index.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,148 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 7.22.1
|
|
7
|
+
|
|
8
|
+
_Nov 1, 2024_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 7 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🐞 Bugfixes
|
|
13
|
+
- 📚 Documentation improvements
|
|
14
|
+
- 🌍 Improve Polish (pl-PL) locale on the Date Pickers
|
|
15
|
+
|
|
16
|
+
Special thanks go out to the community contributors who have helped make this release possible:
|
|
17
|
+
@wojtkolos, @dpak-maurya, @k-rajat19.
|
|
18
|
+
Following are all team members who have contributed to this release:
|
|
19
|
+
@LukasTy, @arminmeh, @MBilalShafi, @KenanYusuf, @flaviendelangle.
|
|
20
|
+
|
|
21
|
+
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
22
|
+
|
|
23
|
+
### Data Grid
|
|
24
|
+
|
|
25
|
+
#### `@mui/x-data-grid@7.22.1`
|
|
26
|
+
|
|
27
|
+
- [DataGrid] Fix right column group header border (#15152) @KenanYusuf
|
|
28
|
+
- [DataGrid] Fix scroll jump when holding down arrow keys (#15167) @arminmeh
|
|
29
|
+
- [DataGrid] Move `rowGroupingModelChange` handler to respective hook (#15127) @MBilalShafi
|
|
30
|
+
- [DataGrid] Prevent error when deleting the last row (#15153) @dpak-maurya
|
|
31
|
+
- [DataGrid] Fix overlay height in autoHeight mode (#15205) @cherniavskii
|
|
32
|
+
|
|
33
|
+
#### `@mui/x-data-grid-pro@7.22.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
34
|
+
|
|
35
|
+
Same changes as in `@mui/x-data-grid@7.22.1`, plus:
|
|
36
|
+
|
|
37
|
+
- [DataGridPro] Add list view tests (#15166) @KenanYusuf
|
|
38
|
+
|
|
39
|
+
#### `@mui/x-data-grid-premium@7.22.1` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
40
|
+
|
|
41
|
+
- [DataGridPremium] Keep focus on the grouping cell on space bar press #15155 @k-rajat19
|
|
42
|
+
|
|
43
|
+
### Date and Time Pickers
|
|
44
|
+
|
|
45
|
+
#### `@mui/x-date-pickers@7.22.1`
|
|
46
|
+
|
|
47
|
+
- [l10n] Improve Polish (pl-PL) locale (#15177) @wojtkolos
|
|
48
|
+
|
|
49
|
+
#### `@mui/x-date-pickers-pro@7.22.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
50
|
+
|
|
51
|
+
Same changes as in `@mui/x-date-pickers@7.22.1`.
|
|
52
|
+
|
|
53
|
+
### Tree View
|
|
54
|
+
|
|
55
|
+
#### `@mui/x-tree-view@7.22.1`
|
|
56
|
+
|
|
57
|
+
- [TreeView] Export `TreeItem2DragAndDropOverlay` and `TreeItem2LabelInput` from the root of each package (#15208) @flaviendelangle
|
|
58
|
+
- [TreeView] Fix drag and drop color usage (#15149) @LukasTy
|
|
59
|
+
|
|
60
|
+
#### `@mui/x-tree-view-pro@7.22.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
61
|
+
|
|
62
|
+
Same changes as in `@mui/x-tree-view@7.22.1`.
|
|
63
|
+
|
|
64
|
+
### Docs
|
|
65
|
+
|
|
66
|
+
- [docs] Add section explaining how to keep the selection while filtering in Data grid docs (#15199) @arminmeh
|
|
67
|
+
|
|
68
|
+
## 7.22.0
|
|
69
|
+
|
|
70
|
+
_Oct 25, 2024_
|
|
71
|
+
|
|
72
|
+
We'd like to offer a big thanks to the 11 contributors who made this release possible. Here are some highlights ✨:
|
|
73
|
+
|
|
74
|
+
- 🛰 Introduce [server-side support for Data Grid row grouping](https://mui.com/x/react-data-grid/server-side-data/row-grouping/)
|
|
75
|
+
- 🐞 Bugfixes
|
|
76
|
+
- 📚 Documentation improvements
|
|
77
|
+
- 🌍 Improve Portuguese (pt-BR) locale on the Data Grid component
|
|
78
|
+
|
|
79
|
+
Special thanks go out to the community contributors who have helped make this release possible:
|
|
80
|
+
@clins1994, @GITPHLAP, @k-rajat19, @kalyan90, @merotosc, @yash49.
|
|
81
|
+
Following are all team members who have contributed to this release:
|
|
82
|
+
@cherniavskii, @flaviendelangle, @LukasTy, @MBilalShafi, @romgrk.
|
|
83
|
+
|
|
84
|
+
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
85
|
+
|
|
86
|
+
### Data Grid
|
|
87
|
+
|
|
88
|
+
#### `@mui/x-data-grid@7.22.0`
|
|
89
|
+
|
|
90
|
+
- [DataGrid] Fix `GridPanelAnchor` positioning (#15022) @k-rajat19
|
|
91
|
+
- [DataGrid] Fix ugly prop-types for the `pageStyle` prop of the `GridPrintExportMenuItem` component (#15015) @flaviendelangle
|
|
92
|
+
- [DataGrid] Fix value type in filter model for number and boolean column type (#14733) @k-rajat19
|
|
93
|
+
- [DataGrid] Focus next row when the focused row is deleted (#15067) @cherniavskii
|
|
94
|
+
- [DataGrid] Remove some usages of `<Box />` and `<Badge />` (#15013) @romgrk
|
|
95
|
+
- [DataGrid] Fix number of rows to display for page size options with negative value (#14890) @kalyan90
|
|
96
|
+
- [l10n] Improve Portuguese (pt-BR) locale (#15021) @k-rajat19
|
|
97
|
+
|
|
98
|
+
#### `@mui/x-data-grid-pro@7.22.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
99
|
+
|
|
100
|
+
Same changes as in `@mui/x-data-grid@7.22.0`, plus:
|
|
101
|
+
|
|
102
|
+
- [DataGridPro] Fix column pinning layout (#15073) @cherniavskii
|
|
103
|
+
|
|
104
|
+
#### `@mui/x-data-grid-premium@7.22.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
105
|
+
|
|
106
|
+
Same changes as in `@mui/x-data-grid-pro@7.22.0`, plus:
|
|
107
|
+
|
|
108
|
+
- [DataGridPremium] Server-side data source with row grouping (#15109) @MBilalShafi
|
|
109
|
+
|
|
110
|
+
### Date and Time Pickers
|
|
111
|
+
|
|
112
|
+
#### `@mui/x-date-pickers@7.22.0`
|
|
113
|
+
|
|
114
|
+
- [pickers] Fix `DateCalendar` timezone management (#15119) @LukasTy
|
|
115
|
+
- [pickers] Fix `DigitalClock` time options on a `DST` switch day (#15092) @LukasTy
|
|
116
|
+
|
|
117
|
+
#### `@mui/x-date-pickers-pro@7.22.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
118
|
+
|
|
119
|
+
Same changes as in `@mui/x-date-pickers@7.22.0`.
|
|
120
|
+
|
|
121
|
+
### Charts
|
|
122
|
+
|
|
123
|
+
#### `@mui/x-charts@7.22.0`
|
|
124
|
+
|
|
125
|
+
- [charts] Export data type in `onAxisClick(_, data)` callback (#15038) @clins1994
|
|
126
|
+
|
|
127
|
+
#### `@mui/x-charts-pro@7.0.0-beta.6` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
128
|
+
|
|
129
|
+
Same changes as in `@mui/x-charts@7.22.0`.
|
|
130
|
+
|
|
131
|
+
### Tree View
|
|
132
|
+
|
|
133
|
+
#### `@mui/x-tree-view@7.22.0`
|
|
134
|
+
|
|
135
|
+
- [TreeView] Make the cancellable event types public (#14992) @flaviendelangle
|
|
136
|
+
|
|
137
|
+
### Docs
|
|
138
|
+
|
|
139
|
+
- [docs] Fix typo in Tree View docs (#15047) @yash49
|
|
140
|
+
|
|
141
|
+
### Core
|
|
142
|
+
|
|
143
|
+
- [core] Adjust cherry-pick GH actions (#15101) @LukasTy
|
|
144
|
+
- [core] Update prettier target branch (#15100) @MBilalShafi
|
|
145
|
+
- [core] Update some `default-branch-switch` instances for `v7.x` (#15085) @MBilalShafi
|
|
146
|
+
- [test] Revert to using `fireEvent` instead of `userEvent` (#14927) @LukasTy
|
|
147
|
+
|
|
6
148
|
## 7.21.0
|
|
7
149
|
|
|
8
150
|
_Oct 17, 2024_
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './useDemoData';
|
|
2
2
|
export * from './useBasicDemoData';
|
|
3
|
-
export
|
|
3
|
+
export { useMovieData } from './useMovieData';
|
|
4
|
+
export type { Movie } from './useMovieData';
|
|
4
5
|
export * from './useQuery';
|
|
5
6
|
export * from './useMockServer';
|
|
6
7
|
export { loadServerRows } from './serverUtils';
|
package/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./useDemoData.js";
|
|
2
2
|
export * from "./useBasicDemoData.js";
|
|
3
|
-
export
|
|
3
|
+
export { useMovieData } from "./useMovieData.js";
|
|
4
4
|
export * from "./useQuery.js";
|
|
5
5
|
export * from "./useMockServer.js";
|
|
6
6
|
export { loadServerRows } from "./serverUtils.js";
|
package/hooks/serverUtils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { GridRowModel, GridFilterModel, GridSortModel, GridColDef, GridRowId, GridPaginationModel } from '@mui/x-data-grid-pro';
|
|
2
|
-
import { UseDemoDataOptions } from './useDemoData';
|
|
1
|
+
import { GridRowModel, GridFilterModel, GridSortModel, GridColDef, GridRowId, GridPaginationModel, GridValidRowModel } from '@mui/x-data-grid-pro';
|
|
3
2
|
export interface FakeServerResponse {
|
|
4
3
|
returnedRows: GridRowModel[];
|
|
5
4
|
nextCursor?: string;
|
|
@@ -35,20 +34,24 @@ export interface ServerSideQueryOptions {
|
|
|
35
34
|
sortModel?: GridSortModel;
|
|
36
35
|
firstRowToRender?: number;
|
|
37
36
|
lastRowToRender?: number;
|
|
37
|
+
groupFields?: string[];
|
|
38
38
|
}
|
|
39
|
-
export declare const DEFAULT_DATASET_OPTIONS: UseDemoDataOptions;
|
|
40
39
|
export declare const disableDelay: any;
|
|
41
40
|
export declare const DEFAULT_SERVER_OPTIONS: DefaultServerOptions;
|
|
42
41
|
/**
|
|
43
42
|
* Simulates server data loading
|
|
44
43
|
*/
|
|
45
44
|
export declare const loadServerRows: (rows: GridRowModel[], queryOptions: QueryOptions, serverOptions: ServerOptions, columnsWithDefaultColDef: GridColDef[]) => Promise<FakeServerResponse>;
|
|
46
|
-
interface
|
|
45
|
+
interface NestedDataRowsResponse {
|
|
47
46
|
rows: GridRowModel[];
|
|
48
47
|
rootRowCount: number;
|
|
49
48
|
}
|
|
50
49
|
/**
|
|
51
|
-
* Simulates server data
|
|
50
|
+
* Simulates server data for tree-data feature
|
|
51
|
+
*/
|
|
52
|
+
export declare const processTreeDataRows: (rows: GridRowModel[], queryOptions: ServerSideQueryOptions, serverOptions: ServerOptions, columnsWithDefaultColDef: GridColDef[]) => Promise<NestedDataRowsResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Simulates server data for row grouping feature
|
|
52
55
|
*/
|
|
53
|
-
export declare const
|
|
56
|
+
export declare const processRowGroupingRows: (rows: GridValidRowModel[], queryOptions: ServerSideQueryOptions, serverOptions: ServerOptions, columnsWithDefaultColDef: GridColDef[]) => Promise<NestedDataRowsResponse>;
|
|
54
57
|
export {};
|
package/hooks/serverUtils.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { GridLogicOperator } from '@mui/x-data-grid-pro';
|
|
3
3
|
import { randomInt } from "../services/random-generator.js";
|
|
4
|
-
export const DEFAULT_DATASET_OPTIONS = {
|
|
5
|
-
dataSet: 'Commodity',
|
|
6
|
-
rowLength: 100,
|
|
7
|
-
maxColumns: 6
|
|
8
|
-
};
|
|
9
4
|
export const disableDelay = typeof DISABLE_CHANCE_RANDOM !== 'undefined' && DISABLE_CHANCE_RANDOM;
|
|
10
5
|
export const DEFAULT_SERVER_OPTIONS = {
|
|
11
6
|
minDelay: disableDelay ? 0 : 100,
|
|
@@ -213,8 +208,7 @@ export const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDef
|
|
|
213
208
|
}, delay); // simulate network latency
|
|
214
209
|
});
|
|
215
210
|
};
|
|
216
|
-
const findTreeDataRowChildren = (allRows, parentPath, pathKey = 'path', depth = 1
|
|
217
|
-
) => {
|
|
211
|
+
const findTreeDataRowChildren = (allRows, parentPath, pathKey = 'path', depth = 1, rowQualifier) => {
|
|
218
212
|
const parentDepth = parentPath.length;
|
|
219
213
|
const children = [];
|
|
220
214
|
for (let i = 0; i < allRows.length; i += 1) {
|
|
@@ -224,7 +218,9 @@ const findTreeDataRowChildren = (allRows, parentPath, pathKey = 'path', depth =
|
|
|
224
218
|
continue;
|
|
225
219
|
}
|
|
226
220
|
if ((depth < 0 && rowPath.length > parentDepth || rowPath.length === parentDepth + depth) && parentPath.every((value, index) => value === rowPath[index])) {
|
|
227
|
-
|
|
221
|
+
if (!rowQualifier || rowQualifier(row)) {
|
|
222
|
+
children.push(row);
|
|
223
|
+
}
|
|
228
224
|
}
|
|
229
225
|
}
|
|
230
226
|
return children;
|
|
@@ -287,7 +283,7 @@ const getTreeDataFilteredRows = (rows, filterModel, columnsWithDefaultColDef) =>
|
|
|
287
283
|
};
|
|
288
284
|
|
|
289
285
|
/**
|
|
290
|
-
* Simulates server data
|
|
286
|
+
* Simulates server data for tree-data feature
|
|
291
287
|
*/
|
|
292
288
|
export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWithDefaultColDef) => {
|
|
293
289
|
const {
|
|
@@ -342,4 +338,117 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
|
|
|
342
338
|
});
|
|
343
339
|
}, delay); // simulate network latency
|
|
344
340
|
});
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Simulates server data for row grouping feature
|
|
345
|
+
*/
|
|
346
|
+
export const processRowGroupingRows = (rows, queryOptions, serverOptions, columnsWithDefaultColDef) => {
|
|
347
|
+
const {
|
|
348
|
+
minDelay = 100,
|
|
349
|
+
maxDelay = 300
|
|
350
|
+
} = serverOptions;
|
|
351
|
+
const pathKey = 'path';
|
|
352
|
+
if (maxDelay < minDelay) {
|
|
353
|
+
throw new Error('serverOptions.minDelay is larger than serverOptions.maxDelay ');
|
|
354
|
+
}
|
|
355
|
+
if (queryOptions.groupKeys == null) {
|
|
356
|
+
throw new Error('serverOptions.groupKeys must be defined to compute row grouping data');
|
|
357
|
+
}
|
|
358
|
+
if (queryOptions.groupFields == null) {
|
|
359
|
+
throw new Error('serverOptions.groupFields must be defined to compute row grouping data');
|
|
360
|
+
}
|
|
361
|
+
const delay = randomInt(minDelay, maxDelay);
|
|
362
|
+
const pathsToAutogenerate = new Set();
|
|
363
|
+
let rowsWithPaths = rows;
|
|
364
|
+
const rowsWithMissingGroups = [];
|
|
365
|
+
|
|
366
|
+
// add paths and generate parent rows based on `groupFields`
|
|
367
|
+
const groupFields = queryOptions.groupFields;
|
|
368
|
+
if (groupFields.length > 0) {
|
|
369
|
+
rowsWithPaths = rows.reduce((acc, row) => {
|
|
370
|
+
const partialPath = groupFields.map(field => String(row[field]));
|
|
371
|
+
for (let index = 0; index < partialPath.length; index += 1) {
|
|
372
|
+
const value = partialPath[index];
|
|
373
|
+
if (value === undefined) {
|
|
374
|
+
if (index === 0) {
|
|
375
|
+
rowsWithMissingGroups.push(_extends({}, row, {
|
|
376
|
+
group: false
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
return acc;
|
|
380
|
+
}
|
|
381
|
+
const parentPath = partialPath.slice(0, index + 1);
|
|
382
|
+
const strigifiedPath = parentPath.join(',');
|
|
383
|
+
if (!pathsToAutogenerate.has(strigifiedPath)) {
|
|
384
|
+
pathsToAutogenerate.add(strigifiedPath);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
acc.push(_extends({}, row, {
|
|
388
|
+
path: [...partialPath, '']
|
|
389
|
+
}));
|
|
390
|
+
return acc;
|
|
391
|
+
}, []);
|
|
392
|
+
} else {
|
|
393
|
+
rowsWithPaths = rows.map(row => _extends({}, row, {
|
|
394
|
+
path: ['']
|
|
395
|
+
}));
|
|
396
|
+
}
|
|
397
|
+
const autogeneratedRows = Array.from(pathsToAutogenerate).map(path => {
|
|
398
|
+
const pathArray = path.split(',');
|
|
399
|
+
return {
|
|
400
|
+
id: `auto-generated-parent-${pathArray.join('-')}`,
|
|
401
|
+
path: pathArray.slice(0, pathArray.length),
|
|
402
|
+
group: pathArray.slice(-1)[0]
|
|
403
|
+
};
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// apply plain filtering
|
|
407
|
+
const filteredRows = getTreeDataFilteredRows([...autogeneratedRows, ...rowsWithPaths, ...rowsWithMissingGroups], queryOptions.filterModel, columnsWithDefaultColDef);
|
|
408
|
+
|
|
409
|
+
// get root row count
|
|
410
|
+
const rootRows = findTreeDataRowChildren(filteredRows, []);
|
|
411
|
+
const rootRowCount = rootRows.length;
|
|
412
|
+
let filteredRowsWithMissingGroups = [];
|
|
413
|
+
let childRows = rootRows;
|
|
414
|
+
if (queryOptions.groupKeys.length === 0) {
|
|
415
|
+
filteredRowsWithMissingGroups = filteredRows.filter(({
|
|
416
|
+
group
|
|
417
|
+
}) => group === false);
|
|
418
|
+
} else {
|
|
419
|
+
childRows = findTreeDataRowChildren(filteredRows, queryOptions.groupKeys);
|
|
420
|
+
}
|
|
421
|
+
let childRowsWithDescendantCounts = childRows.map(row => {
|
|
422
|
+
const descendants = findTreeDataRowChildren(filteredRows, row[pathKey], pathKey, -1, ({
|
|
423
|
+
id
|
|
424
|
+
}) => typeof id !== 'string' || !id.startsWith('auto-generated-parent-'));
|
|
425
|
+
const descendantCount = descendants.length;
|
|
426
|
+
return _extends({}, row, {
|
|
427
|
+
descendantCount
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
if (queryOptions.sortModel) {
|
|
431
|
+
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
432
|
+
const sortedMissingGroups = [...filteredRowsWithMissingGroups].sort(rowComparator);
|
|
433
|
+
const sortedChildRows = [...childRowsWithDescendantCounts].sort(rowComparator);
|
|
434
|
+
childRowsWithDescendantCounts = [...sortedMissingGroups, ...sortedChildRows];
|
|
435
|
+
}
|
|
436
|
+
if (queryOptions.paginationModel && queryOptions.groupKeys.length === 0) {
|
|
437
|
+
// Only paginate root rows, grid should refetch root rows when `paginationModel` updates
|
|
438
|
+
const {
|
|
439
|
+
pageSize,
|
|
440
|
+
page
|
|
441
|
+
} = queryOptions.paginationModel;
|
|
442
|
+
if (pageSize < childRowsWithDescendantCounts.length) {
|
|
443
|
+
childRowsWithDescendantCounts = childRowsWithDescendantCounts.slice(page * pageSize, (page + 1) * pageSize);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return new Promise(resolve => {
|
|
447
|
+
setTimeout(() => {
|
|
448
|
+
resolve({
|
|
449
|
+
rows: childRowsWithDescendantCounts,
|
|
450
|
+
rootRowCount
|
|
451
|
+
});
|
|
452
|
+
}, delay); // simulate network latency
|
|
453
|
+
});
|
|
345
454
|
};
|
package/hooks/useMockServer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GridRowModel, GridGetRowsResponse, GridColDef, GridInitialState } from '@mui/x-data-grid-pro';
|
|
2
|
-
import {
|
|
2
|
+
import { AddPathToDemoDataOptions } from '../services/tree-data-generator';
|
|
3
3
|
import type { ServerOptions } from './serverUtils';
|
|
4
4
|
export declare const BASE_URL = "https://mui.com/x/api/data-grid";
|
|
5
5
|
type UseMockServerResponse = {
|
|
@@ -10,7 +10,20 @@ type UseMockServerResponse = {
|
|
|
10
10
|
fetchRows: (url: string) => Promise<GridGetRowsResponse>;
|
|
11
11
|
loadNewData: () => void;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
type DataSet = 'Commodity' | 'Employee' | 'Movies';
|
|
14
|
+
interface UseMockServerOptions {
|
|
15
|
+
dataSet: DataSet;
|
|
16
|
+
/**
|
|
17
|
+
* Has no effect when DataSet='Movies'
|
|
18
|
+
*/
|
|
19
|
+
rowLength: number;
|
|
20
|
+
maxColumns?: number;
|
|
21
|
+
visibleFields?: string[];
|
|
22
|
+
editable?: boolean;
|
|
23
|
+
treeData?: AddPathToDemoDataOptions;
|
|
24
|
+
rowGrouping?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const useMockServer: (dataSetOptions?: Partial<UseMockServerOptions>, serverOptions?: ServerOptions & {
|
|
14
27
|
verbose?: boolean;
|
|
15
28
|
}, shouldRequestsFail?: boolean) => UseMockServerResponse;
|
|
16
29
|
export {};
|
package/hooks/useMockServer.js
CHANGED
|
@@ -2,16 +2,49 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { LRUCache } from 'lru-cache';
|
|
4
4
|
import { getGridDefaultColumnTypes } from '@mui/x-data-grid-pro';
|
|
5
|
-
import {
|
|
5
|
+
import { extrapolateSeed, deepFreeze } from "./useDemoData.js";
|
|
6
|
+
import { getCommodityColumns } from "../columns/commodities.columns.js";
|
|
7
|
+
import { getEmployeeColumns } from "../columns/employees.columns.js";
|
|
6
8
|
import { getRealGridData } from "../services/real-data-service.js";
|
|
7
9
|
import { addTreeDataOptionsToDemoData } from "../services/tree-data-generator.js";
|
|
8
|
-
import { loadServerRows, processTreeDataRows,
|
|
10
|
+
import { loadServerRows, processTreeDataRows, processRowGroupingRows, DEFAULT_SERVER_OPTIONS } from "./serverUtils.js";
|
|
9
11
|
import { randomInt } from "../services/index.js";
|
|
12
|
+
import { getMovieRows, getMovieColumns } from "./useMovieData.js";
|
|
10
13
|
const dataCache = new LRUCache({
|
|
11
14
|
max: 10,
|
|
12
15
|
ttl: 60 * 5 * 1e3 // 5 minutes
|
|
13
16
|
});
|
|
14
17
|
export const BASE_URL = 'https://mui.com/x/api/data-grid';
|
|
18
|
+
const GET_DEFAULT_DATASET_OPTIONS = isRowGrouping => ({
|
|
19
|
+
dataSet: isRowGrouping ? 'Movies' : 'Commodity',
|
|
20
|
+
rowLength: isRowGrouping ? getMovieRows().length : 100,
|
|
21
|
+
maxColumns: 6
|
|
22
|
+
});
|
|
23
|
+
const getColumnsFromOptions = options => {
|
|
24
|
+
let columns;
|
|
25
|
+
switch (options.dataSet) {
|
|
26
|
+
case 'Commodity':
|
|
27
|
+
columns = getCommodityColumns(options.editable);
|
|
28
|
+
break;
|
|
29
|
+
case 'Employee':
|
|
30
|
+
columns = getEmployeeColumns();
|
|
31
|
+
break;
|
|
32
|
+
case 'Movies':
|
|
33
|
+
columns = getMovieColumns();
|
|
34
|
+
break;
|
|
35
|
+
default:
|
|
36
|
+
throw new Error('Unknown dataset');
|
|
37
|
+
}
|
|
38
|
+
if (options.visibleFields) {
|
|
39
|
+
columns = columns.map(col => options.visibleFields?.includes(col.field) ? col : _extends({}, col, {
|
|
40
|
+
hide: true
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
if (options.maxColumns) {
|
|
44
|
+
columns = columns.slice(0, options.maxColumns);
|
|
45
|
+
}
|
|
46
|
+
return columns;
|
|
47
|
+
};
|
|
15
48
|
function decodeParams(url) {
|
|
16
49
|
const params = new URL(url).searchParams;
|
|
17
50
|
const decodedParams = {};
|
|
@@ -42,6 +75,14 @@ const getInitialState = (columns, groupingField) => {
|
|
|
42
75
|
};
|
|
43
76
|
};
|
|
44
77
|
const defaultColDef = getGridDefaultColumnTypes();
|
|
78
|
+
function sendEmptyResponse() {
|
|
79
|
+
return new Promise(resolve => {
|
|
80
|
+
resolve({
|
|
81
|
+
rows: [],
|
|
82
|
+
rowCount: 0
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
45
86
|
export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail) => {
|
|
46
87
|
const [data, setData] = React.useState();
|
|
47
88
|
const [index, setIndex] = React.useState(0);
|
|
@@ -51,7 +92,9 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
51
92
|
shouldRequestsFailRef.current = shouldRequestsFail;
|
|
52
93
|
}
|
|
53
94
|
}, [shouldRequestsFail]);
|
|
54
|
-
const
|
|
95
|
+
const isRowGrouping = dataSetOptions?.rowGrouping ?? false;
|
|
96
|
+
const options = _extends({}, GET_DEFAULT_DATASET_OPTIONS(isRowGrouping), dataSetOptions);
|
|
97
|
+
const isTreeData = options.treeData?.groupingField != null;
|
|
55
98
|
const columns = React.useMemo(() => {
|
|
56
99
|
return getColumnsFromOptions({
|
|
57
100
|
dataSet: options.dataSet,
|
|
@@ -62,7 +105,6 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
62
105
|
}, [options.dataSet, options.editable, options.maxColumns, options.visibleFields]);
|
|
63
106
|
const initialState = React.useMemo(() => getInitialState(columns, options.treeData?.groupingField), [columns, options.treeData?.groupingField]);
|
|
64
107
|
const columnsWithDefaultColDef = React.useMemo(() => columns.map(column => _extends({}, defaultColDef[column.type || 'string'], column)), [columns]);
|
|
65
|
-
const isTreeData = options.treeData?.groupingField != null;
|
|
66
108
|
const getGroupKey = React.useMemo(() => {
|
|
67
109
|
if (isTreeData) {
|
|
68
110
|
return row => row[options.treeData.groupingField];
|
|
@@ -86,6 +128,15 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
86
128
|
setData(newData);
|
|
87
129
|
return undefined;
|
|
88
130
|
}
|
|
131
|
+
if (options.dataSet === 'Movies') {
|
|
132
|
+
const rowsData = {
|
|
133
|
+
rows: getMovieRows(),
|
|
134
|
+
columns
|
|
135
|
+
};
|
|
136
|
+
setData(rowsData);
|
|
137
|
+
dataCache.set(cacheKey, rowsData);
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
89
140
|
let active = true;
|
|
90
141
|
(async () => {
|
|
91
142
|
let rowData;
|
|
@@ -117,13 +168,8 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
117
168
|
};
|
|
118
169
|
}, [columns, isTreeData, options.rowLength, options.treeData?.maxDepth, options.treeData?.groupingField, options.treeData?.averageChildren, options.dataSet, options.maxColumns, index]);
|
|
119
170
|
const fetchRows = React.useCallback(async requestUrl => {
|
|
120
|
-
if (!
|
|
121
|
-
return
|
|
122
|
-
resolve({
|
|
123
|
-
rows: [],
|
|
124
|
-
rowCount: 0
|
|
125
|
-
});
|
|
126
|
-
});
|
|
171
|
+
if (!requestUrl || !data?.rows) {
|
|
172
|
+
return sendEmptyResponse();
|
|
127
173
|
}
|
|
128
174
|
const params = decodeParams(requestUrl);
|
|
129
175
|
const verbose = serverOptions?.verbose ?? true;
|
|
@@ -151,11 +197,22 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
151
197
|
setTimeout(() => reject(new Error('Could not fetch the data')), delay);
|
|
152
198
|
});
|
|
153
199
|
}
|
|
154
|
-
if (isTreeData
|
|
200
|
+
if (isTreeData) {
|
|
201
|
+
const {
|
|
202
|
+
rows,
|
|
203
|
+
rootRowCount
|
|
204
|
+
} = await processTreeDataRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
205
|
+
getRowsResponse = {
|
|
206
|
+
rows: rows.slice().map(row => _extends({}, row, {
|
|
207
|
+
path: undefined
|
|
208
|
+
})),
|
|
209
|
+
rowCount: rootRowCount
|
|
210
|
+
};
|
|
211
|
+
} else if (isRowGrouping) {
|
|
155
212
|
const {
|
|
156
213
|
rows,
|
|
157
214
|
rootRowCount
|
|
158
|
-
} = await
|
|
215
|
+
} = await processRowGroupingRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
159
216
|
getRowsResponse = {
|
|
160
217
|
rows: rows.slice().map(row => _extends({}, row, {
|
|
161
218
|
path: undefined
|
|
@@ -163,12 +220,11 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
163
220
|
rowCount: rootRowCount
|
|
164
221
|
};
|
|
165
222
|
} else {
|
|
166
|
-
// plain data
|
|
167
223
|
const {
|
|
168
224
|
returnedRows,
|
|
169
225
|
nextCursor,
|
|
170
226
|
totalRowCount
|
|
171
|
-
} = await loadServerRows(data
|
|
227
|
+
} = await loadServerRows(data?.rows ?? [], _extends({}, params, params.paginationModel), serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
172
228
|
getRowsResponse = {
|
|
173
229
|
rows: returnedRows,
|
|
174
230
|
rowCount: totalRowCount,
|
|
@@ -183,10 +239,10 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
183
239
|
}
|
|
184
240
|
resolve(getRowsResponse);
|
|
185
241
|
});
|
|
186
|
-
}, [data, serverOptions?.verbose, serverOptions?.minDelay, serverOptions?.maxDelay, serverOptions?.useCursorPagination, isTreeData, columnsWithDefaultColDef]);
|
|
242
|
+
}, [data, serverOptions?.verbose, serverOptions?.minDelay, serverOptions?.maxDelay, serverOptions?.useCursorPagination, isTreeData, columnsWithDefaultColDef, isRowGrouping]);
|
|
187
243
|
return {
|
|
188
244
|
columns: columnsWithDefaultColDef,
|
|
189
|
-
initialState,
|
|
245
|
+
initialState: options.dataSet === 'Movies' ? {} : initialState,
|
|
190
246
|
getGroupKey,
|
|
191
247
|
getChildrenCount,
|
|
192
248
|
fetchRows,
|
package/hooks/useMovieData.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GridColDef } from '@mui/x-data-grid-premium';
|
|
1
|
+
import { GridColDef, GridRowModel } from '@mui/x-data-grid-premium';
|
|
2
2
|
export type Movie = {
|
|
3
3
|
id: number;
|
|
4
4
|
title: string;
|
|
@@ -13,6 +13,8 @@ export type Movie = {
|
|
|
13
13
|
};
|
|
14
14
|
cinematicUniverse?: string;
|
|
15
15
|
};
|
|
16
|
+
export declare const getMovieColumns: () => GridColDef[];
|
|
17
|
+
export declare const getMovieRows: () => GridRowModel<Movie>[];
|
|
16
18
|
export declare const useMovieData: () => {
|
|
17
19
|
rows: Movie[];
|
|
18
20
|
columns: GridColDef[];
|
package/hooks/useMovieData.js
CHANGED
package/hooks/useQuery.js
CHANGED
|
@@ -3,7 +3,12 @@ import * as React from 'react';
|
|
|
3
3
|
import { getGridDefaultColumnTypes } from '@mui/x-data-grid-pro';
|
|
4
4
|
import { isDeepEqual } from '@mui/x-data-grid/internals';
|
|
5
5
|
import { useDemoData, getColumnsFromOptions, getInitialState } from "./useDemoData.js";
|
|
6
|
-
import {
|
|
6
|
+
import { DEFAULT_SERVER_OPTIONS, loadServerRows } from "./serverUtils.js";
|
|
7
|
+
const DEFAULT_DATASET_OPTIONS = {
|
|
8
|
+
dataSet: 'Commodity',
|
|
9
|
+
rowLength: 100,
|
|
10
|
+
maxColumns: 6
|
|
11
|
+
};
|
|
7
12
|
export const createFakeServer = (dataSetOptions, serverOptions) => {
|
|
8
13
|
const dataSetOptionsWithDefault = _extends({}, DEFAULT_DATASET_OPTIONS, dataSetOptions);
|
|
9
14
|
const serverOptionsWithDefault = _extends({}, DEFAULT_SERVER_OPTIONS, serverOptions);
|
package/index.js
CHANGED
package/modern/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./useDemoData.js";
|
|
2
2
|
export * from "./useBasicDemoData.js";
|
|
3
|
-
export
|
|
3
|
+
export { useMovieData } from "./useMovieData.js";
|
|
4
4
|
export * from "./useQuery.js";
|
|
5
5
|
export * from "./useMockServer.js";
|
|
6
6
|
export { loadServerRows } from "./serverUtils.js";
|