fix: file association field cannot set file manager as field component (#2672)

This commit is contained in:
katherinehhh 2023-09-18 21:10:35 +08:00 committed by GitHub
parent a53a350f95
commit 64dc385eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View File

@ -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 ? <Preview {...props} fieldNames={fieldNames} /> : null;
return (
<EllipsisWithTooltip ellipsis>
{collectionField ? <Preview {...props} fieldNames={fieldNames} /> : null}
</EllipsisWithTooltip>
);
} else {
return <ReadPrettyInternalViewer {...props} />;
}

View File

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