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, TableSelectorParamsProvider,
useTableSelectorProps as useTsp, useTableSelectorProps as useTsp,
} from '../../../block-provider/TableSelectorProvider'; } from '../../../block-provider/TableSelectorProvider';
import { CollectionProvider, useCollection } from '../../../collection-manager'; import { CollectionProvider, useCollection, useCollectionManager } from '../../../collection-manager';
import { useCompile } from '../../hooks'; import { useCompile } from '../../hooks';
import { ActionContextProvider } from '../action'; import { ActionContextProvider } from '../action';
import { FileSelector, Preview } from '../preview'; import { FileSelector, Preview } from '../preview';
@ -20,12 +20,17 @@ import { ReadPrettyInternalViewer } from './InternalViewer';
import { useFieldNames, useInsertSchema } from './hooks'; import { useFieldNames, useInsertSchema } from './hooks';
import schema from './schema'; import schema from './schema';
import { flatData, getLabelFormatValue, isShowFilePicker, useLabelUiSchema } from './util'; import { flatData, getLabelFormatValue, isShowFilePicker, useLabelUiSchema } from './util';
import { EllipsisWithTooltip } from '../input';
const useTableSelectorProps = () => { const useTableSelectorProps = () => {
const field: any = useField(); const field: any = useField();
const { multiple, options = [], setSelectedRows, selectedRows: rcSelectRows = [], onChange } = useContext( const {
RecordPickerContext, multiple,
); options = [],
setSelectedRows,
selectedRows: rcSelectRows = [],
onChange,
} = useContext(RecordPickerContext);
const { onRowSelectionChange, rowKey = 'id', ...others } = useTsp(); const { onRowSelectionChange, rowKey = 'id', ...others } = useTsp();
const { setVisible } = useActionContext(); const { setVisible } = useActionContext();
return { return {
@ -184,15 +189,19 @@ const InternalFileManager = (props) => {
}; };
const FileManageReadPretty = connect((props) => { const FileManageReadPretty = connect((props) => {
const field: any = useField();
const fieldNames = useFieldNames(props); const fieldNames = useFieldNames(props);
const fieldSchema = useFieldSchema();
const { getField } = useCollection(); 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 labelUiSchema = useLabelUiSchema(collectionField?.target, fieldNames?.label || 'label');
const showFilePicker = isShowFilePicker(labelUiSchema); const showFilePicker = isShowFilePicker(labelUiSchema);
if (showFilePicker) { if (showFilePicker) {
return collectionField ? <Preview {...props} fieldNames={fieldNames} /> : null; return (
<EllipsisWithTooltip ellipsis>
{collectionField ? <Preview {...props} fieldNames={fieldNames} /> : null}
</EllipsisWithTooltip>
);
} else { } else {
return <ReadPrettyInternalViewer {...props} />; return <ReadPrettyInternalViewer {...props} />;
} }

View File

@ -264,8 +264,9 @@ export const TableColumnDesigner = (props) => {
readOnlyMode === 'read-pretty' readOnlyMode === 'read-pretty'
? [ ? [
{ label: t('Title'), value: 'Select' }, { label: t('Title'), value: 'Select' },
isFileField && { label: t('File manager'), value: 'FileManager' },
{ label: t('Tag'), value: 'Tag' }, { label: t('Tag'), value: 'Tag' },
] ].filter(Boolean)
: fieldModeOptions : fieldModeOptions
} }
value={fieldMode} value={fieldMode}