react-toolkits 2.9.25 → 2.9.27

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.9.27
4
+
5
+ ### Patch Changes
6
+
7
+ - b5384d7: feat: parse error message when http code out of 2xx range
8
+ ```
9
+
10
+ ```
11
+
12
+ ## 2.9.26
13
+
14
+ ### Patch Changes
15
+
16
+ - 080eeb6: chore: ensure form instance be passed to Form
17
+
3
18
  ## 2.9.25
4
19
 
5
20
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -445,9 +445,7 @@ declare const useTokenStore: zustand.UseBoundStore<Omit<zustand.StoreApi<TokenSt
445
445
  }>>;
446
446
  };
447
447
  }>;
448
- declare function useTokenValidation(options?: {
449
- skip: false;
450
- }): swr.SWRResponse<RequestResponse<any>, any, any>;
448
+ declare function useTestToken(): swr.SWRResponse<RequestResponse<any>, any, any>;
451
449
 
452
450
  interface NotFoundProps {
453
451
  redirectUrl?: string;
@@ -468,4 +466,4 @@ declare const SignIn: FC<SignInProps>;
468
466
 
469
467
  declare const mixedStorage: StateStorage;
470
468
 
471
- export { APP_ID_HEADER_NAME, ContextProvider, type ContextState, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FilterFormWrapper, type FilterFormWrapperProps, type Game, Highlight, type HighlightProps, InfiniteList, type InfiniteListProps, Layout, type LayoutState, NavMenu, type NavMenuItem, NotFound, OperationLogList, PermissionButton, type PermissionButtonProps, QueryList, QueryListAction, type QueryListProps, type QueryListRef, RequestError, type RequestOptions, type RequestResponse, RequireGame, RequirePermission, type RequirePermissionProps, SSO_URL, SignIn, type TokenState, type UseFormModalProps, type UseModalOperation, type UseModalProps, UserWidget, type UserWidgetProps, contextStore, mixedStorage, _default as permissionRoutes, request, useFormModal, useGameStore, useLayoutStore, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useTokenStore, useTokenValidation, useToolkitsContext };
469
+ export { APP_ID_HEADER_NAME, ContextProvider, type ContextState, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FilterFormWrapper, type FilterFormWrapperProps, type Game, Highlight, type HighlightProps, InfiniteList, type InfiniteListProps, Layout, type LayoutState, NavMenu, type NavMenuItem, NotFound, OperationLogList, PermissionButton, type PermissionButtonProps, QueryList, QueryListAction, type QueryListProps, type QueryListRef, RequestError, type RequestOptions, type RequestResponse, RequireGame, RequirePermission, type RequirePermissionProps, SSO_URL, SignIn, type TokenState, type UseFormModalProps, type UseModalOperation, type UseModalProps, UserWidget, type UserWidgetProps, contextStore, mixedStorage, _default as permissionRoutes, request, useFormModal, useGameStore, useLayoutStore, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useTestToken, useTokenStore, useToolkitsContext };
package/lib/index.js CHANGED
@@ -483,15 +483,13 @@ var init_requireGame = __esm({
483
483
  init_RequireGame();
484
484
  }
485
485
  });
