@mui/x-data-grid-generator 8.0.0-beta.2 → 8.0.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 +423 -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 +9 -18
- 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
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { GridColumnVisibilityModel } from '@mui/x-data-grid-premium';
|
|
2
|
-
import { GridDemoData } from "../services/real-data-service.js";
|
|
3
|
-
import { GridColDefGenerator } from "../services/gridColDefGenerator.js";
|
|
4
|
-
import { AddPathToDemoDataOptions, DemoTreeDataValue } from "../services/tree-data-generator.js";
|
|
5
|
-
export type DemoDataReturnType = {
|
|
6
|
-
data: DemoTreeDataValue;
|
|
7
|
-
loading: boolean;
|
|
8
|
-
setRowLength: (count: number) => void;
|
|
9
|
-
loadNewData: () => void;
|
|
10
|
-
};
|
|
11
|
-
type DataSet = 'Commodity' | 'Employee';
|
|
12
|
-
export interface UseDemoDataOptions {
|
|
13
|
-
dataSet: DataSet;
|
|
14
|
-
rowLength: number;
|
|
15
|
-
maxColumns?: number;
|
|
16
|
-
visibleFields?: string[];
|
|
17
|
-
editable?: boolean;
|
|
18
|
-
treeData?: AddPathToDemoDataOptions;
|
|
19
|
-
}
|
|
20
|
-
export declare function extrapolateSeed(rowLength: number, data: GridDemoData): Promise<GridDemoData>;
|
|
21
|
-
export declare const deepFreeze: <T>(object: T) => T;
|
|
22
|
-
export interface ColumnsOptions extends Pick<UseDemoDataOptions, 'dataSet' | 'editable' | 'maxColumns' | 'visibleFields'> {}
|
|
23
|
-
export declare const getColumnsFromOptions: (options: ColumnsOptions) => GridColDefGenerator[];
|
|
24
|
-
export declare const getInitialState: (options: UseDemoDataOptions, columns: GridColDefGenerator[]) => {
|
|
25
|
-
columns: {
|
|
26
|
-
columnVisibilityModel: GridColumnVisibilityModel;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export declare const useDemoData: (options: UseDemoDataOptions) => DemoDataReturnType;
|
|
30
|
-
export {};
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { LRUCache } from 'lru-cache';
|
|
6
|
-
import { getRealGridData } from "../services/real-data-service.js";
|
|
7
|
-
import { getCommodityColumns } from "../columns/commodities.columns.js";
|
|
8
|
-
import { getEmployeeColumns } from "../columns/employees.columns.js";
|
|
9
|
-
import asyncWorker from "../services/asyncWorker.js";
|
|
10
|
-
import { addTreeDataOptionsToDemoData } from "../services/tree-data-generator.js";
|
|
11
|
-
const dataCache = new LRUCache({
|
|
12
|
-
max: 10,
|
|
13
|
-
ttl: 60 * 5 * 1e3 // 5 minutes
|
|
14
|
-
});
|
|
15
|
-
// Generate fake data from a seed.
|
|
16
|
-
// It's about x20 faster than getRealData.
|
|
17
|
-
export async function extrapolateSeed(rowLength, data) {
|
|
18
|
-
return new Promise(resolve => {
|
|
19
|
-
const seed = data.rows;
|
|
20
|
-
const rows = data.rows.slice();
|
|
21
|
-
const tasks = {
|
|
22
|
-
current: rowLength - seed.length
|
|
23
|
-
};
|
|
24
|
-
function work() {
|
|
25
|
-
const row = {};
|
|
26
|
-
for (let j = 0; j < data.columns.length; j += 1) {
|
|
27
|
-
const column = data.columns[j];
|
|
28
|
-
const index = Math.round(Math.random() * (seed.length - 1));
|
|
29
|
-
if (column.field === 'id') {
|
|
30
|
-
row.id = `id-${tasks.current + seed.length}`;
|
|
31
|
-
} else {
|
|
32
|
-
row[column.field] = seed[index][column.field];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
rows.push(row);
|
|
36
|
-
tasks.current -= 1;
|
|
37
|
-
}
|
|
38
|
-
asyncWorker({
|
|
39
|
-
work,
|
|
40
|
-
done: () => resolve(_extends({}, data, {
|
|
41
|
-
rows
|
|
42
|
-
})),
|
|
43
|
-
tasks
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
export const deepFreeze = object => {
|
|
48
|
-
// Retrieve the property names defined on object
|
|
49
|
-
const propNames = Object.getOwnPropertyNames(object);
|
|
50
|
-
|
|
51
|
-
// Freeze properties before freezing self
|
|
52
|
-
|
|
53
|
-
for (const name of propNames) {
|
|
54
|
-
const value = object[name];
|
|
55
|
-
if (value && typeof value === 'object') {
|
|
56
|
-
deepFreeze(value);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return Object.freeze(object);
|
|
60
|
-
};
|
|
61
|
-
export const getColumnsFromOptions = options => {
|
|
62
|
-
let columns = options.dataSet === 'Commodity' ? getCommodityColumns(options.editable) : getEmployeeColumns();
|
|
63
|
-
if (options.visibleFields) {
|
|
64
|
-
columns = columns.map(col => options.visibleFields?.includes(col.field) ? col : _extends({}, col, {
|
|
65
|
-
hide: true
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
if (options.maxColumns) {
|
|
69
|
-
columns = columns.slice(0, options.maxColumns);
|
|
70
|
-
}
|
|
71
|
-
return columns;
|
|
72
|
-
};
|
|
73
|
-
export const getInitialState = (options, columns) => {
|
|
74
|
-
const columnVisibilityModel = {};
|
|
75
|
-
columns.forEach(col => {
|
|
76
|
-
if (col.hide) {
|
|
77
|
-
columnVisibilityModel[col.field] = false;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
const groupingField = options.treeData?.groupingField;
|
|
81
|
-
if (groupingField) {
|
|
82
|
-
columnVisibilityModel[groupingField] = false;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
columns: {
|
|
86
|
-
columnVisibilityModel
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
export const useDemoData = options => {
|
|
91
|
-
const [rowLength, setRowLength] = React.useState(options.rowLength);
|
|
92
|
-
const [index, setIndex] = React.useState(0);
|
|
93
|
-
const [loading, setLoading] = React.useState(true);
|
|
94
|
-
const columns = React.useMemo(() => {
|
|
95
|
-
return getColumnsFromOptions({
|
|
96
|
-
dataSet: options.dataSet,
|
|
97
|
-
editable: options.editable,
|
|
98
|
-
maxColumns: options.maxColumns,
|
|
99
|
-
visibleFields: options.visibleFields
|
|
100
|
-
});
|
|
101
|
-
}, [options.dataSet, options.editable, options.maxColumns, options.visibleFields]);
|
|
102
|
-
const [data, setData] = React.useState(() => {
|
|
103
|
-
return addTreeDataOptionsToDemoData({
|
|
104
|
-
columns,
|
|
105
|
-
rows: [],
|
|
106
|
-
initialState: getInitialState(options, columns)
|
|
107
|
-
}, options.treeData);
|
|
108
|
-
});
|
|
109
|
-
React.useEffect(() => {
|
|
110
|
-
const cacheKey = `${options.dataSet}-${rowLength}-${index}-${options.maxColumns}`;
|
|
111
|
-
|
|
112
|
-
// Cache to allow fast switch between the JavaScript and TypeScript version
|
|
113
|
-
// of the demos.
|
|
114
|
-
if (dataCache.has(cacheKey)) {
|
|
115
|
-
const newData = dataCache.get(cacheKey);
|
|
116
|
-
setData(newData);
|
|
117
|
-
setLoading(false);
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
let active = true;
|
|
121
|
-
(async () => {
|
|
122
|
-
setLoading(true);
|
|
123
|
-
let newData;
|
|
124
|
-
if (rowLength > 1000) {
|
|
125
|
-
newData = await getRealGridData(1000, columns);
|
|
126
|
-
newData = await extrapolateSeed(rowLength, newData);
|
|
127
|
-
} else {
|
|
128
|
-
newData = await getRealGridData(rowLength, columns);
|
|
129
|
-
}
|
|
130
|
-
if (!active) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
newData = addTreeDataOptionsToDemoData(newData, {
|
|
134
|
-
maxDepth: options.treeData?.maxDepth,
|
|
135
|
-
groupingField: options.treeData?.groupingField,
|
|
136
|
-
averageChildren: options.treeData?.averageChildren
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// It's quite slow. No need for it in production.
|
|
140
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
141
|
-
deepFreeze(newData);
|
|
142
|
-
}
|
|
143
|
-
dataCache.set(cacheKey, newData);
|
|
144
|
-
setData(newData);
|
|
145
|
-
setLoading(false);
|
|
146
|
-
})();
|
|
147
|
-
return () => {
|
|
148
|
-
active = false;
|
|
149
|
-
};
|
|
150
|
-
}, [rowLength, options.dataSet, options.maxColumns, options.treeData?.maxDepth, options.treeData?.groupingField, options.treeData?.averageChildren, index, columns]);
|
|
151
|
-
return {
|
|
152
|
-
data,
|
|
153
|
-
loading,
|
|
154
|
-
setRowLength,
|
|
155
|
-
loadNewData: () => {
|
|
156
|
-
setIndex(oldIndex => oldIndex + 1);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { GridGetRowsResponse } from '@mui/x-data-grid';
|
|
2
|
-
import { type GridRowModel, type GridColDef, type GridInitialState } from '@mui/x-data-grid-premium';
|
|
3
|
-
import { AddPathToDemoDataOptions } from "../services/tree-data-generator.js";
|
|
4
|
-
import type { ServerOptions } from './serverUtils';
|
|
5
|
-
export declare const BASE_URL = "https://mui.com/x/api/data-grid";
|
|
6
|
-
type UseMockServerResponse<T> = {
|
|
7
|
-
columns: GridColDef[];
|
|
8
|
-
initialState: GridInitialState;
|
|
9
|
-
getGroupKey?: (row: GridRowModel) => string;
|
|
10
|
-
getChildrenCount?: (row: GridRowModel) => number;
|
|
11
|
-
fetchRows: (url: string) => Promise<T>;
|
|
12
|
-
loadNewData: () => void;
|
|
13
|
-
isReady: boolean;
|
|
14
|
-
};
|
|
15
|
-
type DataSet = 'Commodity' | 'Employee' | 'Movies';
|
|
16
|
-
interface UseMockServerOptions {
|
|
17
|
-
dataSet: DataSet;
|
|
18
|
-
/**
|
|
19
|
-
* Has no effect when DataSet='Movies'
|
|
20
|
-
*/
|
|
21
|
-
rowLength: number;
|
|
22
|
-
maxColumns?: number;
|
|
23
|
-
visibleFields?: string[];
|
|
24
|
-
editable?: boolean;
|
|
25
|
-
treeData?: AddPathToDemoDataOptions;
|
|
26
|
-
rowGrouping?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export declare const useMockServer: <T extends GridGetRowsResponse>(dataSetOptions?: Partial<UseMockServerOptions>, serverOptions?: ServerOptions & {
|
|
29
|
-
verbose?: boolean;
|
|
30
|
-
}, shouldRequestsFail?: boolean) => UseMockServerResponse<T>;
|
|
31
|
-
export {};
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { LRUCache } from 'lru-cache';
|
|
6
|
-
import { getGridDefaultColumnTypes } from '@mui/x-data-grid-premium';
|
|
7
|
-
import { extrapolateSeed, deepFreeze } from "./useDemoData.js";
|
|
8
|
-
import { getCommodityColumns } from "../columns/commodities.columns.js";
|
|
9
|
-
import { getEmployeeColumns } from "../columns/employees.columns.js";
|
|
10
|
-
import { getRealGridData } from "../services/real-data-service.js";
|
|
11
|
-
import { addTreeDataOptionsToDemoData } from "../services/tree-data-generator.js";
|
|
12
|
-
import { loadServerRows, processTreeDataRows, processRowGroupingRows, DEFAULT_SERVER_OPTIONS } from "./serverUtils.js";
|
|
13
|
-
import { randomInt } from "../services/index.js";
|
|
14
|
-
import { getMovieRows, getMovieColumns } from "./useMovieData.js";
|
|
15
|
-
const dataCache = new LRUCache({
|
|
16
|
-
max: 10,
|
|
17
|
-
ttl: 60 * 5 * 1e3 // 5 minutes
|
|
18
|
-
});
|
|
19
|
-
export const BASE_URL = 'https://mui.com/x/api/data-grid';
|
|
20
|
-
const GET_DEFAULT_DATASET_OPTIONS = isRowGrouping => ({
|
|
21
|
-
dataSet: isRowGrouping ? 'Movies' : 'Commodity',
|
|
22
|
-
rowLength: isRowGrouping ? getMovieRows().length : 100,
|
|
23
|
-
maxColumns: 6
|
|
24
|
-
});
|
|
25
|
-
const getColumnsFromOptions = options => {
|
|
26
|
-
let columns;
|
|
27
|
-
switch (options.dataSet) {
|
|
28
|
-
case 'Commodity':
|
|
29
|
-
columns = getCommodityColumns(options.editable);
|
|
30
|
-
break;
|
|
31
|
-
case 'Employee':
|
|
32
|
-
columns = getEmployeeColumns();
|
|
33
|
-
break;
|
|
34
|
-
case 'Movies':
|
|
35
|
-
columns = getMovieColumns();
|
|
36
|
-
break;
|
|
37
|
-
default:
|
|
38
|
-
throw new Error('Unknown dataset');
|
|
39
|
-
}
|
|
40
|
-
if (options.visibleFields) {
|
|
41
|
-
columns = columns.map(col => options.visibleFields?.includes(col.field) ? col : _extends({}, col, {
|
|
42
|
-
hide: true
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
if (options.maxColumns) {
|
|
46
|
-
columns = columns.slice(0, options.maxColumns);
|
|
47
|
-
}
|
|
48
|
-
return columns;
|
|
49
|
-
};
|
|
50
|
-
function decodeParams(url) {
|
|
51
|
-
const params = new URL(url).searchParams;
|
|
52
|
-
const decodedParams = {};
|
|
53
|
-
const array = Array.from(params.entries());
|
|
54
|
-
for (const [key, value] of array) {
|
|
55
|
-
try {
|
|
56
|
-
decodedParams[key] = JSON.parse(value);
|
|
57
|
-
} catch {
|
|
58
|
-
decodedParams[key] = value;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return decodedParams;
|
|
62
|
-
}
|
|
63
|
-
const getInitialState = (columns, groupingField) => {
|
|
64
|
-
const columnVisibilityModel = {};
|
|
65
|
-
columns.forEach(col => {
|
|
66
|
-
if (col.hide) {
|
|
67
|
-
columnVisibilityModel[col.field] = false;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
if (groupingField) {
|
|
71
|
-
columnVisibilityModel[groupingField] = false;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
columns: {
|
|
75
|
-
columnVisibilityModel
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
const defaultColDef = getGridDefaultColumnTypes();
|
|
80
|
-
function sendEmptyResponse() {
|
|
81
|
-
return new Promise(resolve => {
|
|
82
|
-
resolve({
|
|
83
|
-
rows: [],
|
|
84
|
-
rowCount: 0
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail) => {
|
|
89
|
-
const [data, setData] = React.useState();
|
|
90
|
-
const [index, setIndex] = React.useState(0);
|
|
91
|
-
const shouldRequestsFailRef = React.useRef(shouldRequestsFail ?? false);
|
|
92
|
-
React.useEffect(() => {
|
|
93
|
-
if (shouldRequestsFail !== undefined) {
|
|
94
|
-
shouldRequestsFailRef.current = shouldRequestsFail;
|
|
95
|
-
}
|
|
96
|
-
}, [shouldRequestsFail]);
|
|
97
|
-
const isRowGrouping = dataSetOptions?.rowGrouping ?? false;
|
|
98
|
-
const options = _extends({}, GET_DEFAULT_DATASET_OPTIONS(isRowGrouping), dataSetOptions);
|
|
99
|
-
const isTreeData = options.treeData?.groupingField != null;
|
|
100
|
-
const columns = React.useMemo(() => {
|
|
101
|
-
return getColumnsFromOptions({
|
|
102
|
-
dataSet: options.dataSet,
|
|
103
|
-
editable: options.editable,
|
|
104
|
-
maxColumns: options.maxColumns,
|
|
105
|
-
visibleFields: options.visibleFields
|
|
106
|
-
});
|
|
107
|
-
}, [options.dataSet, options.editable, options.maxColumns, options.visibleFields]);
|
|
108
|
-
const initialState = React.useMemo(() => getInitialState(columns, options.treeData?.groupingField), [columns, options.treeData?.groupingField]);
|
|
109
|
-
const columnsWithDefaultColDef = React.useMemo(() => columns.map(column => _extends({}, defaultColDef[column.type || 'string'], column)), [columns]);
|
|
110
|
-
const getGroupKey = React.useMemo(() => {
|
|
111
|
-
if (isTreeData) {
|
|
112
|
-
return row => row[options.treeData.groupingField];
|
|
113
|
-
}
|
|
114
|
-
return undefined;
|
|
115
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
|
-
}, [options.treeData?.groupingField, isTreeData]);
|
|
117
|
-
const getChildrenCount = React.useMemo(() => {
|
|
118
|
-
if (isTreeData) {
|
|
119
|
-
return row => row.descendantCount;
|
|
120
|
-
}
|
|
121
|
-
return undefined;
|
|
122
|
-
}, [isTreeData]);
|
|
123
|
-
React.useEffect(() => {
|
|
124
|
-
const cacheKey = `${options.dataSet}-${options.rowLength}-${index}-${options.maxColumns}`;
|
|
125
|
-
|
|
126
|
-
// Cache to allow fast switch between the JavaScript and TypeScript version
|
|
127
|
-
// of the demos.
|
|
128
|
-
if (dataCache.has(cacheKey)) {
|
|
129
|
-
const newData = dataCache.get(cacheKey);
|
|
130
|
-
setData(newData);
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
if (options.dataSet === 'Movies') {
|
|
134
|
-
const rowsData = {
|
|
135
|
-
rows: getMovieRows(),
|
|
136
|
-
columns
|
|
137
|
-
};
|
|
138
|
-
setData(rowsData);
|
|
139
|
-
dataCache.set(cacheKey, rowsData);
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
let active = true;
|
|
143
|
-
(async () => {
|
|
144
|
-
let rowData;
|
|
145
|
-
const rowLength = options.rowLength;
|
|
146
|
-
if (rowLength > 1000) {
|
|
147
|
-
rowData = await getRealGridData(1000, columns);
|
|
148
|
-
rowData = await extrapolateSeed(rowLength, rowData);
|
|
149
|
-
} else {
|
|
150
|
-
rowData = await getRealGridData(rowLength, columns);
|
|
151
|
-
}
|
|
152
|
-
if (!active) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (isTreeData) {
|
|
156
|
-
rowData = addTreeDataOptionsToDemoData(rowData, {
|
|
157
|
-
maxDepth: options.treeData?.maxDepth,
|
|
158
|
-
groupingField: options.treeData?.groupingField,
|
|
159
|
-
averageChildren: options.treeData?.averageChildren
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
163
|
-
deepFreeze(rowData);
|
|
164
|
-
}
|
|
165
|
-
dataCache.set(cacheKey, rowData);
|
|
166
|
-
setData(rowData);
|
|
167
|
-
})();
|
|
168
|
-
return () => {
|
|
169
|
-
active = false;
|
|
170
|
-
};
|
|
171
|
-
}, [columns, isTreeData, options.rowLength, options.treeData?.maxDepth, options.treeData?.groupingField, options.treeData?.averageChildren, options.dataSet, options.maxColumns, index]);
|
|
172
|
-
const fetchRows = React.useCallback(async requestUrl => {
|
|
173
|
-
if (!requestUrl || !data?.rows) {
|
|
174
|
-
return sendEmptyResponse();
|
|
175
|
-
}
|
|
176
|
-
const params = decodeParams(requestUrl);
|
|
177
|
-
const verbose = serverOptions?.verbose ?? true;
|
|
178
|
-
// eslint-disable-next-line no-console
|
|
179
|
-
const print = console.info;
|
|
180
|
-
if (verbose) {
|
|
181
|
-
print('MUI X: DATASOURCE REQUEST', params);
|
|
182
|
-
}
|
|
183
|
-
let getRowsResponse;
|
|
184
|
-
const serverOptionsWithDefault = {
|
|
185
|
-
minDelay: serverOptions?.minDelay ?? DEFAULT_SERVER_OPTIONS.minDelay,
|
|
186
|
-
maxDelay: serverOptions?.maxDelay ?? DEFAULT_SERVER_OPTIONS.maxDelay,
|
|
187
|
-
useCursorPagination: serverOptions?.useCursorPagination ?? DEFAULT_SERVER_OPTIONS.useCursorPagination
|
|
188
|
-
};
|
|
189
|
-
if (shouldRequestsFailRef.current) {
|
|
190
|
-
const {
|
|
191
|
-
minDelay,
|
|
192
|
-
maxDelay
|
|
193
|
-
} = serverOptionsWithDefault;
|
|
194
|
-
const delay = randomInt(minDelay, maxDelay);
|
|
195
|
-
return new Promise((_, reject) => {
|
|
196
|
-
if (verbose) {
|
|
197
|
-
print('MUI X: DATASOURCE REQUEST FAILURE', params);
|
|
198
|
-
}
|
|
199
|
-
setTimeout(() => reject(new Error('Could not fetch the data')), delay);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
if (isTreeData) {
|
|
203
|
-
const {
|
|
204
|
-
rows,
|
|
205
|
-
rootRowCount,
|
|
206
|
-
aggregateRow
|
|
207
|
-
} = await processTreeDataRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
208
|
-
getRowsResponse = _extends({
|
|
209
|
-
rows: rows.slice().map(row => _extends({}, row, {
|
|
210
|
-
path: undefined
|
|
211
|
-
})),
|
|
212
|
-
rowCount: rootRowCount
|
|
213
|
-
}, aggregateRow ? {
|
|
214
|
-
aggregateRow
|
|
215
|
-
} : {});
|
|
216
|
-
} else if (isRowGrouping) {
|
|
217
|
-
const {
|
|
218
|
-
rows,
|
|
219
|
-
rootRowCount,
|
|
220
|
-
aggregateRow
|
|
221
|
-
} = await processRowGroupingRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
222
|
-
getRowsResponse = _extends({
|
|
223
|
-
rows: rows.slice().map(row => _extends({}, row, {
|
|
224
|
-
path: undefined
|
|
225
|
-
})),
|
|
226
|
-
rowCount: rootRowCount
|
|
227
|
-
}, aggregateRow ? {
|
|
228
|
-
aggregateRow
|
|
229
|
-
} : {});
|
|
230
|
-
} else {
|
|
231
|
-
const {
|
|
232
|
-
returnedRows,
|
|
233
|
-
nextCursor,
|
|
234
|
-
totalRowCount,
|
|
235
|
-
aggregateRow
|
|
236
|
-
} = await loadServerRows(data?.rows ?? [], _extends({}, params, params.paginationModel), serverOptionsWithDefault, columnsWithDefaultColDef);
|
|
237
|
-
getRowsResponse = _extends({
|
|
238
|
-
rows: returnedRows,
|
|
239
|
-
rowCount: totalRowCount,
|
|
240
|
-
pageInfo: {
|
|
241
|
-
nextCursor
|
|
242
|
-
}
|
|
243
|
-
}, aggregateRow ? {
|
|
244
|
-
aggregateRow
|
|
245
|
-
} : {});
|
|
246
|
-
}
|
|
247
|
-
return new Promise(resolve => {
|
|
248
|
-
if (verbose) {
|
|
249
|
-
print('MUI X: DATASOURCE RESPONSE', params, getRowsResponse);
|
|
250
|
-
}
|
|
251
|
-
resolve(getRowsResponse);
|
|
252
|
-
});
|
|
253
|
-
}, [data, serverOptions?.verbose, serverOptions?.minDelay, serverOptions?.maxDelay, serverOptions?.useCursorPagination, isTreeData, columnsWithDefaultColDef, isRowGrouping]);
|
|
254
|
-
return {
|
|
255
|
-
columns: columnsWithDefaultColDef,
|
|
256
|
-
initialState: options.dataSet === 'Movies' ? {} : initialState,
|
|
257
|
-
getGroupKey,
|
|
258
|
-
getChildrenCount,
|
|
259
|
-
fetchRows,
|
|
260
|
-
loadNewData: () => {
|
|
261
|
-
setIndex(oldIndex => oldIndex + 1);
|
|
262
|
-
},
|
|
263
|
-
isReady: Boolean(data?.rows?.length)
|
|
264
|
-
};
|
|
265
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { GridColDef, GridRowModel } from '@mui/x-data-grid-premium';
|
|
2
|
-
export type Movie = {
|
|
3
|
-
id: number;
|
|
4
|
-
title: string;
|
|
5
|
-
gross: number;
|
|
6
|
-
budget: number;
|
|
7
|
-
director: string;
|
|
8
|
-
company: string;
|
|
9
|
-
year: number;
|
|
10
|
-
imdbRating: number;
|
|
11
|
-
composer: {
|
|
12
|
-
name: string;
|
|
13
|
-
};
|
|
14
|
-
cinematicUniverse?: string;
|
|
15
|
-
};
|
|
16
|
-
export declare const getMovieColumns: () => GridColDef[];
|
|
17
|
-
export declare const getMovieRows: () => GridRowModel<Movie>[];
|
|
18
|
-
export declare const useMovieData: () => {
|
|
19
|
-
rows: Movie[];
|
|
20
|
-
columns: GridColDef[];
|
|
21
|
-
};
|