import { ISchema, useField, useFieldSchema } from '@formily/react'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { useCollectionManager } from '../../../collection-manager'; import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; import { useCompile, useDesignable } from '../../hooks'; const useLabelFields = (collectionName?: any) => { if (!collectionName) { return []; } const compile = useCompile(); const { getCollectionFields } = useCollectionManager(); const targetFields = getCollectionFields(collectionName); return targetFields ?.filter?.((field) => field?.interface && !field?.target && field.type !== 'boolean') ?.map?.((field) => { return { value: field.name, label: compile(field?.uiSchema?.title || field.name), }; }); }; export const TableColumnDesigner = (props) => { const { uiSchema, fieldSchema, collectionField } = props; const field = useField(); const { t } = useTranslation(); const columnSchema = useFieldSchema(); const { dn } = useDesignable(); const fieldNames = fieldSchema?.['x-component-props']?.['fieldNames'] || uiSchema?.['x-component-props']?.['fieldNames']; const options = useLabelFields(collectionField?.target); return ( { if (title) { field.title = title; columnSchema.title = title; dn.emit('patch', { schema: { 'x-uid': columnSchema['x-uid'], title: columnSchema.title, }, }); } dn.refresh(); }} /> {collectionField?.interface === 'linkTo' && ( { const fieldNames = { ...fieldSchema['x-component-props']['fieldNames'], label, }; fieldSchema['x-component-props']['fieldNames'] = fieldNames; field.query(`.*.${fieldSchema.name}`).take((f) => { f.componentProps.fieldNames = fieldNames; }); dn.emit('patch', { schema: { 'x-uid': fieldSchema['x-uid'], 'x-component-props': { fieldNames, }, }, }); dn.refresh(); }} /> )} ); };