486
- function useTokenValidation(options) {
486
+ function useTestToken() {
487
487
  const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
488
488
  return useSWRImmutable(
489
- !options?.skip ? usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check" : null,
489
+ usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check",
490
490
  (url) => request(url, {
491
491
  method: "POST",
492
- body: {
493
- permissions: ["100001"]
494
- },
492
+ body: { permissions: [] },
495
493
  headers: { [APP_ID_HEADER_NAME]: "global" }
496
494
  })
497
495
  );
@@ -891,7 +889,15 @@ async function request(url, opts = {}) {
891
889
  });
892
890
  const response = await fetch(url, requestOpts);
893
891
  if (!response.ok) {
894
- throw new RequestError({ status: response.status });
892
+ try {
893
+ const json = await response.json();
894
+ throw new Error(json.msg);
895
+ } catch (error) {
896
+ throw new RequestError({
897
+ status: response.status,
898
+ message: error?.message ?? "Can't parse response."
899
+ });
900
+ }
895
901
  }
896
902
  const responseInterceptor = contextStore.getState().interceptor?.response;
897
903
  if (typeof responseInterceptor === "function") {
@@ -940,32 +946,33 @@ var init_request = __esm({
940
946
  });
941
947
  function usePermissions(codes, options) {
942
948
  const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
949
+ const url = usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check";
950
+ const key = codes.length > 0 ? {
951
+ url,
952
+ codes,
953
+ options
954
+ } : null;
943
955
  const { data, isValidating, isLoading } = useSWR3(
944
- codes.length > 0 ? [usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check", codes, options] : null,
945
- ([url]) => request(url, {
946
- ...options,
947
- method: "POST",
948
- body: {
949
- permissions: codes
950
- }
951
- }).then((response) => {
952
- if (response.data?.has_all) {
953
- return codes.reduce(
954
- (acc, curr) => {
955
- acc[curr] = true;
956
- return acc;
957
- },
958
- {}
959
- );
960
- }
961
- return codes.reduce(
962
- (acc, curr) => {
963
- acc[curr] = response.data?.[curr] ?? false;
956
+ key,
957
+ async () => {
958
+ const res = await request(url, {
959
+ ...options,
960
+ method: "POST",
961
+ body: {
962
+ permissions: codes
963
+ }
964
+ });
965
+ if (res.data?.has_all) {
966
+ return codes.reduce((acc, curr) => {
967
+ acc[curr] = true;
964
968
  return acc;
965
- },
966
- {}
967
- );
968
- }),
969
+ }, {});
970
+ }
971
+ return codes.reduce((acc, curr) => {
972
+ acc[curr] = res.data?.[curr] ?? false;
973
+ return acc;
974
+ }, {});
975
+ },
969
976
  {
970
977
  revalidateOnFocus: false
971
978
  }
@@ -1271,7 +1278,7 @@ var init_QueryList = __esm({
1271
1278
  if (!accessible) {
1272
1279
  return /* @__PURE__ */ jsx(Result, { status: 403, subTitle: t("global.noEntitlement") });
1273
1280
  }
1274
- const formRenderer = typeof renderForm === "function" && /* @__PURE__ */ jsx(
1281
+ const formRenderer = typeof renderForm === "function" ? /* @__PURE__ */ jsx(
1275
1282
  FilterFormWrapper_default,
1276
1283
  {
1277
1284
  showReset,
@@ -1287,7 +1294,11 @@ var init_QueryList = __esm({
1287
1294
  }
1288
1295
  })
1289
1296
  }
1297
+ ) : (
1298
+ // 屏蔽 Form 组件的警告(Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?)
1299
+ /* @__PURE__ */ jsx(Form, { form: _form })
1290
1300
  );
1301
+ const renderFooter = footer && (() => footer(data));
1291
1302
  return /* @__PURE__ */ jsxs("div", { children: [
1292
1303
  formRenderer,
1293
1304
  typeof tableExtra === "function" ? tableExtra(_form, data) : tableExtra,
@@ -1298,7 +1309,7 @@ var init_QueryList = __esm({
1298
1309
  dataSource,
1299
1310
  loading: isValidating,
1300
1311
  pagination,
1301
- footer: () => footer?.(data)
1312
+ footer: renderFooter
1302
1313
  }
1303
1314
  )
1304
1315
  ] });
@@ -2780,6 +2791,6 @@ var signIn_default = SignIn;
2780
2791
  init_request();
2781
2792
  init_storage();
2782
2793
 
2783
- export { APP_ID_HEADER_NAME, Provider_default as ContextProvider, DynamicTags_default as DynamicTags, ExpandableParagraph_default as ExpandableParagraph, FilterFormWrapper_default as FilterFormWrapper, Highlight_default as Highlight, InfiniteList_default as InfiniteList, Layout_default as Layout, NavMenu_default as NavMenu, notFound_default as NotFound, operationLogList_default as OperationLogList, PermissionButton_default as PermissionButton, QueryList_default as QueryList, QueryListAction, RequestError, RequireGame_default as RequireGame, RequirePermission_default as RequirePermission, SSO_URL, signIn_default as SignIn, UserWidget_default as UserWidget, contextStore, mixedStorage, permission_default as permissionRoutes, request, useFormModal, useGameStore, useLayoutStore, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useTokenStore, useTokenValidation, useToolkitsContext };
2794
+ export { APP_ID_HEADER_NAME, Provider_default as ContextProvider, DynamicTags_default as DynamicTags, ExpandableParagraph_default as ExpandableParagraph, FilterFormWrapper_default as FilterFormWrapper, Highlight_default as Highlight, InfiniteList_default as InfiniteList, Layout_default as Layout, NavMenu_default as NavMenu, notFound_default as NotFound, operationLogList_default as OperationLogList, PermissionButton_default as PermissionButton, QueryList_default as QueryList, QueryListAction, RequestError, RequireGame_default as RequireGame, RequirePermission_default as RequirePermission, SSO_URL, signIn_default as SignIn, UserWidget_default as UserWidget, contextStore, mixedStorage, permission_default as permissionRoutes, request, useFormModal, useGameStore, useLayoutStore, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useTestToken, useTokenStore, useToolkitsContext };
2784
2795
  //# sourceMappingURL=index.js.map
2785
2796
  //# sourceMappingURL=index.js.map