fix: table column field failed to be actived (#2309)

This commit is contained in:
katherinehhh 2023-07-24 23:59:17 +08:00 committed by GitHub
parent 68976e0ebe
commit d068f9b5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,17 +1,20 @@
import { observer, RecursionField } from '@formily/react'; import { observer, RecursionField } from '@formily/react';
import React from 'react'; import React from 'react';
import { useCollectionManager } from '../../../../collection-manager';
import { useRecord } from '../../../../record-provider'; import { useRecord } from '../../../../record-provider';
export const ColumnFieldProvider = observer( export const ColumnFieldProvider = observer(
(props: { schema: any; basePath: any; children: any }) => { (props: { schema: any; basePath: any; children: any }) => {
const { schema, basePath } = props; const { schema, basePath } = props;
const record = useRecord(); const record = useRecord();
const { getCollectionJoinField } = useCollectionManager();
const fieldSchema = schema.reduceProperties((buf, s) => { const fieldSchema = schema.reduceProperties((buf, s) => {
if (s['x-component'] === 'CollectionField') { if (s['x-component'] === 'CollectionField') {
return s; return s;
} }
return buf; return buf;
}, null); }, null);
if (fieldSchema && record?.__collection) { const collectionField = fieldSchema && getCollectionJoinField(fieldSchema['x-collection-field']);
if (fieldSchema && record?.__collection && ['select', 'multipleSelect'].includes(collectionField.interface)) {
const fieldName = `${record.__collection}.${fieldSchema.name}`; const fieldName = `${record.__collection}.${fieldSchema.name}`;
schema.properties[fieldSchema.name]['x-collection-field'] = fieldName; schema.properties[fieldSchema.name]['x-collection-field'] = fieldName;
return <RecursionField basePath={basePath} schema={schema} onlyRenderProperties />; return <RecursionField basePath={basePath} schema={schema} onlyRenderProperties />;