@canlooks/can-ui 0.0.161 → 0.0.162

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.
@@ -52,7 +52,7 @@ export interface CurdBaseProps<R extends RowType = RowType, F extends FormValue
52
52
  }, filterValue?: FormValue, sorter?: {
53
53
  field: FieldPath;
54
54
  type: OrderType;
55
- }): LoadRowsReturn<R> | Promise<LoadRowsReturn<R>>;
55
+ }): LoadRowsReturn<R> | null | Promise<LoadRowsReturn<R> | null>;
56
56
  }['bivarianceHack'];
57
57
  onLoad?(rowsReturn: LoadRowsReturn<R>): void;
58
58
  columns?: (CurdColumn<R> | symbol)[];
@@ -144,7 +144,12 @@ exports.Curd = (0, react_1.memo)((props) => {
144
144
  _setInnerRows(data);
145
145
  };
146
146
  const [innerTotal, setInnerTotal] = (0, utils_1.useDerivedState)(props.paginationProps?.total || 0);
147
+ const suppressReload = (0, react_1.useRef)(false);
147
148
  const [innerLoading, innerLoadRows] = (0, utils_1.useLoading)(async () => {
149
+ if (suppressReload.current) {
150
+ suppressReload.current = false;
151
+ return;
152
+ }
148
153
  if (loadRows) {
149
154
  const res = await loadRows(props.paginatable !== false
150
155
  ? {
@@ -158,8 +163,14 @@ exports.Curd = (0, react_1.memo)((props) => {
158
163
  }
159
164
  : void 0);
160
165
  if (typeof res === 'object' && res !== null) {
161
- setInnerRows(res.rows);
162
- setInnerTotal(res.total);
166
+ const { rows, total = 0 } = res;
167
+ setInnerRows(rows);
168
+ setInnerTotal(total);
169
+ const maxPage = Math.max(Math.ceil(total / innerPageSize.current), 1);
170
+ if (maxPage < innerPage.current) {
171
+ suppressReload.current = true;
172
+ setInnerPage(maxPage);
173
+ }
163
174
  }
164
175
  }
165
176
  }, props.loading);
@@ -52,7 +52,7 @@ export interface CurdBaseProps<R extends RowType = RowType, F extends FormValue
52
52
  }, filterValue?: FormValue, sorter?: {
53
53
  field: FieldPath;
54
54
  type: OrderType;
55
- }): LoadRowsReturn<R> | Promise<LoadRowsReturn<R>>;
55
+ }): LoadRowsReturn<R> | null | Promise<LoadRowsReturn<R> | null>;
56
56
  }['bivarianceHack'];
57
57
  onLoad?(rowsReturn: LoadRowsReturn<R>): void;
58
58
  columns?: (CurdColumn<R> | symbol)[];
@@ -141,7 +141,12 @@ export const Curd = memo((props) => {
141
141
  _setInnerRows(data);
142
142
  };
143
143
  const [innerTotal, setInnerTotal] = useDerivedState(props.paginationProps?.total || 0);
144
+ const suppressReload = useRef(false);
144
145
  const [innerLoading, innerLoadRows] = useLoading(async () => {
146
+ if (suppressReload.current) {
147
+ suppressReload.current = false;
148
+ return;
149
+ }
145
150
  if (loadRows) {
146
151
  const res = await loadRows(props.paginatable !== false
147
152
  ? {
@@ -155,8 +160,14 @@ export const Curd = memo((props) => {
155
160
  }
156
161
  : void 0);
157
162
  if (typeof res === 'object' && res !== null) {
158
- setInnerRows(res.rows);
159
- setInnerTotal(res.total);
163
+ const { rows, total = 0 } = res;
164
+ setInnerRows(rows);
165
+ setInnerTotal(total);
166
+ const maxPage = Math.max(Math.ceil(total / innerPageSize.current), 1);
167
+ if (maxPage < innerPage.current) {
168
+ suppressReload.current = true;
169
+ setInnerPage(maxPage);
170
+ }
160
171
  }
161
172
  }
162
173
  }, props.loading);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.161",
3
+ "version": "0.0.162",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",