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
This commit is contained in:
katherinehhh 2023-07-20 10:56:26 +08:00 committed by GitHub
parent fa2de8e806
commit d2a9e4acee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -70,7 +70,7 @@ const InternalFileManager = (props) => {
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const { getField } = useCollection(); const { getField } = useCollection();
const collectionField = getField(field.props.name); 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 compile = useCompile();
const getFilter = () => { const getFilter = () => {
const targetKey = collectionField?.targetKey || 'id'; const targetKey = collectionField?.targetKey || 'id';
@ -192,7 +192,7 @@ const FileManageReadPretty = connect((props) => {
const fieldNames = useFieldNames(props); const fieldNames = useFieldNames(props);
const { getField } = useCollection(); const { getField } = useCollection();
const collectionField = getField(field.props.name); 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); const showFilePicker = isShowFilePicker(labelUiSchema);
if (showFilePicker) { if (showFilePicker) {
@ -202,4 +202,4 @@ const FileManageReadPretty = connect((props) => {
} }
}); });
export { InternalFileManager, FileManageReadPretty }; export { FileManageReadPretty, InternalFileManager };

View File

@ -37,13 +37,16 @@ export const ReadPrettyInternalViewer: React.FC = observer(
const [record, setRecord] = useState({}); const [record, setRecord] = useState({});
const compile = useCompile(); const compile = useCompile();
const { designable } = useDesignable(); const { designable } = useDesignable();
const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label');
const { snapshot } = useActionContext(); const { snapshot } = useActionContext();
const ellipsisWithTooltipRef = useRef<IEllipsisWithTooltipRef>(); const ellipsisWithTooltipRef = useRef<IEllipsisWithTooltipRef>();
const renderRecords = () => const renderRecords = () =>
toArr(props.value).map((record, index, arr) => { toArr(props.value).map((record, index, arr) => {
const val = toValue(compile(record?.[fieldNames?.label || 'label']), 'N/A'); 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); const text = getLabelFormatValue(compile(labelUiSchema), val, true);
return ( return (
<Fragment key={`${record.id}_${index}`}> <Fragment key={`${record.id}_${index}`}>

View File

@ -5,12 +5,12 @@ import { Tag } from 'antd';
import React from 'react'; import React from 'react';
import { CollectionFieldOptions, useCollectionManager } from '../../../collection-manager'; 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(); const { getCollectionJoinField } = useCollectionManager();
if (!collectionField) { if (!collectionName) {
return; return;
} }
const labelField = getCollectionJoinField(`${collectionField.target}.${label}`) as CollectionFieldOptions; const labelField = getCollectionJoinField(`${collectionName}.${label}`) as CollectionFieldOptions;
return labelField?.uiSchema; return labelField?.uiSchema;
}; };