fix(client): fix typo in upload component (#5460)
Some checks are pending
Build docker image / build-and-push (push) Waiting to run
Build pro image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase frontEnd test / frontend-test (18) (push) Waiting to run

* fix(client): fix typo in upload component

* fix(plugin-file-manager): fix rule hook
This commit is contained in:
Junyi 2024-10-19 15:13:46 +08:00 committed by GitHub
parent 72867c6acb
commit d553e51b51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 12 deletions

View File

@ -250,7 +250,7 @@ function AttachmentListItem(props) {
{item}
</a>
) : (
<span className={`${prefixCls}-span`}>{item}3</span>
<span className={`${prefixCls}-span`}>{item}</span>
);
const content = (
@ -358,6 +358,7 @@ export function Uploader({ rules, ...props }: UploadProps) {
const uploadProps = useUploadProps(props);
const beforeUpload = useBeforeUpload(rules);
console.log('----------', pendingList);
useEffect(() => {
if (pendingList.length) {

View File

@ -59,8 +59,11 @@ export class AttachmentFileTypes {
*/
export const attachmentFileTypes = new AttachmentFileTypes();
export function matchMimetype(file: FileModel, type: string) {
if (file.mimetype) {
export function matchMimetype(file: FileModel | UploadFile<any>, type: string) {
if ('originFileObj' in file) {
return match(file.type, type);
}
if ('mimetype' in file) {
return match(file.mimetype, type);
}
if (file.url) {
@ -223,7 +226,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;
}

View File

@ -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;
}