@etsoo/materialui 1.4.37 → 1.4.39
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/lib/DataGridEx.js +4 -2
- package/lib/GridUtils.d.ts +1 -9
- package/lib/GridUtils.js +0 -22
- package/lib/MUUtils.d.ts +9 -0
- package/lib/MUUtils.js +23 -0
- package/lib/TableEx.js +3 -2
- package/package.json +3 -3
- package/src/DataGridEx.tsx +6 -2
- package/src/GridUtils.ts +0 -29
- package/src/MUUtils.ts +31 -0
- package/src/TableEx.tsx +5 -2
package/lib/DataGridEx.js
CHANGED
|
@@ -91,7 +91,7 @@ export function DataGridEx(props) {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
else if (sortable && field != null) {
|
|
94
|
-
const active = orderBy?.
|
|
94
|
+
const active = orderBy?.some((o) => o.field.toUpperCase() === field.toUpperCase());
|
|
95
95
|
sortLabel = (_jsx(TableSortLabel, { active: active, direction: sortAsc ? "asc" : "desc", onClick: (_event) => {
|
|
96
96
|
if (active)
|
|
97
97
|
column.sortAsc = !sortAsc;
|
|
@@ -165,7 +165,9 @@ export function DataGridEx(props) {
|
|
|
165
165
|
});
|
|
166
166
|
// New sort
|
|
167
167
|
const handleSort = (field, asc) => {
|
|
168
|
-
reset({
|
|
168
|
+
reset({
|
|
169
|
+
queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] }
|
|
170
|
+
});
|
|
169
171
|
};
|
|
170
172
|
// Reset
|
|
171
173
|
const reset = (add) => {
|
package/lib/GridUtils.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GridLoadDataProps, GridLoaderStates } from "@etsoo/react";
|
|
2
2
|
import { DataTypes } from "@etsoo/shared";
|
|
3
3
|
import { GridDataCacheType } from "./GridDataCacheType";
|
|
4
|
-
import { QueryPagingData } from "@etsoo/appscript";
|
|
5
4
|
/**
|
|
6
5
|
* Grid utilities
|
|
7
6
|
*/
|
|
@@ -14,7 +13,7 @@ export declare namespace GridUtils {
|
|
|
14
13
|
* @returns Request data
|
|
15
14
|
*/
|
|
16
15
|
function createLoader<F extends DataTypes.BasicTemplate>(props: GridLoadDataProps, template?: F, cacheKey?: string): DataTypes.BasicTemplateType<F> & {
|
|
17
|
-
queryPaging: QueryPagingData;
|
|
16
|
+
queryPaging: import("@etsoo/appscript").QueryPagingData;
|
|
18
17
|
};
|
|
19
18
|
/**
|
|
20
19
|
* Get cache data
|
|
@@ -41,11 +40,4 @@ export declare namespace GridUtils {
|
|
|
41
40
|
* @param searchData Search data
|
|
42
41
|
*/
|
|
43
42
|
function mergeSearchData<T, F extends DataTypes.BasicTemplate>(state: GridLoaderStates<T>, searchData?: DataTypes.BasicTemplateType<F>): void;
|
|
44
|
-
/**
|
|
45
|
-
* Setup paging keysets
|
|
46
|
-
* @param data Paging data
|
|
47
|
-
* @param lastItem Last item of the query
|
|
48
|
-
* @param idField Id field
|
|
49
|
-
*/
|
|
50
|
-
function setupPagingKeysets<T>(data: QueryPagingData, lastItem: T | undefined, idField: keyof T & string): void;
|
|
51
43
|
}
|
package/lib/GridUtils.js
CHANGED
|
@@ -83,26 +83,4 @@ export var GridUtils;
|
|
|
83
83
|
Object.assign(state.data, searchData);
|
|
84
84
|
}
|
|
85
85
|
GridUtils.mergeSearchData = mergeSearchData;
|
|
86
|
-
/**
|
|
87
|
-
* Setup paging keysets
|
|
88
|
-
* @param data Paging data
|
|
89
|
-
* @param lastItem Last item of the query
|
|
90
|
-
* @param idField Id field
|
|
91
|
-
*/
|
|
92
|
-
function setupPagingKeysets(data, lastItem, idField) {
|
|
93
|
-
// If the id field is not set for ordering, add it with descending
|
|
94
|
-
if (data.orderBy == null) {
|
|
95
|
-
data.orderBy = new Map([[idField, true]]);
|
|
96
|
-
}
|
|
97
|
-
else if (!data.orderBy.has(idField)) {
|
|
98
|
-
data.orderBy.set(idField, true);
|
|
99
|
-
}
|
|
100
|
-
// Set the paging keysets
|
|
101
|
-
if (lastItem) {
|
|
102
|
-
const keysets = [];
|
|
103
|
-
data.orderBy.forEach((_value, key) => keysets.push(Reflect.get(lastItem, key)));
|
|
104
|
-
data.keysets = keysets;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
GridUtils.setupPagingKeysets = setupPagingKeysets;
|
|
108
86
|
})(GridUtils || (GridUtils = {}));
|
package/lib/MUUtils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { QueryRQ } from "@etsoo/appscript";
|
|
2
|
+
import { IdType } from "@etsoo/shared";
|
|
1
3
|
import { GridApiCommunity } from "@mui/x-data-grid/models/api/gridApiCommunity";
|
|
2
4
|
/**
|
|
3
5
|
* MU utilities
|
|
@@ -10,4 +12,11 @@ export declare namespace MUUtils {
|
|
|
10
12
|
* @returns Results
|
|
11
13
|
*/
|
|
12
14
|
function getGridData<T>(grid: GridApiCommunity, checkField: keyof T | ((item: T) => boolean)): T[];
|
|
15
|
+
/**
|
|
16
|
+
* Setup paging keysets
|
|
17
|
+
* @param data Paging data
|
|
18
|
+
* @param lastItem Last item of the query
|
|
19
|
+
* @param idField Id field
|
|
20
|
+
*/
|
|
21
|
+
function setupPagingKeysets<T, K extends IdType = number>(data: QueryRQ<K>, lastItem: T | undefined, idField: keyof T & string): QueryRQ<K>;
|
|
13
22
|
}
|
package/lib/MUUtils.js
CHANGED
|
@@ -26,4 +26,27 @@ export var MUUtils;
|
|
|
26
26
|
return items;
|
|
27
27
|
}
|
|
28
28
|
MUUtils.getGridData = getGridData;
|
|
29
|
+
/**
|
|
30
|
+
* Setup paging keysets
|
|
31
|
+
* @param data Paging data
|
|
32
|
+
* @param lastItem Last item of the query
|
|
33
|
+
* @param idField Id field
|
|
34
|
+
*/
|
|
35
|
+
function setupPagingKeysets(data, lastItem, idField) {
|
|
36
|
+
// If the id field is not set for ordering, add it with descending
|
|
37
|
+
if (typeof data.queryPaging === "object") {
|
|
38
|
+
const orderBy = (data.queryPaging.orderBy ??= []);
|
|
39
|
+
const idUpper = idField.toUpperCase();
|
|
40
|
+
if (!orderBy.find((o) => o.field.toUpperCase() === idUpper)) {
|
|
41
|
+
orderBy.push({ field: idField, desc: true, unique: true });
|
|
42
|
+
}
|
|
43
|
+
// Set the paging keysets
|
|
44
|
+
if (lastItem) {
|
|
45
|
+
const keysets = orderBy.map((o) => Reflect.get(lastItem, o.field));
|
|
46
|
+
data.queryPaging.keysets = keysets;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
MUUtils.setupPagingKeysets = setupPagingKeysets;
|
|
29
52
|
})(MUUtils || (MUUtils = {}));
|
package/lib/TableEx.js
CHANGED
|
@@ -63,6 +63,7 @@ export function TableEx(props) {
|
|
|
63
63
|
hasNextPage: true,
|
|
64
64
|
isNextPageLoading: false,
|
|
65
65
|
lastLoadedItems: undefined,
|
|
66
|
+
lastItem: undefined,
|
|
66
67
|
...rest
|
|
67
68
|
};
|
|
68
69
|
Object.assign(state, resetState);
|
|
@@ -171,7 +172,7 @@ export function TableEx(props) {
|
|
|
171
172
|
};
|
|
172
173
|
// New sort
|
|
173
174
|
const handleSort = (field, asc) => {
|
|
174
|
-
reset({ queryPaging: { orderBy:
|
|
175
|
+
reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
|
|
175
176
|
};
|
|
176
177
|
// Set items for rerenderer
|
|
177
178
|
const setItems = (callback) => {
|
|
@@ -218,7 +219,7 @@ export function TableEx(props) {
|
|
|
218
219
|
// Sortable
|
|
219
220
|
let sortLabel;
|
|
220
221
|
if (sortable && field != null) {
|
|
221
|
-
const active = queryPaging.orderBy?.
|
|
222
|
+
const active = queryPaging.orderBy?.some((o) => o.field.toLowerCase() === field.toLowerCase());
|
|
222
223
|
sortLabel = (_jsx(TableSortLabel, { active: active, direction: sortAsc ? "asc" : "desc", onClick: (_event) => {
|
|
223
224
|
if (active)
|
|
224
225
|
column.sortAsc = !sortAsc;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.39",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@emotion/css": "^11.13.5",
|
|
36
36
|
"@emotion/react": "^11.13.5",
|
|
37
37
|
"@emotion/styled": "^11.13.5",
|
|
38
|
-
"@etsoo/appscript": "^1.5.
|
|
38
|
+
"@etsoo/appscript": "^1.5.78",
|
|
39
39
|
"@etsoo/notificationbase": "^1.1.54",
|
|
40
|
-
"@etsoo/react": "^1.8.
|
|
40
|
+
"@etsoo/react": "^1.8.8",
|
|
41
41
|
"@etsoo/shared": "^1.2.55",
|
|
42
42
|
"@mui/icons-material": "^6.1.9",
|
|
43
43
|
"@mui/material": "^6.1.9",
|
package/src/DataGridEx.tsx
CHANGED
|
@@ -258,7 +258,9 @@ export function DataGridEx<T extends object>(props: DataGridExProps<T>) {
|
|
|
258
258
|
states
|
|
259
259
|
});
|
|
260
260
|
} else if (sortable && field != null) {
|
|
261
|
-
const active = orderBy?.
|
|
261
|
+
const active = orderBy?.some(
|
|
262
|
+
(o) => o.field.toUpperCase() === field.toUpperCase()
|
|
263
|
+
);
|
|
262
264
|
|
|
263
265
|
sortLabel = (
|
|
264
266
|
<TableSortLabel
|
|
@@ -438,7 +440,9 @@ export function DataGridEx<T extends object>(props: DataGridExProps<T>) {
|
|
|
438
440
|
|
|
439
441
|
// New sort
|
|
440
442
|
const handleSort = (field: string, asc?: boolean) => {
|
|
441
|
-
reset({
|
|
443
|
+
reset({
|
|
444
|
+
queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] }
|
|
445
|
+
});
|
|
442
446
|
};
|
|
443
447
|
|
|
444
448
|
// Reset
|
package/src/GridUtils.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
} from "@etsoo/react";
|
|
6
6
|
import { DataTypes } from "@etsoo/shared";
|
|
7
7
|
import { GridDataCacheType } from "./GridDataCacheType";
|
|
8
|
-
import { QueryPagingData } from "@etsoo/appscript";
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Grid utilities
|
|
@@ -99,32 +98,4 @@ export namespace GridUtils {
|
|
|
99
98
|
state.data ??= {};
|
|
100
99
|
Object.assign(state.data, searchData);
|
|
101
100
|
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Setup paging keysets
|
|
105
|
-
* @param data Paging data
|
|
106
|
-
* @param lastItem Last item of the query
|
|
107
|
-
* @param idField Id field
|
|
108
|
-
*/
|
|
109
|
-
export function setupPagingKeysets<T>(
|
|
110
|
-
data: QueryPagingData,
|
|
111
|
-
lastItem: T | undefined,
|
|
112
|
-
idField: keyof T & string
|
|
113
|
-
) {
|
|
114
|
-
// If the id field is not set for ordering, add it with descending
|
|
115
|
-
if (data.orderBy == null) {
|
|
116
|
-
data.orderBy = new Map<string, boolean>([[idField, true]]);
|
|
117
|
-
} else if (!data.orderBy.has(idField)) {
|
|
118
|
-
data.orderBy.set(idField, true);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Set the paging keysets
|
|
122
|
-
if (lastItem) {
|
|
123
|
-
const keysets: unknown[] = [];
|
|
124
|
-
data.orderBy.forEach((_value, key) =>
|
|
125
|
-
keysets.push(Reflect.get(lastItem, key))
|
|
126
|
-
);
|
|
127
|
-
data.keysets = keysets;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
101
|
}
|
package/src/MUUtils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { QueryRQ } from "@etsoo/appscript";
|
|
2
|
+
import { IdType } from "@etsoo/shared";
|
|
1
3
|
import { GridApiCommunity } from "@mui/x-data-grid/models/api/gridApiCommunity";
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -31,4 +33,33 @@ export namespace MUUtils {
|
|
|
31
33
|
}
|
|
32
34
|
return items;
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Setup paging keysets
|
|
39
|
+
* @param data Paging data
|
|
40
|
+
* @param lastItem Last item of the query
|
|
41
|
+
* @param idField Id field
|
|
42
|
+
*/
|
|
43
|
+
export function setupPagingKeysets<T, K extends IdType = number>(
|
|
44
|
+
data: QueryRQ<K>,
|
|
45
|
+
lastItem: T | undefined,
|
|
46
|
+
idField: keyof T & string
|
|
47
|
+
) {
|
|
48
|
+
// If the id field is not set for ordering, add it with descending
|
|
49
|
+
if (typeof data.queryPaging === "object") {
|
|
50
|
+
const orderBy = (data.queryPaging.orderBy ??= []);
|
|
51
|
+
const idUpper = idField.toUpperCase();
|
|
52
|
+
if (!orderBy.find((o) => o.field.toUpperCase() === idUpper)) {
|
|
53
|
+
orderBy.push({ field: idField, desc: true, unique: true });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Set the paging keysets
|
|
57
|
+
if (lastItem) {
|
|
58
|
+
const keysets = orderBy.map((o) => Reflect.get(lastItem, o.field));
|
|
59
|
+
data.queryPaging.keysets = keysets;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
34
65
|
}
|
package/src/TableEx.tsx
CHANGED
|
@@ -174,6 +174,7 @@ export function TableEx<
|
|
|
174
174
|
hasNextPage: true,
|
|
175
175
|
isNextPageLoading: false,
|
|
176
176
|
lastLoadedItems: undefined,
|
|
177
|
+
lastItem: undefined,
|
|
177
178
|
...rest
|
|
178
179
|
};
|
|
179
180
|
Object.assign(state, resetState);
|
|
@@ -306,7 +307,7 @@ export function TableEx<
|
|
|
306
307
|
|
|
307
308
|
// New sort
|
|
308
309
|
const handleSort = (field: string, asc?: boolean) => {
|
|
309
|
-
reset({ queryPaging: { orderBy:
|
|
310
|
+
reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
|
|
310
311
|
};
|
|
311
312
|
|
|
312
313
|
// Set items for rerenderer
|
|
@@ -400,7 +401,9 @@ export function TableEx<
|
|
|
400
401
|
// Sortable
|
|
401
402
|
let sortLabel: React.ReactNode;
|
|
402
403
|
if (sortable && field != null) {
|
|
403
|
-
const active = queryPaging.orderBy?.
|
|
404
|
+
const active = queryPaging.orderBy?.some(
|
|
405
|
+
(o) => o.field.toLowerCase() === field.toLowerCase()
|
|
406
|
+
);
|
|
404
407
|
|
|
405
408
|
sortLabel = (
|
|
406
409
|
<TableSortLabel
|