From d2a9e4aceeef81f0c30d0a302d3d86b494301e33 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 20 Jul 2023 10:56:26 +0800 Subject: [PATCH] fix: the drop-down multiple selection fields are not displayed as title fields when inherited collection (#2257) * fix: inherit field override association field option field * fix: inherit field override association field option field --- .../schema-component/antd/association-field/FileManager.tsx | 6 +++--- .../antd/association-field/InternalViewer.tsx | 5 ++++- .../src/schema-component/antd/association-field/util.ts | 6 +++--- 3 files changed, 10 insertions(+), 7 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 7cf1ddcc1..a8b937d99 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 @@ -70,7 +70,7 @@ const InternalFileManager = (props) => { const [options, setOptions] = useState([]); const { getField } = useCollection(); const collectionField = getField(field.props.name); - const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label'); + const labelUiSchema = useLabelUiSchema(collectionField?.target, fieldNames?.label || 'label'); const compile = useCompile(); const getFilter = () => { const targetKey = collectionField?.targetKey || 'id'; @@ -192,7 +192,7 @@ const FileManageReadPretty = connect((props) => { const fieldNames = useFieldNames(props); const { getField } = useCollection(); const collectionField = getField(field.props.name); - const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label'); + const labelUiSchema = useLabelUiSchema(collectionField?.target, fieldNames?.label || 'label'); const showFilePicker = isShowFilePicker(labelUiSchema); if (showFilePicker) { @@ -202,4 +202,4 @@ const FileManageReadPretty = connect((props) => { } }); -export { InternalFileManager, FileManageReadPretty }; +export { FileManageReadPretty, InternalFileManager }; diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx index c59471628..6d7d46a62 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx @@ -37,13 +37,16 @@ export const ReadPrettyInternalViewer: React.FC = observer( const [record, setRecord] = useState({}); const compile = useCompile(); const { designable } = useDesignable(); - const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label'); const { snapshot } = useActionContext(); const ellipsisWithTooltipRef = useRef(); const renderRecords = () => toArr(props.value).map((record, index, arr) => { const val = toValue(compile(record?.[fieldNames?.label || 'label']), 'N/A'); + const labelUiSchema = useLabelUiSchema( + record?.__collection || collectionField?.target, + fieldNames?.label || 'label', + ); const text = getLabelFormatValue(compile(labelUiSchema), val, true); return ( diff --git a/packages/core/client/src/schema-component/antd/association-field/util.ts b/packages/core/client/src/schema-component/antd/association-field/util.ts index b3ea25230..b3fd4516a 100644 --- a/packages/core/client/src/schema-component/antd/association-field/util.ts +++ b/packages/core/client/src/schema-component/antd/association-field/util.ts @@ -5,12 +5,12 @@ import { Tag } from 'antd'; import React from 'react'; import { CollectionFieldOptions, useCollectionManager } from '../../../collection-manager'; -export const useLabelUiSchema = (collectionField: CollectionFieldOptions, label: string): ISchema => { +export const useLabelUiSchema = (collectionName: string, label: string): ISchema => { const { getCollectionJoinField } = useCollectionManager(); - if (!collectionField) { + if (!collectionName) { return; } - const labelField = getCollectionJoinField(`${collectionField.target}.${label}`) as CollectionFieldOptions; + const labelField = getCollectionJoinField(`${collectionName}.${label}`) as CollectionFieldOptions; return labelField?.uiSchema; };