@etsoo/materialui 1.4.36 → 1.4.37

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?.has(field);
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: new Map([[field, !(asc ?? true)]]) } });
169
169
  };
170
170
  // Reset
171
171
  const reset = (add) => {
@@ -1,6 +1,7 @@
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";
4
5
  /**
5
6
  * Grid utilities
6
7
  */
@@ -13,7 +14,7 @@ export declare namespace GridUtils {
13
14
  * @returns Request data
14
15
  */
15
16
  function createLoader<F extends DataTypes.BasicTemplate>(props: GridLoadDataProps, template?: F, cacheKey?: string): DataTypes.BasicTemplateType<F> & {
16
- queryPaging: import("@etsoo/appscript").QueryPagingData;
17
+ queryPaging: QueryPagingData;
17
18
  };
18
19
  /**
19
20
  * Get cache data
@@ -40,4 +41,11 @@ export declare namespace GridUtils {
40
41
  * @param searchData Search data
41
42
  */
42
43
  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;
43
51
  }
package/lib/GridUtils.js CHANGED
@@ -83,4 +83,26 @@ 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;
86
108
  })(GridUtils || (GridUtils = {}));
@@ -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: new Map([[field, !(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?.has(field);
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.37",
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.77",
39
39
  "@etsoo/notificationbase": "^1.1.54",
40
- "@etsoo/react": "^1.8.3",
40
+ "@etsoo/react": "^1.8.6",
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,7 @@ 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?.has(field);
262
262
 
263
263
  sortLabel = (
264
264
  <TableSortLabel
@@ -438,7 +438,7 @@ export function DataGridEx<T extends object>(props: DataGridExProps<T>) {
438
438
 
439
439
  // New sort
440
440
  const handleSort = (field: string, asc?: boolean) => {
441
- reset({ queryPaging: { orderBy: { [field]: asc ?? true } } });
441
+ reset({ queryPaging: { orderBy: new Map([[field, !(asc ?? true)]]) } });
442
442
  };
443
443
 
444
444
  // Reset
package/src/GridUtils.ts CHANGED
@@ -5,6 +5,7 @@ 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";
8
9
 
9
10
  /**
10
11
  * Grid utilities
@@ -98,4 +99,32 @@ export namespace GridUtils {
98
99
  state.data ??= {};
99
100
  Object.assign(state.data, searchData);
100
101
  }
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
+ }
101
130
  }
@@ -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: new Map([[field, !(asc ?? true)]]) } });
310
310
  };
311
311
 
312
312
  // Set items for rerenderer
@@ -400,9 +400,7 @@ 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?.has(field);
406
404
 
407
405
  sortLabel = (
408
406
  <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
  /**