From 64dc385eb3378f9baabd39538ad8975b3cc7eace Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Mon, 18 Sep 2023 21:10:35 +0800 Subject: [PATCH] fix: file association field cannot set file manager as field component (#2672) --- .../antd/association-field/FileManager.tsx | 25 +++++++++++++------ .../antd/table-v2/Table.Column.Designer.tsx | 3 ++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/association-field/FileManager.tsx b/packages/core/client/src/schema-component/antd/association-field/FileManager.tsx index 7958ea5f8..e81bdeb1f 100644 --- a/packages/core/client/src/schema-component/antd/association-field/FileManager.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/FileManager.tsx @@ -12,7 +12,7 @@ import { TableSelectorParamsProvider, useTableSelectorProps as useTsp, } from '../../../block-provider/TableSelectorProvider'; -import { CollectionProvider, useCollection } from '../../../collection-manager'; +import { CollectionProvider, useCollection, useCollectionManager } from '../../../collection-manager'; import { useCompile } from '../../hooks'; import { ActionContextProvider } from '../action'; import { FileSelector, Preview } from '../preview'; @@ -20,12 +20,17 @@ import { ReadPrettyInternalViewer } from './InternalViewer'; import { useFieldNames, useInsertSchema } from './hooks'; import schema from './schema'; import { flatData, getLabelFormatValue, isShowFilePicker, useLabelUiSchema } from './util'; +import { EllipsisWithTooltip } from '../input'; const useTableSelectorProps = () => { const field: any = useField(); - const { multiple, options = [], setSelectedRows, selectedRows: rcSelectRows = [], onChange } = useContext( - RecordPickerContext, - ); + const { + multiple, + options = [], + setSelectedRows, + selectedRows: rcSelectRows = [], + onChange, + } = useContext(RecordPickerContext); const { onRowSelectionChange, rowKey = 'id', ...others } = useTsp(); const { setVisible } = useActionContext(); return { @@ -184,15 +189,19 @@ const InternalFileManager = (props) => { }; const FileManageReadPretty = connect((props) => { - const field: any = useField(); const fieldNames = useFieldNames(props); + const fieldSchema = useFieldSchema(); const { getField } = useCollection(); - const collectionField = getField(field.props.name); + const { getCollectionJoinField } = useCollectionManager(); + const collectionField = getField(fieldSchema.name) || getCollectionJoinField(fieldSchema['x-collection-field']); const labelUiSchema = useLabelUiSchema(collectionField?.target, fieldNames?.label || 'label'); const showFilePicker = isShowFilePicker(labelUiSchema); - if (showFilePicker) { - return collectionField ? : null; + return ( + + {collectionField ? : null} + + ); } else { return ; } diff --git a/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx b/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx index 2e30f26a0..af948f9b6 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx @@ -264,8 +264,9 @@ export const TableColumnDesigner = (props) => { readOnlyMode === 'read-pretty' ? [ { label: t('Title'), value: 'Select' }, + isFileField && { label: t('File manager'), value: 'FileManager' }, { label: t('Tag'), value: 'Tag' }, - ] + ].filter(Boolean) : fieldModeOptions } value={fieldMode}