@etsoo/react 1.7.34 → 1.7.36

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) {
@@ -119,8 +120,11 @@ export const ScrollerGrid = (props) => {
119
120
  // Reset the state and load again
120
121
  const reset = (add, items = []) => {
121
122
  const resetState = {
123
+ queryPaging: {
124
+ ...refs.current.queryPaging,
125
+ currentPage: 0
126
+ },
122
127
  autoLoad: true,
123
- currentPage: 0,
124
128
  loadedItems: 0,
125
129
  hasNextPage: true,
126
130
  isNextPageLoading: false,
@@ -225,7 +229,7 @@ export const ScrollerGrid = (props) => {
225
229
  // Row count
226
230
  const rowCount = refs.current.hasNextPage ? rowLength + 1 : rowLength;
227
231
  // Auto load data when current page is 0
228
- if (refs.current.currentPage === 0 && refs.current.autoLoad) {
232
+ if (refs.current.queryPaging.currentPage === 0 && refs.current.autoLoad) {
229
233
  const initItems = onInitLoad == null ? undefined : onInitLoad(ref.current);
230
234
  if (initItems)
231
235
  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) {
@@ -114,10 +114,13 @@ export const ScrollerList = (props) => {
114
114
  // Reset the state and load again
115
115
  const reset = (add, items = []) => {
116
116
  const resetState = {
117
+ queryPaging: {
118
+ ...stateRefs.current.queryPaging,
119
+ currentPage: 0
120
+ },
117
121
  autoLoad: true,
118
122
  lastLoadedItems: undefined,
119
123
  loadedItems: 0,
120
- currentPage: 0,
121
124
  hasNextPage: true,
122
125
  isNextPageLoading: false,
123
126
  ...add
@@ -179,7 +182,8 @@ export const ScrollerList = (props) => {
179
182
  // Item count
180
183
  const itemCount = stateRefs.current.hasNextPage ? rowCount + 1 : rowCount;
181
184
  // Auto load data when current page is 0
182
- if (stateRefs.current.currentPage === 0 && stateRefs.current.autoLoad) {
185
+ if (stateRefs.current.queryPaging?.currentPage === 0 &&
186
+ stateRefs.current.autoLoad) {
183
187
  const initItems = onInitLoad == null ? undefined : onInitLoad(listRef.current);
184
188
  if (initItems)
185
189
  reset(initItems[1], initItems[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.7.34",
3
+ "version": "1.7.36",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@emotion/css": "^11.11.2",
51
51
  "@emotion/react": "^11.11.4",
52
52
  "@emotion/styled": "^11.11.5",
53
- "@etsoo/appscript": "^1.4.84",
53
+ "@etsoo/appscript": "^1.4.85",
54
54
  "@etsoo/notificationbase": "^1.1.42",
55
55
  "@etsoo/shared": "^1.2.37",
56
56
  "react": "^18.3.1",
@@ -59,13 +59,13 @@
59
59
  "react-window": "^1.8.10"
60
60
  },
61
61
  "devDependencies": {
62
- "@babel/cli": "^7.24.1",
63
- "@babel/core": "^7.24.4",
62
+ "@babel/cli": "^7.24.5",
63
+ "@babel/core": "^7.24.5",
64
64
  "@babel/plugin-transform-runtime": "^7.24.3",
65
- "@babel/preset-env": "^7.24.4",
66
- "@babel/runtime-corejs3": "^7.24.4",
67
- "@testing-library/jest-dom": "^6.4.2",
68
- "@testing-library/react": "^15.0.5",
65
+ "@babel/preset-env": "^7.24.5",
66
+ "@babel/runtime-corejs3": "^7.24.5",
67
+ "@testing-library/jest-dom": "^6.4.5",
68
+ "@testing-library/react": "^15.0.6",
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];
@@ -319,8 +319,11 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
319
319
  // Reset the state and load again
320
320
  const reset = (add?: Partial<GridLoaderStates<T>>, items: T[] = []) => {
321
321
  const resetState: Partial<GridLoaderStates<T>> = {
322
+ queryPaging: {
323
+ ...refs.current.queryPaging,
324
+ currentPage: 0
325
+ },
322
326
  autoLoad: true,
323
- currentPage: 0,
324
327
  loadedItems: 0,
325
328
  hasNextPage: true,
326
329
  isNextPageLoading: false,
@@ -443,7 +446,7 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
443
446
  const rowCount = refs.current.hasNextPage ? rowLength + 1 : rowLength;
444
447
 
445
448
  // Auto load data when current page is 0
446
- if (refs.current.currentPage === 0 && refs.current.autoLoad) {
449
+ if (refs.current.queryPaging.currentPage === 0 && refs.current.autoLoad) {
447
450
  const initItems =
448
451
  onInitLoad == null ? undefined : onInitLoad(ref.current);
449
452
  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];
@@ -250,10 +250,13 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
250
250
  // Reset the state and load again
251
251
  const reset = (add?: Partial<GridLoaderStates<T>>, items: T[] = []) => {
252
252
  const resetState: Partial<GridLoaderStates<T>> = {
253
+ queryPaging: {
254
+ ...stateRefs.current.queryPaging,
255
+ currentPage: 0
256
+ },
253
257
  autoLoad: true,
254
258
  lastLoadedItems: undefined,
255
259
  loadedItems: 0,
256
- currentPage: 0,
257
260
  hasNextPage: true,
258
261
  isNextPageLoading: false,
259
262
  ...add
@@ -330,7 +333,10 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
330
333
  const itemCount = stateRefs.current.hasNextPage ? rowCount + 1 : rowCount;
331
334
 
332
335
  // Auto load data when current page is 0
333
- if (stateRefs.current.currentPage === 0 && stateRefs.current.autoLoad) {
336
+ if (
337
+ stateRefs.current.queryPaging?.currentPage === 0 &&
338
+ stateRefs.current.autoLoad
339
+ ) {
334
340
  const initItems =
335
341
  onInitLoad == null ? undefined : onInitLoad(listRef.current);
336
342
  if (initItems) reset(initItems[1], initItems[0]);