@etsoo/react 1.7.35 → 1.7.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.
@@ -1,3 +1,4 @@
1
+ import { QueryPagingData } from '@etsoo/appscript';
1
2
  import { DataTypes } from '@etsoo/shared';
2
3
  /**
3
4
  * Grid size
@@ -34,21 +35,9 @@ export type GridJsonData = Omit<GridLoadDataProps, 'data'>;
34
35
  */
35
36
  export type GridLoadDataProps = {
36
37
  /**
37
- * Current page
38
+ * Query paging data
38
39
  */
39
- currentPage: number;
40
- /**
41
- * Load batch size
42
- */
43
- batchSize: number;
44
- /**
45
- * Current order field
46
- */
47
- orderBy?: string;
48
- /**
49
- * Order ascending or not?
50
- */
51
- orderByAsc?: boolean;
40
+ queryPaging: QueryPagingData;
52
41
  /**
53
42
  * Data related
54
43
  */
@@ -18,13 +18,15 @@ export const ScrollerGrid = (props) => {
18
18
  };
19
19
  // Refs
20
20
  const refs = React.useRef({
21
+ queryPaging: {
22
+ currentPage: 0,
23
+ orderBy: defaultOrderBy,
24
+ orderByAsc: defaultOrderByAsc,
25
+ batchSize: 10
26
+ },
21
27
  autoLoad,
22
- currentPage: 0,
23
28
  hasNextPage: true,
24
29
  isNextPageLoading: false,
25
- orderBy: defaultOrderBy,
26
- orderByAsc: defaultOrderByAsc,
27
- batchSize: 10,
28
30
  loadedItems: 0,
29
31
  selectedItems: [],
30
32
  idCache: {}
@@ -38,12 +40,9 @@ export const ScrollerGrid = (props) => {
38
40
  // Update state
39
41
  refs.current.isNextPageLoading = true;
40
42
  // Parameters
41
- const { currentPage, batchSize, orderBy, orderByAsc, data } = refs.current;
43
+ const { queryPaging, data } = refs.current;
42
44
  const loadProps = {
43
- currentPage,
44
- batchSize,
45
- orderBy,
46
- orderByAsc,
45
+ queryPaging,
47
46
  data
48
47
  };
49
48
  loadData(loadProps).then((result) => {
@@ -54,7 +53,8 @@ export const ScrollerGrid = (props) => {
54
53
  const newItems = result.length;
55
54
  refs.current.lastLoadedItems = newItems;
56
55
  refs.current.isNextPageLoading = false;
57
- refs.current.hasNextPage = newItems >= batchSize;
56
+ refs.current.hasNextPage =
57
+ newItems >= refs.current.queryPaging.batchSize;
58
58
  if (pageAdd === 0) {
59
59
  // New items
60
60
  const newRows = refs.current.lastLoadedItems
@@ -72,7 +72,8 @@ export const ScrollerGrid = (props) => {
72
72
  }
73
73
  else {
74
74
  // Set current page
75
- refs.current.currentPage = refs.current.currentPage + pageAdd;
75
+ var currentPage = refs.current.queryPaging.currentPage ?? 0;
76
+ refs.current.queryPaging.currentPage = currentPage + pageAdd;
76
77
  // Update rows, avoid duplicate items
77
78
  const newRows = [...rows];
78
79
  for (const item of result) {
@@ -118,14 +119,19 @@ export const ScrollerGrid = (props) => {
118
119
  };
119
120
  // Reset the state and load again
120
121
  const reset = (add, items = []) => {
122
+ const { queryPaging, ...rest } = add ?? {};
121
123
  const resetState = {
124
+ queryPaging: {
125
+ ...refs.current.queryPaging,
126
+ currentPage: 0,
127
+ ...queryPaging
128
+ },
122
129
  autoLoad: true,
123
- currentPage: 0,
124
130
  loadedItems: 0,
125
131
  hasNextPage: true,
126
132
  isNextPageLoading: false,
127
133
  lastLoadedItems: undefined,
128
- ...add
134
+ ...rest
129
135
  };
130
136
  Object.assign(refs.current, resetState);
131
137
  // Reset items
@@ -225,7 +231,7 @@ export const ScrollerGrid = (props) => {
225
231
  // Row count
226
232
  const rowCount = refs.current.hasNextPage ? rowLength + 1 : rowLength;
227
233
  // Auto load data when current page is 0
228
- if (refs.current.currentPage === 0 && refs.current.autoLoad) {
234
+ if (refs.current.queryPaging.currentPage === 0 && refs.current.autoLoad) {
229
235
  const initItems = onInitLoad == null ? undefined : onInitLoad(ref.current);
230
236
  if (initItems)
231
237
  reset(initItems[1], initItems[0]);
@@ -37,14 +37,16 @@ export const ScrollerList = (props) => {
37
37
  // States
38
38
  const batchSize = GridSizeGet(loadBatchSize, height);
39
39
  const stateRefs = React.useRef({
40
+ queryPaging: {
41
+ currentPage: 0,
42
+ orderBy: defaultOrderBy,
43
+ orderByAsc: defaultOrderByAsc,
44
+ batchSize: batchSize
45
+ },
40
46
  autoLoad,
41
- currentPage: 0,
42
47
  loadedItems: 0,
43
48
  hasNextPage: true,
44
49
  isNextPageLoading: false,
45
- orderBy: defaultOrderBy,
46
- orderByAsc: defaultOrderByAsc,
47
- batchSize: batchSize,
48
50
  selectedItems: [],
49
51
  idCache: {}
50
52
  });
@@ -57,12 +59,9 @@ export const ScrollerList = (props) => {
57
59
  // Update state
58
60
  stateRefs.current.isNextPageLoading = true;
59
61
  // Parameters
60
- const { currentPage, batchSize, orderBy, orderByAsc, data } = stateRefs.current;
62
+ const { queryPaging, data } = stateRefs.current;
61
63
  const loadProps = {
62
- currentPage,
63
- batchSize,
64
- orderBy,
65
- orderByAsc,
64
+ queryPaging,
66
65
  data
67
66
  };
68
67
  loadData(loadProps).then((result) => {
@@ -90,8 +89,9 @@ export const ScrollerList = (props) => {
90
89
  setRows(newRows);
91
90
  }
92
91
  else {
93
- stateRefs.current.currentPage =
94
- stateRefs.current.currentPage + pageAdd;
92
+ var currentPage = stateRefs.current.queryPaging.currentPage ?? 0;
93
+ stateRefs.current.queryPaging.currentPage =
94
+ currentPage + pageAdd;
95
95
  // Update rows, avoid duplicate items
96
96
  const newRows = [...rows];
97
97
  for (const item of result) {
@@ -113,14 +113,19 @@ export const ScrollerList = (props) => {
113
113
  };
114
114
  // Reset the state and load again
115
115
  const reset = (add, items = []) => {
116
+ const { queryPaging, ...rest } = add ?? {};
116
117
  const resetState = {
118
+ queryPaging: {
119
+ ...stateRefs.current.queryPaging,
120
+ currentPage: 0,
121
+ ...queryPaging
122
+ },
117
123
  autoLoad: true,
118
124
  lastLoadedItems: undefined,
119
125
  loadedItems: 0,
120
- currentPage: 0,
121
126
  hasNextPage: true,
122
127
  isNextPageLoading: false,
123
- ...add
128
+ ...rest
124
129
  };
125
130
  Object.assign(stateRefs.current, resetState);
126
131
  // Reset
@@ -179,7 +184,8 @@ export const ScrollerList = (props) => {
179
184
  // Item count
180
185
  const itemCount = stateRefs.current.hasNextPage ? rowCount + 1 : rowCount;
181
186
  // Auto load data when current page is 0
182
- if (stateRefs.current.currentPage === 0 && stateRefs.current.autoLoad) {
187
+ if (stateRefs.current.queryPaging?.currentPage === 0 &&
188
+ stateRefs.current.autoLoad) {
183
189
  const initItems = onInitLoad == null ? undefined : onInitLoad(listRef.current);
184
190
  if (initItems)
185
191
  reset(initItems[1], initItems[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.7.35",
3
+ "version": "1.7.37",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -65,7 +65,7 @@
65
65
  "@babel/preset-env": "^7.24.5",
66
66
  "@babel/runtime-corejs3": "^7.24.5",
67
67
  "@testing-library/jest-dom": "^6.4.5",
68
- "@testing-library/react": "^15.0.6",
68
+ "@testing-library/react": "^15.0.7",
69
69
  "@types/jest": "^29.5.12",
70
70
  "@types/react": "^18.3.1",
71
71
  "@types/react-dom": "^18.3.0",
@@ -1,3 +1,4 @@
1
+ import { QueryPagingData } from '@etsoo/appscript';
1
2
  import { DataTypes, DomUtils } from '@etsoo/shared';
2
3
 
3
4
  /**
@@ -67,24 +68,9 @@ export type GridJsonData = Omit<GridLoadDataProps, 'data'>;
67
68
  */
68
69
  export type GridLoadDataProps = {
69
70
  /**
70
- * Current page
71
+ * Query paging data
71
72
  */
72
- currentPage: number;
73
-
74
- /**
75
- * Load batch size
76
- */
77
- batchSize: number;
78
-
79
- /**
80
- * Current order field
81
- */
82
- orderBy?: string;
83
-
84
- /**
85
- * Order ascending or not?
86
- */
87
- orderByAsc?: boolean;
73
+ queryPaging: QueryPagingData;
88
74
 
89
75
  /**
90
76
  * Data related
@@ -190,13 +190,15 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
190
190
 
191
191
  // Refs
192
192
  const refs = React.useRef<GridLoaderStates<T>>({
193
+ queryPaging: {
194
+ currentPage: 0,
195
+ orderBy: defaultOrderBy,
196
+ orderByAsc: defaultOrderByAsc,
197
+ batchSize: 10
198
+ },
193
199
  autoLoad,
194
- currentPage: 0,
195
200
  hasNextPage: true,
196
201
  isNextPageLoading: false,
197
- orderBy: defaultOrderBy,
198
- orderByAsc: defaultOrderByAsc,
199
- batchSize: 10,
200
202
  loadedItems: 0,
201
203
  selectedItems: [],
202
204
  idCache: {}
@@ -213,14 +215,10 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
213
215
  refs.current.isNextPageLoading = true;
214
216
 
215
217
  // Parameters
216
- const { currentPage, batchSize, orderBy, orderByAsc, data } =
217
- refs.current;
218
+ const { queryPaging, data } = refs.current;
218
219
 
219
220
  const loadProps: GridLoadDataProps = {
220
- currentPage,
221
- batchSize,
222
- orderBy,
223
- orderByAsc,
221
+ queryPaging,
224
222
  data
225
223
  };
226
224
 
@@ -233,7 +231,8 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
233
231
  const newItems = result.length;
234
232
  refs.current.lastLoadedItems = newItems;
235
233
  refs.current.isNextPageLoading = false;
236
- refs.current.hasNextPage = newItems >= batchSize;
234
+ refs.current.hasNextPage =
235
+ newItems >= refs.current.queryPaging.batchSize;
237
236
 
238
237
  if (pageAdd === 0) {
239
238
  // New items
@@ -256,7 +255,8 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
256
255
  setRows(newRows);
257
256
  } else {
258
257
  // Set current page
259
- refs.current.currentPage = refs.current.currentPage + pageAdd;
258
+ var currentPage = refs.current.queryPaging.currentPage ?? 0;
259
+ refs.current.queryPaging.currentPage = currentPage + pageAdd;
260
260
 
261
261
  // Update rows, avoid duplicate items
262
262
  const newRows = [...rows];
@@ -318,14 +318,19 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
318
318
 
319
319
  // Reset the state and load again
320
320
  const reset = (add?: Partial<GridLoaderStates<T>>, items: T[] = []) => {
321
+ const { queryPaging, ...rest } = add ?? {};
321
322
  const resetState: Partial<GridLoaderStates<T>> = {
323
+ queryPaging: {
324
+ ...refs.current.queryPaging,
325
+ currentPage: 0,
326
+ ...queryPaging
327
+ },
322
328
  autoLoad: true,
323
- currentPage: 0,
324
329
  loadedItems: 0,
325
330
  hasNextPage: true,
326
331
  isNextPageLoading: false,
327
332
  lastLoadedItems: undefined,
328
- ...add
333
+ ...rest
329
334
  };
330
335
  Object.assign(refs.current, resetState);
331
336
 
@@ -443,7 +448,7 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
443
448
  const rowCount = refs.current.hasNextPage ? rowLength + 1 : rowLength;
444
449
 
445
450
  // Auto load data when current page is 0
446
- if (refs.current.currentPage === 0 && refs.current.autoLoad) {
451
+ if (refs.current.queryPaging.currentPage === 0 && refs.current.autoLoad) {
447
452
  const initItems =
448
453
  onInitLoad == null ? undefined : onInitLoad(ref.current);
449
454
  if (initItems) reset(initItems[1], initItems[0]);
@@ -154,14 +154,16 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
154
154
  // States
155
155
  const batchSize = GridSizeGet(loadBatchSize, height);
156
156
  const stateRefs = React.useRef<GridLoaderStates<T>>({
157
+ queryPaging: {
158
+ currentPage: 0,
159
+ orderBy: defaultOrderBy,
160
+ orderByAsc: defaultOrderByAsc,
161
+ batchSize: batchSize
162
+ },
157
163
  autoLoad,
158
- currentPage: 0,
159
164
  loadedItems: 0,
160
165
  hasNextPage: true,
161
166
  isNextPageLoading: false,
162
- orderBy: defaultOrderBy,
163
- orderByAsc: defaultOrderByAsc,
164
- batchSize: batchSize,
165
167
  selectedItems: [],
166
168
  idCache: {}
167
169
  });
@@ -179,14 +181,10 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
179
181
  stateRefs.current.isNextPageLoading = true;
180
182
 
181
183
  // Parameters
182
- const { currentPage, batchSize, orderBy, orderByAsc, data } =
183
- stateRefs.current;
184
+ const { queryPaging, data } = stateRefs.current;
184
185
 
185
186
  const loadProps: GridLoadDataProps = {
186
- currentPage,
187
- batchSize,
188
- orderBy,
189
- orderByAsc,
187
+ queryPaging,
190
188
  data
191
189
  };
192
190
 
@@ -221,8 +219,10 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
221
219
  // Update rows
222
220
  setRows(newRows);
223
221
  } else {
224
- stateRefs.current.currentPage =
225
- stateRefs.current.currentPage + pageAdd;
222
+ var currentPage =
223
+ stateRefs.current.queryPaging.currentPage ?? 0;
224
+ stateRefs.current.queryPaging.currentPage =
225
+ currentPage + pageAdd;
226
226
 
227
227
  // Update rows, avoid duplicate items
228
228
  const newRows = [...rows];
@@ -249,14 +249,19 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
249
249
 
250
250
  // Reset the state and load again
251
251
  const reset = (add?: Partial<GridLoaderStates<T>>, items: T[] = []) => {
252
+ const { queryPaging, ...rest } = add ?? {};
252
253
  const resetState: Partial<GridLoaderStates<T>> = {
254
+ queryPaging: {
255
+ ...stateRefs.current.queryPaging,
256
+ currentPage: 0,
257
+ ...queryPaging
258
+ },
253
259
  autoLoad: true,
254
260
  lastLoadedItems: undefined,
255
261
  loadedItems: 0,
256
- currentPage: 0,
257
262
  hasNextPage: true,
258
263
  isNextPageLoading: false,
259
- ...add
264
+ ...rest
260
265
  };
261
266
  Object.assign(stateRefs.current, resetState);
262
267
 
@@ -330,7 +335,10 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
330
335
  const itemCount = stateRefs.current.hasNextPage ? rowCount + 1 : rowCount;
331
336
 
332
337
  // Auto load data when current page is 0
333
- if (stateRefs.current.currentPage === 0 && stateRefs.current.autoLoad) {
338
+ if (
339
+ stateRefs.current.queryPaging?.currentPage === 0 &&
340
+ stateRefs.current.autoLoad
341
+ ) {
334
342
  const initItems =
335
343
  onInitLoad == null ? undefined : onInitLoad(listRef.current);
336
344
  if (initItems) reset(initItems[1], initItems[0]);