react-toolkits 2.13.33 → 2.13.35

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,17 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.13.35
4
+
5
+ ### Patch Changes
6
+
7
+ - 36f96c7: fix: swr cache not been cleared
8
+
9
+ ## 2.13.34
10
+
11
+ ### Patch Changes
12
+
13
+ - ca6e5e1: feat: add skipRequestInterceptor and skipResponseInterceptor in AxiosRequestConfig
14
+
3
15
  ## 2.13.33
4
16
 
5
17
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -439,7 +439,7 @@ interface MenuListItem {
439
439
  }
440
440
 
441
441
  declare function usePermission(code?: string, config?: AxiosRequestConfig): SWRResponse<boolean>;
442
- declare function usePermission(code?: string[], config?: AxiosRequestConfig): SWRResponse<true> | SWRResponse<Record<string, boolean>>;
442
+ declare function usePermission(code?: string[], config?: AxiosRequestConfig): SWRResponse<Record<string, boolean>>;
443
443
  declare function useMenuList(): SWRResponse<MenuListItem[], any, any>;
444
444
 
445
445
  declare const _default$2: react_jsx_runtime.JSX.Element;
package/lib/index.js CHANGED
@@ -389,6 +389,9 @@ var init_Interceptors = __esm({
389
389
  requestInterceptorId = axios2.interceptors.request.use(...interceptors.request);
390
390
  } else {
391
391
  requestInterceptorId = axios2.interceptors.request.use((config) => {
392
+ if (config.skipRequestInterceptor) {
393
+ return config;
394
+ }
392
395
  const headers = new AxiosHeaders(config.headers);
393
396
  config.responseType = config.responseType || "json";
394
397
  if (token) {
@@ -411,6 +414,9 @@ var init_Interceptors = __esm({
411
414
  } else {
412
415
  responseInterceptorId = axios2.interceptors.response.use(
413
416
  (response) => {
417
+ if (response.config.skipResponseInterceptor) {
418
+ return response;
419
+ }
414
420
  const responseType = response.request.responseType || "json";
415
421
  if (responseType === "json") {
416
422
  const data = response.data;
@@ -628,15 +634,21 @@ function usePermission(code, config) {
628
634
  (args) => axios2.post(...args).then((response) => response.data.data)
629
635
  );
630
636
  let newData;
631
- if (typeof code === "undefined" || Array.isArray(code) && code.length === 0) {
632
- newData = true;
633
- } else if (typeof code === "string") {
634
- newData = data?.has_all ? true : data?.[code] ?? false;
635
- } else {
636
- newData = permissionCodes.reduce((acc, curr) => {
637
- acc[curr] = data?.has_all ? true : data?.[curr] ?? false;
638
- return acc;
639
- }, {});
637
+ if (data !== void 0) {
638
+ if (typeof code === "undefined") {
639
+ newData = true;
640
+ } else if (typeof code === "string") {
641
+ newData = data.has_all ? true : data[code] ?? false;
642
+ } else {
643
+ if (code.length === 0) {
644
+ newData = { [code[0]]: true };
645
+ } else {
646
+ newData = permissionCodes.reduce((acc, curr) => {
647
+ acc[curr] = data.has_all ? true : data[curr] ?? false;
648
+ return acc;
649
+ }, {});
650
+ }
651
+ }
640
652
  }
641
653
  return {
642
654
  ...rest,
@@ -913,16 +925,23 @@ var init_GameSelect = __esm({
913
925
  const { t } = useTranslation();
914
926
  const { gameApiV2, gameId, setGameId } = useToolkitsStore((s) => s);
915
927
  const { data, isLoading } = useGames();
916
- const { mutate: mutate2 } = useSWRConfig();
928
+ const { cache } = useSWRConfig();
917
929
  const filteredData = data?.filter((item) => filter?.(item) ?? true);
918
930
  const _options = typeof options === "function" ? options(filteredData) : filteredData?.map((item) => ({
919
931
  label: item.name,
920
932
  value: gameApiV2 ? item.game_id : item.id
921
933
  }));
922
- const onChange = async (value) => {
923
- await mutate2((key) => key !== "/api/game/list" && key !== "/api/usystem/game/all", void 0, false);
934
+ const onChange = (value) => {
935
+ clearCache();
924
936
  setGameId(value);
925
937
  };
938
+ const clearCache = () => {
939
+ for (const key of cache.keys()) {
940
+ if (key !== "/api/game/list" && key !== "/api/usystem/game/all") {
941
+ cache.delete(key);
942
+ }
943
+ }
944
+ };
926
945
  useEffect(() => {
927
946
  if (data && data.length > 0) {
928
947
  const firstId = gameApiV2 ? data[0].game_id : data[0].id;