From dc34e027e368a6f5dd403dd3966887d06c5002f5 Mon Sep 17 00:00:00 2001 From: Junyi Date: Tue, 22 Oct 2024 14:19:03 +0800 Subject: [PATCH] fix(client): fix typo in upload component (#5460) (#5479) * fix(client): fix typo in upload component (#5460) * fix(client): fix typo in upload component * fix(plugin-file-manager): fix rule hook * fix(plugin-file-manager): fix useless log --- .../schema-component/antd/upload/shared.ts | 2 +- .../src/client/hooks/useStorageRules.ts | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/upload/shared.ts b/packages/core/client/src/schema-component/antd/upload/shared.ts index c979136edc..ca195a7ffe 100644 --- a/packages/core/client/src/schema-component/antd/upload/shared.ts +++ b/packages/core/client/src/schema-component/antd/upload/shared.ts @@ -203,7 +203,7 @@ const Rules: Record = { type RuleFunction = (file: UploadFile, options: any) => string | null; -function validate(file, rules: Record) { +export function validate(file, rules: Record) { if (!rules) { return null; } 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 942f5b812b..e40f1cb927 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,6 +7,7 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ +import { useEffect } from 'react'; import { useField } from '@formily/react'; import { useAPIClient, useCollectionField, useCollectionManager, useRequest } from '@nocobase/client'; @@ -14,20 +15,22 @@ export function useStorageRules(storage) { const name = storage ?? ''; const apiClient = useAPIClient(); const field = useField(); - const { loading, data } = useRequest( - async () => { - if (field.pattern !== 'editable') { - return null; - } - return apiClient.request({ - url: `storages:getRules/${name}`, - }); + const { loading, data, run } = useRequest( + { + url: `storages:getRules/${name}`, }, { + manual: true, refreshDeps: [name], cacheKey: name, }, ); + useEffect(() => { + if (field.pattern !== 'editable') { + return; + } + run(); + }, [field.pattern, run]); return (!loading && data?.data) || null; }