react-toolkits 2.13.34 → 2.13.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.13.36
4
+
5
+ ### Patch Changes
6
+
7
+ - dba6e3c: feat: usePermission hook default return true
8
+
9
+ ## 2.13.35
10
+
11
+ ### Patch Changes
12
+
13
+ - 36f96c7: fix: swr cache not been cleared
14
+
3
15
  ## 2.13.34
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
@@ -633,12 +633,10 @@ function usePermission(code, config) {
633
633
  permissionCodes.length > 0 ? [url4, body, config] : null,
634
634
  (args) => axios2.post(...args).then((response) => response.data.data)
635
635
  );
636
- let newData;
637
- if (typeof code === "undefined" || Array.isArray(code) && code.length === 0) {
638
- newData = true;
639
- } else if (typeof code === "string") {
636
+ let newData = true;
637
+ if (typeof code === "string") {
640
638
  newData = data?.has_all ? true : data?.[code] ?? false;
641
- } else {
639
+ } else if (Array.isArray(code) && code.length > 0) {
642
640
  newData = permissionCodes.reduce((acc, curr) => {
643
641
  acc[curr] = data?.has_all ? true : data?.[curr] ?? false;
644
642
  return acc;
@@ -919,16 +917,23 @@ var init_GameSelect = __esm({
919
917
  const { t } = useTranslation();
920
918
  const { gameApiV2, gameId, setGameId } = useToolkitsStore((s) => s);
921
919
  const { data, isLoading } = useGames();
922
- const { mutate: mutate2 } = useSWRConfig();
920
+ const { cache } = useSWRConfig();
923
921
  const filteredData = data?.filter((item) => filter?.(item) ?? true);
924
922
  const _options = typeof options === "function" ? options(filteredData) : filteredData?.map((item) => ({
925
923
  label: item.name,
926
924
  value: gameApiV2 ? item.game_id : item.id
927
925
  }));
928
- const onChange = async (value) => {
929
- await mutate2((key) => key !== "/api/game/list" && key !== "/api/usystem/game/all", void 0, false);
926
+ const onChange = (value) => {
927
+ clearCache();
930
928
  setGameId(value);
931
929
  };
930
+ const clearCache = () => {
931
+ for (const key of cache.keys()) {
932
+ if (key !== "/api/game/list" && key !== "/api/usystem/game/all") {
933
+ cache.delete(key);
934
+ }
935
+ }
936
+ };
932
937
  useEffect(() => {
933
938
  if (data && data.length > 0) {
934
939
  const firstId = gameApiV2 ? data[0].game_id : data[0].id;