From 796d4d0c2f1f8b818759187d0140c4cb6b2283bd Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Fri, 26 Apr 2024 16:34:04 +0800 Subject: [PATCH] chore: attachement field --- packages/core/client/src/common/useFieldComponentName.tsx | 2 +- .../FileManager/uploadAttachmentComponentFieldSettings.tsx | 6 ++++-- .../schema-component/antd/form-item/FormItem.Settings.tsx | 5 +++-- .../client/__e2e__/fields/attachment/schemaSettings.test.ts | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/common/useFieldComponentName.tsx b/packages/core/client/src/common/useFieldComponentName.tsx index 61b5edf926..cdb05c506a 100644 --- a/packages/core/client/src/common/useFieldComponentName.tsx +++ b/packages/core/client/src/common/useFieldComponentName.tsx @@ -1,8 +1,8 @@ import { Field } from '@formily/core'; import { useField, useFieldSchema } from '@formily/react'; +import { useCollectionField } from '../data-source/collection-field/CollectionFieldProvider'; import { useIsFileField } from '../schema-component/antd/form-item/FormItem.Settings'; import { useColumnSchema } from '../schema-component/antd/table-v2/Table.Column.Decorator'; -import { useCollectionField } from '../data-source/collection-field/CollectionFieldProvider'; export function useFieldComponentName(): string { const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema(); diff --git a/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx index 25a6db2f8b..58aa294bb3 100644 --- a/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/FileManager/uploadAttachmentComponentFieldSettings.tsx @@ -2,7 +2,7 @@ import { Field } from '@formily/core'; import { useField, useFieldSchema } from '@formily/react'; import { useTranslation } from 'react-i18next'; import { SchemaSettings } from '../../../../application/schema-settings/SchemaSettings'; -import { useDesignable } from '../../../../schema-component'; +import { useColumnSchema, useDesignable } from '../../../../schema-component'; import { useIsFieldReadPretty } from '../../../../schema-component/antd/form-item/FormItem.Settings'; export const uploadAttachmentComponentFieldSettings = new SchemaSettings({ @@ -12,8 +12,10 @@ export const uploadAttachmentComponentFieldSettings = new SchemaSettings({ name: 'size', type: 'select', useVisible() { + const { fieldSchema: tableColumnSchema } = useColumnSchema(); const readPretty = useIsFieldReadPretty(); - return readPretty; + const isInTable = tableColumnSchema?.parent?.['x-component'] === 'TableV2.Column'; + return readPretty && !isInTable; }, useComponentProps() { const { t } = useTranslation(); diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx index e3e9f5df69..86d0ac0945 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.Settings.tsx @@ -12,6 +12,7 @@ import { useCollectionManager_deprecated, useCollection_deprecated, } from '../../../collection-manager'; +import { useCollectionManager } from '../../../data-source'; import { useFlag } from '../../../flag-provider'; import { useRecord } from '../../../record-provider'; import { useColumnSchema } from '../../../schema-component/antd/table-v2/Table.Column.Decorator'; @@ -979,9 +980,9 @@ export function useIsAssociationField() { } export function useIsFileField() { - const { getCollection } = useCollectionManager_deprecated(); + const cm = useCollectionManager(); const collectionField = useFormItemCollectionField(); - const targetCollection = getCollection(collectionField?.target); + const targetCollection = cm.getCollection(collectionField?.target); const isFileField = isFileCollection(targetCollection as any); return isFileField; } diff --git a/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/attachment/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/attachment/schemaSettings.test.ts index d6fc5b61ec..4a3b3bde06 100644 --- a/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/attachment/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-collection-manager/src/client/__e2e__/fields/attachment/schemaSettings.test.ts @@ -281,6 +281,7 @@ test.describe('table column & table', () => { await showSettingsMenu(page, 'attachment'); }, supportedOptions: ['Custom column title', 'Column width', 'Delete'], + unsupportedOptions: ['Size'], }); }); });