From c8741e76560c592b9bab379399b5c5d647772c5b Mon Sep 17 00:00:00 2001 From: Junyi Date: Thu, 17 Oct 2024 18:30:09 +0800 Subject: [PATCH] fix(plugin-file-manager): fix calling rule hook on read-pretty fields (#5447) --- .../src/client/hooks/useStorageRules.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useStorageRules.ts b/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useStorageRules.ts index 5ffbcd6f05..942f5b812b 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useStorageRules.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useStorageRules.ts @@ -7,16 +7,25 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -import { useCollectionField, useCollectionManager, useRequest } from '@nocobase/client'; +import { useField } from '@formily/react'; +import { useAPIClient, useCollectionField, useCollectionManager, useRequest } from '@nocobase/client'; export function useStorageRules(storage) { const name = storage ?? ''; + const apiClient = useAPIClient(); + const field = useField(); const { loading, data } = useRequest( - { - url: `storages:getRules/${name}`, + async () => { + if (field.pattern !== 'editable') { + return null; + } + return apiClient.request({ + url: `storages:getRules/${name}`, + }); }, { refreshDeps: [name], + cacheKey: name, }, ); return (!loading && data?.data) || null;