@mui/x-data-grid-generator 8.0.0-beta.3 → 8.1.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 +388 -96
- package/columns/commodities.columns.js +1 -1
- package/columns/employees.columns.js +1 -0
- package/constants/prompts.d.ts +1 -1
- package/constants/prompts.js +8 -4
- package/esm/columns/commodities.columns.js +1 -1
- package/esm/columns/employees.columns.js +1 -0
- package/esm/constants/prompts.d.ts +1 -1
- package/esm/constants/prompts.js +8 -4
- package/esm/hooks/serverUtils.js +15 -7
- package/esm/hooks/useDemoData.js +2 -2
- package/esm/hooks/useMockServer.d.ts +2 -2
- package/esm/hooks/useMockServer.js +64 -12
- package/esm/hooks/useQuery.d.ts +6 -3
- package/esm/index.js +1 -1
- package/esm/renderer/renderCountry.d.ts +1 -2
- package/esm/renderer/renderCountry.js +3 -0
- package/esm/services/prompt-resolver.d.ts +2 -2
- package/esm/services/prompt-resolver.js +3 -2
- package/hooks/serverUtils.js +15 -7
- package/hooks/useDemoData.js +2 -2
- package/hooks/useMockServer.d.ts +2 -2
- package/hooks/useMockServer.js +64 -12
- package/hooks/useQuery.d.ts +6 -3
- package/index.js +1 -1
- package/package.json +5 -14
- package/renderer/renderCountry.d.ts +1 -2
- package/renderer/renderCountry.js +3 -0
- package/services/prompt-resolver.d.ts +2 -2
- package/services/prompt-resolver.js +3 -2
- package/modern/columns/commodities.columns.d.ts +0 -2
- package/modern/columns/commodities.columns.js +0 -231
- package/modern/columns/employees.columns.d.ts +0 -2
- package/modern/columns/employees.columns.js +0 -134
- package/modern/columns/index.d.ts +0 -2
- package/modern/columns/index.js +0 -2
- package/modern/constants/prompts.d.ts +0 -2
- package/modern/constants/prompts.js +0 -49
- package/modern/hooks/index.d.ts +0 -8
- package/modern/hooks/index.js +0 -6
- package/modern/hooks/serverUtils.d.ts +0 -61
- package/modern/hooks/serverUtils.js +0 -527
- package/modern/hooks/useBasicDemoData.d.ts +0 -2
- package/modern/hooks/useBasicDemoData.js +0 -5
- package/modern/hooks/useDemoData.d.ts +0 -30
- package/modern/hooks/useDemoData.js +0 -159
- package/modern/hooks/useMockServer.d.ts +0 -31
- package/modern/hooks/useMockServer.js +0 -265
- package/modern/hooks/useMovieData.d.ts +0 -21
- package/modern/hooks/useMovieData.js +0 -500
- package/modern/hooks/useQuery.d.ts +0 -169
- package/modern/hooks/useQuery.js +0 -84
- package/modern/index.d.ts +0 -4
- package/modern/index.js +0 -11
- package/modern/package.json +0 -1
- package/modern/renderer/index.d.ts +0 -16
- package/modern/renderer/index.js +0 -16
- package/modern/renderer/renderAvatar.d.ts +0 -6
- package/modern/renderer/renderAvatar.js +0 -14
- package/modern/renderer/renderCountry.d.ts +0 -4
- package/modern/renderer/renderCountry.js +0 -57
- package/modern/renderer/renderEditCountry.d.ts +0 -4
- package/modern/renderer/renderEditCountry.js +0 -80
- package/modern/renderer/renderEditCurrency.d.ts +0 -3
- package/modern/renderer/renderEditCurrency.js +0 -78
- package/modern/renderer/renderEditIncoterm.d.ts +0 -3
- package/modern/renderer/renderEditIncoterm.js +0 -75
- package/modern/renderer/renderEditProgress.d.ts +0 -3
- package/modern/renderer/renderEditProgress.js +0 -109
- package/modern/renderer/renderEditRating.d.ts +0 -3
- package/modern/renderer/renderEditRating.js +0 -68
- package/modern/renderer/renderEditStatus.d.ts +0 -3
- package/modern/renderer/renderEditStatus.js +0 -98
- package/modern/renderer/renderEmail.d.ts +0 -3
- package/modern/renderer/renderEmail.js +0 -11
- package/modern/renderer/renderIncoterm.d.ts +0 -3
- package/modern/renderer/renderIncoterm.js +0 -40
- package/modern/renderer/renderLink.d.ts +0 -10
- package/modern/renderer/renderLink.js +0 -31
- package/modern/renderer/renderPnl.d.ts +0 -3
- package/modern/renderer/renderPnl.js +0 -41
- package/modern/renderer/renderProgress.d.ts +0 -3
- package/modern/renderer/renderProgress.js +0 -70
- package/modern/renderer/renderRating.d.ts +0 -3
- package/modern/renderer/renderRating.js +0 -38
- package/modern/renderer/renderStatus.d.ts +0 -3
- package/modern/renderer/renderStatus.js +0 -74
- package/modern/renderer/renderTotalPrice.d.ts +0 -3
- package/modern/renderer/renderTotalPrice.js +0 -49
- package/modern/services/asyncWorker.d.ts +0 -11
- package/modern/services/asyncWorker.js +0 -27
- package/modern/services/basic-data-service.d.ts +0 -13
- package/modern/services/basic-data-service.js +0 -37
- package/modern/services/gridColDefGenerator.d.ts +0 -23
- package/modern/services/gridColDefGenerator.js +0 -1
- package/modern/services/index.d.ts +0 -5
- package/modern/services/index.js +0 -5
- package/modern/services/prompt-resolver.d.ts +0 -2
- package/modern/services/prompt-resolver.js +0 -13
- package/modern/services/random-generator.d.ts +0 -49
- package/modern/services/random-generator.js +0 -124
- package/modern/services/real-data-service.d.ts +0 -8
- package/modern/services/real-data-service.js +0 -49
- package/modern/services/static-data.d.ts +0 -18
- package/modern/services/static-data.js +0 -1258
- package/modern/services/tree-data-generator.d.ts +0 -21
- package/modern/services/tree-data-generator.js +0 -70
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -175,7 +175,7 @@ const getCommodityColumns = (editable = false) => [{
|
|
|
175
175
|
return value;
|
|
176
176
|
},
|
|
177
177
|
valueFormatter: value => value?.label,
|
|
178
|
-
groupingValueGetter: value => value
|
|
178
|
+
groupingValueGetter: value => value?.label,
|
|
179
179
|
sortComparator: (v1, v2, param1, param2) => (0, _xDataGridPremium.gridStringOrNumberComparator)(v1.label, v2.label, param1, param2),
|
|
180
180
|
editable,
|
|
181
181
|
width: 120
|
|
@@ -89,6 +89,7 @@ const getEmployeeColumns = () => [{
|
|
|
89
89
|
generateData: _services.randomCountry,
|
|
90
90
|
renderCell: _renderer.renderCountry,
|
|
91
91
|
renderEditCell: _renderer.renderEditCountry,
|
|
92
|
+
groupingValueGetter: value => value?.label,
|
|
92
93
|
sortComparator: (v1, v2, param1, param2) => (0, _xDataGridPremium.gridStringOrNumberComparator)(v1.label, v2.label, param1, param2),
|
|
93
94
|
width: 150,
|
|
94
95
|
editable: true
|
package/constants/prompts.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PromptResponse } from '@mui/x-data-grid-premium';
|
|
2
2
|
export declare const mockPrompts: Map<string, PromptResponse>;
|
package/constants/prompts.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.mockPrompts = void 0;
|
|
7
7
|
const mockPrompts = exports.mockPrompts = new Map([['sort by name', {
|
|
8
|
+
conversationId: 'mock',
|
|
8
9
|
select: -1,
|
|
9
10
|
filters: [],
|
|
10
11
|
aggregation: {},
|
|
@@ -13,8 +14,9 @@ const mockPrompts = exports.mockPrompts = new Map([['sort by name', {
|
|
|
13
14
|
direction: 'asc'
|
|
14
15
|
}],
|
|
15
16
|
grouping: [],
|
|
16
|
-
|
|
17
|
+
pivoting: {}
|
|
17
18
|
}], ['sort by company name and employee name', {
|
|
19
|
+
conversationId: 'mock',
|
|
18
20
|
select: -1,
|
|
19
21
|
filters: [],
|
|
20
22
|
aggregation: {},
|
|
@@ -26,8 +28,9 @@ const mockPrompts = exports.mockPrompts = new Map([['sort by name', {
|
|
|
26
28
|
direction: 'asc'
|
|
27
29
|
}],
|
|
28
30
|
grouping: [],
|
|
29
|
-
|
|
31
|
+
pivoting: {}
|
|
30
32
|
}], ['show people from the eu', {
|
|
33
|
+
conversationId: 'mock',
|
|
31
34
|
select: -1,
|
|
32
35
|
filters: [{
|
|
33
36
|
column: 'country',
|
|
@@ -37,8 +40,9 @@ const mockPrompts = exports.mockPrompts = new Map([['sort by name', {
|
|
|
37
40
|
aggregation: {},
|
|
38
41
|
sorting: [],
|
|
39
42
|
grouping: [],
|
|
40
|
-
|
|
43
|
+
pivoting: {}
|
|
41
44
|
}], ['order companies by amount of people', {
|
|
45
|
+
conversationId: 'mock',
|
|
42
46
|
select: -1,
|
|
43
47
|
filters: [],
|
|
44
48
|
aggregation: {
|
|
@@ -51,5 +55,5 @@ const mockPrompts = exports.mockPrompts = new Map([['sort by name', {
|
|
|
51
55
|
grouping: [{
|
|
52
56
|
column: 'company'
|
|
53
57
|
}],
|
|
54
|
-
|
|
58
|
+
pivoting: {}
|
|
55
59
|
}]]);
|
|
@@ -169,7 +169,7 @@ export const getCommodityColumns = (editable = false) => [{
|
|
|
169
169
|
return value;
|
|
170
170
|
},
|
|
171
171
|
valueFormatter: value => value?.label,
|
|
172
|
-
groupingValueGetter: value => value
|
|
172
|
+
groupingValueGetter: value => value?.label,
|
|
173
173
|
sortComparator: (v1, v2, param1, param2) => gridStringOrNumberComparator(v1.label, v2.label, param1, param2),
|
|
174
174
|
editable,
|
|
175
175
|
width: 120
|
|
@@ -83,6 +83,7 @@ export const getEmployeeColumns = () => [{
|
|
|
83
83
|
generateData: randomCountry,
|
|
84
84
|
renderCell: renderCountry,
|
|
85
85
|
renderEditCell: renderEditCountry,
|
|
86
|
+
groupingValueGetter: value => value?.label,
|
|
86
87
|
sortComparator: (v1, v2, param1, param2) => gridStringOrNumberComparator(v1.label, v2.label, param1, param2),
|
|
87
88
|
width: 150,
|
|
88
89
|
editable: true
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PromptResponse } from '@mui/x-data-grid-premium';
|
|
2
2
|
export declare const mockPrompts: Map<string, PromptResponse>;
|
package/esm/constants/prompts.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const mockPrompts = new Map([['sort by name', {
|
|
2
|
+
conversationId: 'mock',
|
|
2
3
|
select: -1,
|
|
3
4
|
filters: [],
|
|
4
5
|
aggregation: {},
|
|
@@ -7,8 +8,9 @@ export const mockPrompts = new Map([['sort by name', {
|
|
|
7
8
|
direction: 'asc'
|
|
8
9
|
}],
|
|
9
10
|
grouping: [],
|
|
10
|
-
|
|
11
|
+
pivoting: {}
|
|
11
12
|
}], ['sort by company name and employee name', {
|
|
13
|
+
conversationId: 'mock',
|
|
12
14
|
select: -1,
|
|
13
15
|
filters: [],
|
|
14
16
|
aggregation: {},
|
|
@@ -20,8 +22,9 @@ export const mockPrompts = new Map([['sort by name', {
|
|
|
20
22
|
direction: 'asc'
|
|
21
23
|
}],
|
|
22
24
|
grouping: [],
|
|
23
|
-
|
|
25
|
+
pivoting: {}
|
|
24
26
|
}], ['show people from the eu', {
|
|
27
|
+
conversationId: 'mock',
|
|
25
28
|
select: -1,
|
|
26
29
|
filters: [{
|
|
27
30
|
column: 'country',
|
|
@@ -31,8 +34,9 @@ export const mockPrompts = new Map([['sort by name', {
|
|
|
31
34
|
aggregation: {},
|
|
32
35
|
sorting: [],
|
|
33
36
|
grouping: [],
|
|
34
|
-
|
|
37
|
+
pivoting: {}
|
|
35
38
|
}], ['order companies by amount of people', {
|
|
39
|
+
conversationId: 'mock',
|
|
36
40
|
select: -1,
|
|
37
41
|
filters: [],
|
|
38
42
|
aggregation: {
|
|
@@ -45,5 +49,5 @@ export const mockPrompts = new Map([['sort by name', {
|
|
|
45
49
|
grouping: [{
|
|
46
50
|
column: 'company'
|
|
47
51
|
}],
|
|
48
|
-
|
|
52
|
+
pivoting: {}
|
|
49
53
|
}]]);
|
package/esm/hooks/serverUtils.js
CHANGED
|
@@ -21,16 +21,16 @@ const apiRef = {};
|
|
|
21
21
|
const simplifiedValueGetter = (field, colDef) => row => {
|
|
22
22
|
return colDef.valueGetter?.(row[row.id], row, colDef, apiRef) || row[field];
|
|
23
23
|
};
|
|
24
|
-
const getRowComparator = (sortModel, columnsWithDefaultColDef) => {
|
|
24
|
+
const getRowComparator = (sortModel, aggregationModel, columnsWithDefaultColDef) => {
|
|
25
25
|
if (!sortModel) {
|
|
26
26
|
const comparator = () => 0;
|
|
27
27
|
return comparator;
|
|
28
28
|
}
|
|
29
29
|
const sortOperators = sortModel.map(sortItem => {
|
|
30
|
-
const columnField = sortItem.field;
|
|
30
|
+
const columnField = aggregationModel?.[sortItem.field] ? `${sortItem.field}Aggregate` : sortItem.field;
|
|
31
31
|
const colDef = columnsWithDefaultColDef.find(({
|
|
32
32
|
field
|
|
33
|
-
}) => field ===
|
|
33
|
+
}) => field === sortItem.field);
|
|
34
34
|
return _extends({}, sortItem, {
|
|
35
35
|
valueGetter: simplifiedValueGetter(columnField, colDef),
|
|
36
36
|
sortComparator: colDef.sortComparator
|
|
@@ -220,7 +220,7 @@ export const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDef
|
|
|
220
220
|
let firstRowIndex;
|
|
221
221
|
let lastRowIndex;
|
|
222
222
|
let filteredRows = getFilteredRows(rows, queryOptions.filterModel, columnsWithDefaultColDef);
|
|
223
|
-
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
223
|
+
const rowComparator = getRowComparator(queryOptions.sortModel, queryOptions.aggregationModel, columnsWithDefaultColDef);
|
|
224
224
|
filteredRows = [...filteredRows].sort(rowComparator);
|
|
225
225
|
let aggregateRow = {};
|
|
226
226
|
if (queryOptions.aggregationModel) {
|
|
@@ -374,7 +374,7 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
|
|
|
374
374
|
});
|
|
375
375
|
if (queryOptions.sortModel) {
|
|
376
376
|
// apply sorting
|
|
377
|
-
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
377
|
+
const rowComparator = getRowComparator(queryOptions.sortModel, queryOptions.aggregationModel, columnsWithDefaultColDef);
|
|
378
378
|
childRowsWithDescendantCounts = [...childRowsWithDescendantCounts].sort(rowComparator);
|
|
379
379
|
}
|
|
380
380
|
let aggregateRow;
|
|
@@ -429,7 +429,15 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
|
|
|
429
429
|
const groupFields = queryOptions.groupFields;
|
|
430
430
|
if (groupFields.length > 0) {
|
|
431
431
|
rowsWithPaths = rows.reduce((acc, row) => {
|
|
432
|
-
const partialPath = groupFields.map(field =>
|
|
432
|
+
const partialPath = groupFields.map(field => {
|
|
433
|
+
const colDef = columnsWithDefaultColDef.find(({
|
|
434
|
+
field: f
|
|
435
|
+
}) => f === field);
|
|
436
|
+
if (colDef?.groupingValueGetter) {
|
|
437
|
+
return colDef.groupingValueGetter(row[field], row, colDef, apiRef);
|
|
438
|
+
}
|
|
439
|
+
return String(row[field]);
|
|
440
|
+
});
|
|
433
441
|
for (let index = 0; index < partialPath.length; index += 1) {
|
|
434
442
|
const value = partialPath[index];
|
|
435
443
|
if (value === undefined) {
|
|
@@ -496,7 +504,7 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
|
|
|
496
504
|
});
|
|
497
505
|
});
|
|
498
506
|
if (queryOptions.sortModel) {
|
|
499
|
-
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
507
|
+
const rowComparator = getRowComparator(queryOptions.sortModel, queryOptions.aggregationModel, columnsWithDefaultColDef);
|
|
500
508
|
const sortedMissingGroups = [...filteredRowsWithMissingGroups].sort(rowComparator);
|
|
501
509
|
const sortedChildRows = [...childRowsWithDescendantCounts].sort(rowComparator);
|
|
502
510
|
childRowsWithDescendantCounts = [...sortedMissingGroups, ...sortedChildRows];
|
package/esm/hooks/useDemoData.js
CHANGED
|
@@ -61,8 +61,8 @@ export const deepFreeze = object => {
|
|
|
61
61
|
export const getColumnsFromOptions = options => {
|
|
62
62
|
let columns = options.dataSet === 'Commodity' ? getCommodityColumns(options.editable) : getEmployeeColumns();
|
|
63
63
|
if (options.visibleFields) {
|
|
64
|
-
columns = columns.map(col =>
|
|
65
|
-
hide:
|
|
64
|
+
columns = columns.map(col => _extends({}, col, {
|
|
65
|
+
hide: !options.visibleFields?.includes(col.field)
|
|
66
66
|
}));
|
|
67
67
|
}
|
|
68
68
|
if (options.maxColumns) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type GridRowModel, type GridColDef, type GridInitialState } from '@mui/x-data-grid-premium';
|
|
1
|
+
import { type GridGetRowsResponse, type GridRowId, type GridRowModel, type GridColDef, type GridInitialState } from '@mui/x-data-grid-premium';
|
|
3
2
|
import { AddPathToDemoDataOptions } from "../services/tree-data-generator.js";
|
|
4
3
|
import type { ServerOptions } from './serverUtils';
|
|
5
4
|
export declare const BASE_URL = "https://mui.com/x/api/data-grid";
|
|
@@ -9,6 +8,7 @@ type UseMockServerResponse<T> = {
|
|
|
9
8
|
getGroupKey?: (row: GridRowModel) => string;
|
|
10
9
|
getChildrenCount?: (row: GridRowModel) => number;
|
|
11
10
|
fetchRows: (url: string) => Promise<T>;
|
|
11
|
+
editRow: (rowId: GridRowId, updatedRow: GridRowModel) => Promise<GridRowModel>;
|
|
12
12
|
loadNewData: () => void;
|
|
13
13
|
isReady: boolean;
|
|
14
14
|
};
|
|
@@ -38,8 +38,8 @@ const getColumnsFromOptions = options => {
|
|
|
38
38
|
throw new Error('Unknown dataset');
|
|
39
39
|
}
|
|
40
40
|
if (options.visibleFields) {
|
|
41
|
-
columns = columns.map(col =>
|
|
42
|
-
hide:
|
|
41
|
+
columns = columns.map(col => _extends({}, col, {
|
|
42
|
+
hide: !options.visibleFields?.includes(col.field)
|
|
43
43
|
}));
|
|
44
44
|
}
|
|
45
45
|
if (options.maxColumns) {
|
|
@@ -86,7 +86,8 @@ function sendEmptyResponse() {
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail) => {
|
|
89
|
-
const
|
|
89
|
+
const dataRef = React.useRef(null);
|
|
90
|
+
const [isDataReady, setDataReady] = React.useState(false);
|
|
90
91
|
const [index, setIndex] = React.useState(0);
|
|
91
92
|
const shouldRequestsFailRef = React.useRef(shouldRequestsFail ?? false);
|
|
92
93
|
React.useEffect(() => {
|
|
@@ -127,7 +128,8 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
127
128
|
// of the demos.
|
|
128
129
|
if (dataCache.has(cacheKey)) {
|
|
129
130
|
const newData = dataCache.get(cacheKey);
|
|
130
|
-
|
|
131
|
+
dataRef.current = newData;
|
|
132
|
+
setDataReady(true);
|
|
131
133
|
return undefined;
|
|
132
134
|
}
|
|
133
135
|
if (options.dataSet === 'Movies') {
|
|
@@ -135,7 +137,8 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
135
137
|
rows: getMovieRows(),
|
|
136
138
|
columns
|
|
137
139
|
};
|
|
138
|
-
|
|
140
|
+
dataRef.current = rowsData;
|
|
141
|
+
setDataReady(true);
|
|
139
142
|
dataCache.set(cacheKey, rowsData);
|
|
140
143
|
return undefined;
|
|
141
144
|
}
|
|
@@ -163,14 +166,15 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
163
166
|
deepFreeze(rowData);
|
|
164
167
|
}
|
|
165
168
|
dataCache.set(cacheKey, rowData);
|
|
166
|
-
|
|
169
|
+
dataRef.current = rowData;
|
|
170
|
+
setDataReady(true);
|
|
167
171
|
})();
|
|
168
172
|
return () => {
|
|
169
173
|
active = false;
|
|
170
174
|
};
|
|
171
175
|
}, [columns, isTreeData, options.rowLength, options.treeData?.maxDepth, options.treeData?.groupingField, options.treeData?.averageChildren, options.dataSet, options.maxColumns, index]);
|
|
172
176
|
const fetchRows = React.useCallback(async requestUrl => {
|
|
173
|
-
if (!requestUrl || !
|
|
177
|
+
if (!requestUrl || !isDataReady) {
|
|
174
178
|
return sendEmptyResponse();
|
|
175
179
|
}
|
|
176
180
|
const params = decodeParams(requestUrl);
|
|
@@ -204,7 +208,7 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
204
208
|
rows,
|
|
205
209
|
rootRowCount,
|
|
206
210
|
aggregateRow
|
|
207
|
-
} = await processTreeDataRows(
|
|
211
|
+
} = await processTreeDataRows(dataRef.current?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
208
212
|
getRowsResponse = _extends({
|
|
209
213
|
rows: rows.slice().map(row => _extends({}, row, {
|
|
210
214
|
path: undefined
|
|
@@ -218,7 +222,7 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
218
222
|
rows,
|
|
219
223
|
rootRowCount,
|
|
220
224
|
aggregateRow
|
|
221
|
-
} = await processRowGroupingRows(
|
|
225
|
+
} = await processRowGroupingRows(dataRef.current?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
222
226
|
getRowsResponse = _extends({
|
|
223
227
|
rows: rows.slice().map(row => _extends({}, row, {
|
|
224
228
|
path: undefined
|
|
@@ -233,7 +237,7 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
233
237
|
nextCursor,
|
|
234
238
|
totalRowCount,
|
|
235
239
|
aggregateRow
|
|
236
|
-
} = await loadServerRows(
|
|
240
|
+
} = await loadServerRows(dataRef.current?.rows ?? [], _extends({}, params, params.paginationModel), serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
237
241
|
getRowsResponse = _extends({
|
|
238
242
|
rows: returnedRows,
|
|
239
243
|
rowCount: totalRowCount,
|
|
@@ -250,16 +254,64 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
|
|
|
250
254
|
}
|
|
251
255
|
resolve(getRowsResponse);
|
|
252
256
|
});
|
|
253
|
-
}, [
|
|
257
|
+
}, [dataRef, isDataReady, serverOptions?.verbose, serverOptions?.minDelay, serverOptions?.maxDelay, serverOptions?.useCursorPagination, isTreeData, columnsWithDefaultColDef, isRowGrouping]);
|
|
258
|
+
const editRow = React.useCallback(async (rowId, updatedRow) => {
|
|
259
|
+
return new Promise((resolve, reject) => {
|
|
260
|
+
const minDelay = serverOptions?.minDelay ?? DEFAULT_SERVER_OPTIONS.minDelay;
|
|
261
|
+
const maxDelay = serverOptions?.maxDelay ?? DEFAULT_SERVER_OPTIONS.maxDelay;
|
|
262
|
+
const delay = randomInt(minDelay, maxDelay);
|
|
263
|
+
const verbose = serverOptions?.verbose ?? true;
|
|
264
|
+
// eslint-disable-next-line no-console
|
|
265
|
+
const print = console.info;
|
|
266
|
+
if (verbose) {
|
|
267
|
+
print('MUI X: DATASOURCE EDIT ROW REQUEST', {
|
|
268
|
+
rowId,
|
|
269
|
+
updatedRow
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (shouldRequestsFailRef.current) {
|
|
273
|
+
setTimeout(() => reject(new Error(`Could not update the row with the id ${rowId}`)), delay);
|
|
274
|
+
if (verbose) {
|
|
275
|
+
print('MUI X: DATASOURCE EDIT ROW FAILURE', {
|
|
276
|
+
rowId,
|
|
277
|
+
updatedRow
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const newRows = [...(dataRef.current?.rows || [])];
|
|
283
|
+
const rowIndex = newRows.findIndex(row => row.id === rowId) ?? -1;
|
|
284
|
+
if (rowIndex === -1) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
newRows[rowIndex] = updatedRow;
|
|
288
|
+
const newData = _extends({}, dataRef.current, {
|
|
289
|
+
rows: newRows
|
|
290
|
+
});
|
|
291
|
+
const cacheKey = `${options.dataSet}-${options.rowLength}-${index}-${options.maxColumns}`;
|
|
292
|
+
dataCache.set(cacheKey, newData);
|
|
293
|
+
setTimeout(() => {
|
|
294
|
+
if (verbose) {
|
|
295
|
+
print('MUI X: DATASOURCE EDIT ROW SUCCESS', {
|
|
296
|
+
rowId,
|
|
297
|
+
updatedRow
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
resolve(updatedRow);
|
|
301
|
+
}, delay);
|
|
302
|
+
dataRef.current = newData;
|
|
303
|
+
});
|
|
304
|
+
}, [index, options.dataSet, options.maxColumns, options.rowLength, serverOptions?.maxDelay, serverOptions?.minDelay, serverOptions?.verbose]);
|
|
254
305
|
return {
|
|
255
306
|
columns: columnsWithDefaultColDef,
|
|
256
307
|
initialState: options.dataSet === 'Movies' ? {} : initialState,
|
|
257
308
|
getGroupKey,
|
|
258
309
|
getChildrenCount,
|
|
259
310
|
fetchRows,
|
|
311
|
+
editRow,
|
|
260
312
|
loadNewData: () => {
|
|
261
313
|
setIndex(oldIndex => oldIndex + 1);
|
|
262
314
|
},
|
|
263
|
-
isReady:
|
|
315
|
+
isReady: isDataReady
|
|
264
316
|
};
|
|
265
317
|
};
|
package/esm/hooks/useQuery.d.ts
CHANGED
|
@@ -44,12 +44,13 @@ export declare const createFakeServer: (dataSetOptions?: Partial<UseDemoDataOpti
|
|
|
44
44
|
disableReorder?: boolean;
|
|
45
45
|
disableExport?: boolean;
|
|
46
46
|
colSpan?: number | import("@mui/x-data-grid").GridColSpanFn<any, any, any> | undefined;
|
|
47
|
-
|
|
47
|
+
examples?: any[] | undefined;
|
|
48
48
|
renderHeaderFilter?: (params: import("@mui/x-data-grid-pro").GridRenderHeaderFilterProps) => React.ReactNode;
|
|
49
49
|
aggregable?: boolean;
|
|
50
50
|
availableAggregationFunctions?: string[];
|
|
51
51
|
groupingValueGetter?: import("@mui/x-data-grid-premium").GridGroupingValueGetter<any> | undefined;
|
|
52
52
|
pastedValueParser?: import("@mui/x-data-grid-premium").GridPastedValueParser<any, any, any> | undefined;
|
|
53
|
+
pivotable?: boolean;
|
|
53
54
|
generateData?: (row: any, context: import("..").GridDataGeneratorContext) => any;
|
|
54
55
|
dataGeneratorUniquenessEnabled?: boolean;
|
|
55
56
|
hide?: boolean;
|
|
@@ -94,12 +95,13 @@ export declare const createFakeServer: (dataSetOptions?: Partial<UseDemoDataOpti
|
|
|
94
95
|
disableReorder?: boolean;
|
|
95
96
|
disableExport?: boolean;
|
|
96
97
|
colSpan?: number | import("@mui/x-data-grid").GridColSpanFn<any, any, any> | undefined;
|
|
97
|
-
|
|
98
|
+
examples?: any[] | undefined;
|
|
98
99
|
renderHeaderFilter?: (params: import("@mui/x-data-grid-pro").GridRenderHeaderFilterProps) => React.ReactNode;
|
|
99
100
|
aggregable?: boolean;
|
|
100
101
|
availableAggregationFunctions?: string[];
|
|
101
102
|
groupingValueGetter?: import("@mui/x-data-grid-premium").GridGroupingValueGetter<any> | undefined;
|
|
102
103
|
pastedValueParser?: import("@mui/x-data-grid-premium").GridPastedValueParser<any, any, any> | undefined;
|
|
104
|
+
pivotable?: boolean;
|
|
103
105
|
generateData?: (row: any, context: import("..").GridDataGeneratorContext) => any;
|
|
104
106
|
dataGeneratorUniquenessEnabled?: boolean;
|
|
105
107
|
hide?: boolean;
|
|
@@ -146,12 +148,13 @@ export declare const createFakeServer: (dataSetOptions?: Partial<UseDemoDataOpti
|
|
|
146
148
|
disableReorder?: boolean;
|
|
147
149
|
disableExport?: boolean;
|
|
148
150
|
colSpan?: number | import("@mui/x-data-grid").GridColSpanFn<any, any, any> | undefined;
|
|
149
|
-
|
|
151
|
+
examples?: any[] | undefined;
|
|
150
152
|
renderHeaderFilter?: (params: import("@mui/x-data-grid-pro").GridRenderHeaderFilterProps) => React.ReactNode;
|
|
151
153
|
aggregable?: boolean;
|
|
152
154
|
availableAggregationFunctions?: string[];
|
|
153
155
|
groupingValueGetter?: import("@mui/x-data-grid-premium").GridGroupingValueGetter<any> | undefined;
|
|
154
156
|
pastedValueParser?: import("@mui/x-data-grid-premium").GridPastedValueParser<any, any, any> | undefined;
|
|
157
|
+
pivotable?: boolean;
|
|
155
158
|
generateData?: (row: any, context: import("..").GridDataGeneratorContext) => any;
|
|
156
159
|
dataGeneratorUniquenessEnabled?: boolean;
|
|
157
160
|
hide?: boolean;
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { GridRenderCellParams } from '@mui/x-data-grid-premium';
|
|
3
2
|
import { CountryIsoOption } from "../services/static-data.js";
|
|
4
|
-
export declare function renderCountry(params: GridRenderCellParams<CountryIsoOption, any, any>):
|
|
3
|
+
export declare function renderCountry(params: GridRenderCellParams<CountryIsoOption, any, any>): any;
|
|
@@ -51,6 +51,9 @@ export function renderCountry(params) {
|
|
|
51
51
|
if (params.aggregation && !params.aggregation.hasCellUnit) {
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
+
if (params.rowNode.type === 'group') {
|
|
55
|
+
return params.value;
|
|
56
|
+
}
|
|
54
57
|
return /*#__PURE__*/_jsx(Country, {
|
|
55
58
|
value: params.value
|
|
56
59
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const mockPromptResolver: (
|
|
1
|
+
import { PromptResponse } from '@mui/x-data-grid-premium';
|
|
2
|
+
export declare const mockPromptResolver: (query: string, _: string) => Promise<PromptResponse>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { mockPrompts } from "../constants/prompts.js";
|
|
2
|
-
export const mockPromptResolver = (
|
|
2
|
+
export const mockPromptResolver = (query, _) => {
|
|
3
3
|
const resolved = mockPrompts.get(query.toLowerCase().trim());
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
5
|
setTimeout(() => {
|
|
6
6
|
if (resolved) {
|
|
7
7
|
resolve(resolved);
|
|
8
8
|
} else {
|
|
9
|
-
|
|
9
|
+
console.error(`Unsupported query: ${query}`);
|
|
10
|
+
reject(new Error('Could not process prompt'));
|
|
10
11
|
}
|
|
11
12
|
}, 1000);
|
|
12
13
|
});
|
package/hooks/serverUtils.js
CHANGED
|
@@ -28,16 +28,16 @@ const apiRef = {};
|
|
|
28
28
|
const simplifiedValueGetter = (field, colDef) => row => {
|
|
29
29
|
return colDef.valueGetter?.(row[row.id], row, colDef, apiRef) || row[field];
|
|
30
30
|
};
|
|
31
|
-
const getRowComparator = (sortModel, columnsWithDefaultColDef) => {
|
|
31
|
+
const getRowComparator = (sortModel, aggregationModel, columnsWithDefaultColDef) => {
|
|
32
32
|
if (!sortModel) {
|
|
33
33
|
const comparator = () => 0;
|
|
34
34
|
return comparator;
|
|
35
35
|
}
|
|
36
36
|
const sortOperators = sortModel.map(sortItem => {
|
|
37
|
-
const columnField = sortItem.field;
|
|
37
|
+
const columnField = aggregationModel?.[sortItem.field] ? `${sortItem.field}Aggregate` : sortItem.field;
|
|
38
38
|
const colDef = columnsWithDefaultColDef.find(({
|
|
39
39
|
field
|
|
40
|
-
}) => field ===
|
|
40
|
+
}) => field === sortItem.field);
|
|
41
41
|
return (0, _extends2.default)({}, sortItem, {
|
|
42
42
|
valueGetter: simplifiedValueGetter(columnField, colDef),
|
|
43
43
|
sortComparator: colDef.sortComparator
|
|
@@ -227,7 +227,7 @@ const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDefaultCol
|
|
|
227
227
|
let firstRowIndex;
|
|
228
228
|
let lastRowIndex;
|
|
229
229
|
let filteredRows = getFilteredRows(rows, queryOptions.filterModel, columnsWithDefaultColDef);
|
|
230
|
-
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
230
|
+
const rowComparator = getRowComparator(queryOptions.sortModel, queryOptions.aggregationModel, columnsWithDefaultColDef);
|
|
231
231
|
filteredRows = [...filteredRows].sort(rowComparator);
|
|
232
232
|
let aggregateRow = {};
|
|
233
233
|
if (queryOptions.aggregationModel) {
|
|
@@ -382,7 +382,7 @@ const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWithDefau
|
|
|
382
382
|
});
|
|
383
383
|
if (queryOptions.sortModel) {
|
|
384
384
|
// apply sorting
|
|
385
|
-
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
385
|
+
const rowComparator = getRowComparator(queryOptions.sortModel, queryOptions.aggregationModel, columnsWithDefaultColDef);
|
|
386
386
|
childRowsWithDescendantCounts = [...childRowsWithDescendantCounts].sort(rowComparator);
|
|
387
387
|
}
|
|
388
388
|
let aggregateRow;
|
|
@@ -438,7 +438,15 @@ const processRowGroupingRows = (rows, queryOptions, serverOptions, columnsWithDe
|
|
|
438
438
|
const groupFields = queryOptions.groupFields;
|
|
439
439
|
if (groupFields.length > 0) {
|
|
440
440
|
rowsWithPaths = rows.reduce((acc, row) => {
|
|
441
|
-
const partialPath = groupFields.map(field =>
|
|
441
|
+
const partialPath = groupFields.map(field => {
|
|
442
|
+
const colDef = columnsWithDefaultColDef.find(({
|
|
443
|
+
field: f
|
|
444
|
+
}) => f === field);
|
|
445
|
+
if (colDef?.groupingValueGetter) {
|
|
446
|
+
return colDef.groupingValueGetter(row[field], row, colDef, apiRef);
|
|
447
|
+
}
|
|
448
|
+
return String(row[field]);
|
|
449
|
+
});
|
|
442
450
|
for (let index = 0; index < partialPath.length; index += 1) {
|
|
443
451
|
const value = partialPath[index];
|
|
444
452
|
if (value === undefined) {
|
|
@@ -505,7 +513,7 @@ const processRowGroupingRows = (rows, queryOptions, serverOptions, columnsWithDe
|
|
|
505
513
|
});
|
|
506
514
|
});
|
|
507
515
|
if (queryOptions.sortModel) {
|
|
508
|
-
const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
|
|
516
|
+
const rowComparator = getRowComparator(queryOptions.sortModel, queryOptions.aggregationModel, columnsWithDefaultColDef);
|
|
509
517
|
const sortedMissingGroups = [...filteredRowsWithMissingGroups].sort(rowComparator);
|
|
510
518
|
const sortedChildRows = [...childRowsWithDescendantCounts].sort(rowComparator);
|
|
511
519
|
childRowsWithDescendantCounts = [...sortedMissingGroups, ...sortedChildRows];
|
package/hooks/useDemoData.js
CHANGED
|
@@ -71,8 +71,8 @@ exports.deepFreeze = deepFreeze;
|
|
|
71
71
|
const getColumnsFromOptions = options => {
|
|
72
72
|
let columns = options.dataSet === 'Commodity' ? (0, _commodities.getCommodityColumns)(options.editable) : (0, _employees.getEmployeeColumns)();
|
|
73
73
|
if (options.visibleFields) {
|
|
74
|
-
columns = columns.map(col =>
|
|
75
|
-
hide:
|
|
74
|
+
columns = columns.map(col => (0, _extends2.default)({}, col, {
|
|
75
|
+
hide: !options.visibleFields?.includes(col.field)
|
|
76
76
|
}));
|
|
77
77
|
}
|
|
78
78
|
if (options.maxColumns) {
|
package/hooks/useMockServer.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type GridRowModel, type GridColDef, type GridInitialState } from '@mui/x-data-grid-premium';
|
|
1
|
+
import { type GridGetRowsResponse, type GridRowId, type GridRowModel, type GridColDef, type GridInitialState } from '@mui/x-data-grid-premium';
|
|
3
2
|
import { AddPathToDemoDataOptions } from "../services/tree-data-generator.js";
|
|
4
3
|
import type { ServerOptions } from './serverUtils';
|
|
5
4
|
export declare const BASE_URL = "https://mui.com/x/api/data-grid";
|
|
@@ -9,6 +8,7 @@ type UseMockServerResponse<T> = {
|
|
|
9
8
|
getGroupKey?: (row: GridRowModel) => string;
|
|
10
9
|
getChildrenCount?: (row: GridRowModel) => number;
|
|
11
10
|
fetchRows: (url: string) => Promise<T>;
|
|
11
|
+
editRow: (rowId: GridRowId, updatedRow: GridRowModel) => Promise<GridRowModel>;
|
|
12
12
|
loadNewData: () => void;
|
|
13
13
|
isReady: boolean;
|
|
14
14
|
};
|