@etsoo/materialui 1.4.36 → 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 != null && orderBy[field] != null;
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: { [field]: asc ?? true } } });
168
+ reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
169
169
  };
170
170
  // Reset
171
171
  const reset = (add) => {
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 = {}));
@@ -61,7 +61,7 @@ export type ResponsibleContainerProps<T extends object, F extends DataTypes.Basi
61
61
  /**
62
62
  * Load data callback
63
63
  */
64
- loadData: (data: GridJsonData & DataTypes.BasicTemplateType<F>) => PromiseLike<T[] | null | undefined>;
64
+ loadData: (data: GridJsonData & DataTypes.BasicTemplateType<F>, lastItem?: T) => PromiseLike<T[] | null | undefined>;
65
65
  /**
66
66
  * Methods
67
67
  */
@@ -44,9 +44,9 @@ export function ResponsibleContainer(props) {
44
44
  // Has fields
45
45
  const hasFields = fields != null && fields.length > 0;
46
46
  // Load data
47
- const localLoadData = (props) => {
47
+ const localLoadData = (props, lastItem) => {
48
48
  state.mounted = true;
49
- return loadData(GridUtils.createLoader(props, fieldTemplate, cacheKey));
49
+ return loadData(GridUtils.createLoader(props, fieldTemplate, cacheKey), lastItem);
50
50
  };
51
51
  // Search data
52
52
  const searchData = GridUtils.getSearchData(cacheKey);
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: { [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,8 +218,7 @@ export function TableEx(props) {
218
218
  // Sortable
219
219
  let sortLabel;
220
220
  if (sortable && field != null) {
221
- const active = queryPaging.orderBy != null &&
222
- queryPaging.orderBy[field] != null;
221
+ const active = queryPaging.orderBy?.some((o) => o.field.toLowerCase() === field.toLowerCase());
223
222
  sortLabel = (_jsx(TableSortLabel, { active: active, direction: sortAsc ? "asc" : "desc", onClick: (_event) => {
224
223
  if (active)
225
224
  column.sortAsc = !sortAsc;
@@ -33,8 +33,8 @@ export function DataGridPage(props) {
33
33
  const onSubmit = (data, _reset) => {
34
34
  setStates({ data });
35
35
  };
36
- const localLoadData = (props) => {
37
- return loadData(GridUtils.createLoader(props, fieldTemplate, cacheKey));
36
+ const localLoadData = (props, lastItem) => {
37
+ return loadData(GridUtils.createLoader(props, fieldTemplate, cacheKey), lastItem);
38
38
  };
39
39
  // Search data
40
40
  const searchData = GridUtils.getSearchData(cacheKey);
@@ -24,7 +24,7 @@ export type SearchPageProps<T extends object, F extends DataTypes.BasicTemplate>
24
24
  /**
25
25
  * Load data callback
26
26
  */
27
- loadData: (data: GridJsonData & DataTypes.BasicTemplateType<F>) => PromiseLike<T[] | null | undefined>;
27
+ loadData: (data: GridJsonData & DataTypes.BasicTemplateType<F>, lastItem?: T) => PromiseLike<T[] | null | undefined>;
28
28
  /**
29
29
  * Page props
30
30
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.4.36",
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.76",
38
+ "@etsoo/appscript": "^1.5.78",
39
39
  "@etsoo/notificationbase": "^1.1.54",
40
- "@etsoo/react": "^1.8.3",
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 != null && orderBy[field] != null;
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: { [field]: asc ?? true } } });
443
+ reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
442
444
  };
443
445
 
444
446
  // Reset
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
  }
@@ -123,7 +123,8 @@ export type ResponsibleContainerProps<
123
123
  * Load data callback
124
124
  */
125
125
  loadData: (
126
- data: GridJsonData & DataTypes.BasicTemplateType<F>
126
+ data: GridJsonData & DataTypes.BasicTemplateType<F>,
127
+ lastItem?: T
127
128
  ) => PromiseLike<T[] | null | undefined>;
128
129
 
129
130
  /**
@@ -238,9 +239,12 @@ export function ResponsibleContainer<
238
239
  const hasFields = fields != null && fields.length > 0;
239
240
 
240
241
  // Load data
241
- const localLoadData = (props: GridLoadDataProps) => {
242
+ const localLoadData = (props: GridLoadDataProps, lastItem?: T) => {
242
243
  state.mounted = true;
243
- return loadData(GridUtils.createLoader<F>(props, fieldTemplate, cacheKey));
244
+ return loadData(
245
+ GridUtils.createLoader<F>(props, fieldTemplate, cacheKey),
246
+ lastItem
247
+ );
244
248
  };
245
249
 
246
250
  // Search data
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: { [field]: asc ?? true } } });
309
+ reset({ queryPaging: { orderBy: [{ field, desc: !(asc ?? true) }] } });
310
310
  };
311
311
 
312
312
  // Set items for rerenderer
@@ -400,9 +400,9 @@ export function TableEx<
400
400
  // Sortable
401
401
  let sortLabel: React.ReactNode;
402
402
  if (sortable && field != null) {
403
- const active =
404
- queryPaging.orderBy != null &&
405
- queryPaging.orderBy[field] != null;
403
+ const active = queryPaging.orderBy?.some(
404
+ (o) => o.field.toLowerCase() === field.toLowerCase()
405
+ );
406
406
 
407
407
  sortLabel = (
408
408
  <TableSortLabel
@@ -76,8 +76,11 @@ export function DataGridPage<
76
76
  setStates({ data });
77
77
  };
78
78
 
79
- const localLoadData = (props: GridLoadDataProps) => {
80
- return loadData(GridUtils.createLoader<F>(props, fieldTemplate, cacheKey));
79
+ const localLoadData = (props: GridLoadDataProps, lastItem?: T) => {
80
+ return loadData(
81
+ GridUtils.createLoader<F>(props, fieldTemplate, cacheKey),
82
+ lastItem
83
+ );
81
84
  };
82
85
 
83
86
  // Search data
@@ -35,7 +35,8 @@ export type SearchPageProps<
35
35
  * Load data callback
36
36
  */
37
37
  loadData: (
38
- data: GridJsonData & DataTypes.BasicTemplateType<F>
38
+ data: GridJsonData & DataTypes.BasicTemplateType<F>,
39
+ lastItem?: T
39
40
  ) => PromiseLike<T[] | null | undefined>;
40
41
 
41
42
  /**