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
This commit is contained in:
Junyi
2024-10-22 14:19:03 +08:00
committed by GitHub
parent f3ef42968e
commit dc34e027e3
2 changed files with 12 additions and 9 deletions
@@ -203,7 +203,7 @@ const Rules: Record<string, RuleFunction> = {
type RuleFunction = (file: UploadFile, options: any) => string | null;
function validate(file, rules: Record<string, any>) {
export function validate(file, rules: Record<string, any>) {
if (!rules) {
return null;
}
@@ -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<any>();
const { loading, data } = useRequest<any>(
async () => {
if (field.pattern !== 'editable') {
return null;
}
return apiClient.request({
url: `storages:getRules/${name}`,
});
const { loading, data, run } = useRequest<any>(
{
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;
}