@etsoo/materialui 1.4.37 → 1.4.38

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 CHANGED
@@ -91,7 +91,7 @@ export function DataGridEx(props) {
91
91
  });
92
92
  }
93
93
  else if (sortable && field != null) {
94
- const active = orderBy?.has(field);
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,7 @@ export function DataGridEx(props) {
165
165
  });
166
166
  // New sort
167
167
  const handleSort = (field, asc) => {
168
- reset({ queryPaging: { orderBy: new Map([[field, !(asc ?? true)]]) } });
168
+ reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
169
169
  };
170
170
  // Reset
171
171
  const reset = (add) => {
@@ -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): void;
13
22
  }
package/lib/MUUtils.js CHANGED
@@ -26,4 +26,26 @@ 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
+ }
50
+ MUUtils.setupPagingKeysets = setupPagingKeysets;
29
51
  })(MUUtils || (MUUtils = {}));
package/lib/TableEx.js CHANGED
@@ -171,7 +171,7 @@ export function TableEx(props) {
171
171
  };
172
172
  // New sort
173
173
  const handleSort = (field, asc) => {
174
- reset({ queryPaging: { orderBy: new Map([[field, !(asc ?? true)]]) } });
174
+ reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
175
175
  };
176
176
  // Set items for rerenderer
177
177
  const setItems = (callback) => {
@@ -218,7 +218,7 @@ export function TableEx(props) {
218
218
  // Sortable
219
219
  let sortLabel;
220
220
  if (sortable && field != null) {
221
- const active = queryPaging.orderBy?.has(field);
221
+ const active = queryPaging.orderBy?.some((o) => o.field.toLowerCase() === field.toLowerCase());
222
222
  sortLabel = (_jsx(TableSortLabel, { active: active, direction: sortAsc ? "asc" : "desc", onClick: (_event) => {
223
223
  if (active)
224
224
  column.sortAsc = !sortAsc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.37",
3
+ "version": "1.4.38",
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.77",
38
+ "@etsoo/appscript": "^1.5.78",
39
39
  "@etsoo/notificationbase": "^1.1.54",
40
- "@etsoo/react": "^1.8.6",
40
+ "@etsoo/react": "^1.8.7",
41
41
  "@etsoo/shared": "^1.2.55",
42
42
  "@mui/icons-material": "^6.1.9",
43
43
  "@mui/material": "^6.1.9",
@@ -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?.has(field);
261
+ const active = orderBy?.some(
262
+ (o) => o.field.toUpperCase() === field.toUpperCase()
263
+ );
262
264
 
263
265
  sortLabel = (
264
266
  <TableSortLabel
@@ -438,7 +440,7 @@ 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({ queryPaging: { orderBy: new Map([[field, !(asc ?? true)]]) } });
443
+ reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
442
444
  };
443
445
 
444
446
  // 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,31 @@ 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
+ }
34
63
  }
package/src/TableEx.tsx CHANGED
@@ -306,7 +306,7 @@ export function TableEx<
306
306
 
307
307
  // New sort
308
308
  const handleSort = (field: string, asc?: boolean) => {
309
- reset({ queryPaging: { orderBy: new Map([[field, !(asc ?? true)]]) } });
309
+ reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
310
310
  };
311
311
 
312
312
  // Set items for rerenderer
@@ -400,7 +400,9 @@ export function TableEx<
400
400
  // Sortable
401
401
  let sortLabel: React.ReactNode;
402
402
  if (sortable && field != null) {
403
- const active = queryPaging.orderBy?.has(field);
403
+ const active = queryPaging.orderBy?.some(
404
+ (o) => o.field.toLowerCase() === field.toLowerCase()
405
+ );
404
406
 
405
407
  sortLabel = (
406
408
  <TableSortLabel