fui-material 2.8.20 → 2.8.21

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.
@@ -9979,6 +9979,51 @@ function extractDefaultPageMeta(raw, defaultSize, currentPage) {
9979
9979
  const number = Number(p.number ?? p.currentPage ?? p.page ?? currentPage);
9980
9980
  return { totalItems, size, totalPages, number };
9981
9981
  }
9982
+ function autoMergeAccumulatedData(prev, next) {
9983
+ if (!prev) return next;
9984
+ if (Array.isArray(next)) {
9985
+ const prevArray = Array.isArray(prev) ? prev : [];
9986
+ return [...prevArray, ...next];
9987
+ }
9988
+ if (next && typeof next === "object" && prev && typeof prev === "object") {
9989
+ const nextObj = next;
9990
+ const prevObj = prev;
9991
+ const commonArrayKeys = ["result", "items", "content", "data", "posts", "rows", "list"];
9992
+ for (const key of commonArrayKeys) {
9993
+ if (Array.isArray(nextObj[key])) {
9994
+ return {
9995
+ ...nextObj,
9996
+ [key]: [
9997
+ ...Array.isArray(prevObj[key]) ? prevObj[key] : [],
9998
+ ...nextObj[key]
9999
+ ]
10000
+ };
10001
+ }
10002
+ }
10003
+ if (nextObj.result && typeof nextObj.result === "object" && !Array.isArray(nextObj.result)) {
10004
+ const nextResult = nextObj.result;
10005
+ const prevResult = prevObj.result && typeof prevObj.result === "object" ? prevObj.result : {};
10006
+ const mergedResult = { ...nextResult };
10007
+ let hasArray = false;
10008
+ for (const subKey of Object.keys(nextResult)) {
10009
+ if (Array.isArray(nextResult[subKey])) {
10010
+ hasArray = true;
10011
+ mergedResult[subKey] = [
10012
+ ...Array.isArray(prevResult[subKey]) ? prevResult[subKey] : [],
10013
+ ...nextResult[subKey]
10014
+ ];
10015
+ }
10016
+ }
10017
+ if (hasArray) {
10018
+ return {
10019
+ ...nextObj,
10020
+ result: mergedResult
10021
+ };
10022
+ }
10023
+ }
10024
+ }
10025
+ return next;
10026
+ }
9982
10027
  function useFManualPagination(options) {
9983
10028
  const {
9984
10029
  queryKey,
@@ -10006,6 +10051,7 @@ function useFManualPagination(options) {
10006
10051
  const [pageSize, setPageSize] = useState(defaultPageSize);
10007
10052
  const [accumulatedData, setAccumulatedData] = useState(void 0);
10008
10053
  const [isFetchingMore, setIsFetchingMore] = useState(false);
10054
+ const [isSubmitting, setIsSubmitting] = useState(false);
10009
10055
  const isInfinite = mode === "infinite";
10010
10056
  useEffect(() => {
10011
10057
  setPageSize(defaultPageSize);
@@ -10051,11 +10097,7 @@ function useFManualPagination(options) {
10051
10097
  }, [select]);
10052
10098
  const defaultAppend = useCallback((prev, next) => {
10053
10099
  if (appendData) return appendData(prev, next);
10054
- if (Array.isArray(next)) {
10055
- const prevArray = Array.isArray(prev) ? prev : [];
10056
- return [...prevArray, ...next];
10057
- }
10058
- return next;
10100
+ return autoMergeAccumulatedData(prev, next);
10059
10101
  }, [appendData]);
10060
10102
  const submitFilters = useCallback(async ({
10061
10103
  payload,
@@ -10069,15 +10111,20 @@ function useFManualPagination(options) {
10069
10111
  setAccumulatedData(void 0);
10070
10112
  }
10071
10113
  }
10072
- const rawResponse = await query.run({
10073
- newParams: { ...payload, page: targetPage, size: pageSize },
10074
- dopUrl
10075
- });
10076
- const extracted = extractResult(rawResponse);
10077
- if (isInfinite) {
10078
- setAccumulatedData(extracted);
10114
+ setIsSubmitting(true);
10115
+ try {
10116
+ const rawResponse = await query.run({
10117
+ newParams: { ...payload, page: targetPage, size: pageSize },
10118
+ dopUrl
10119
+ });
10120
+ const extracted = extractResult(rawResponse);
10121
+ if (isInfinite) {
10122
+ setAccumulatedData(extracted);
10123
+ }
10124
+ return extracted;
10125
+ } finally {
10126
+ setIsSubmitting(false);
10079
10127
  }
10080
- return extracted;
10081
10128
  }, [query, page, pageSize, isInfinite, extractResult]);
10082
10129
  const changePage = useCallback(async (newPage) => {
10083
10130
  if (isInfinite) {
@@ -10133,13 +10180,14 @@ function useFManualPagination(options) {
10133
10180
  }
10134
10181
  }
10135
10182
  }), [pageMeta, page, pageSize, changePage]);
10183
+ const isLoading = isInfinite ? isSubmitting || query.isLoading && !accumulatedData : isSubmitting || query.isLoading && !currentExtractedData;
10136
10184
  return {
10137
10185
  data,
10138
10186
  result: data,
10139
10187
  rawResponse: rawData,
10140
10188
  meta,
10141
10189
  pageMeta,
10142
- isLoading: query.isLoading,
10190
+ isLoading,
10143
10191
  isFetching: query.isFetching,
10144
10192
  isFetchingMore,
10145
10193
  hasMore,