fix: auto generate reverseField uiSchema title

This commit is contained in:
chenos 2022-03-10 15:57:14 +08:00
parent 683b63826a
commit ffe3463dc2
2 changed files with 23 additions and 17 deletions

View File

@ -7,6 +7,7 @@ import { cloneDeep } from 'lodash';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useRequest } from '../../api-client'; import { useRequest } from '../../api-client';
import { useRecord } from '../../record-provider';
import { ActionContext, SchemaComponent, useCompile } from '../../schema-component'; import { ActionContext, SchemaComponent, useCompile } from '../../schema-component';
import { useCreateAction } from '../action-hooks'; import { useCreateAction } from '../action-hooks';
import { useCollectionManager } from '../hooks'; import { useCollectionManager } from '../hooks';
@ -78,10 +79,12 @@ const useCreateCollectionField = () => {
const form = useForm(); const form = useForm();
const { run } = useCreateAction(); const { run } = useCreateAction();
const { refreshCM } = useCollectionManager(); const { refreshCM } = useCollectionManager();
const { title } = useRecord();
return { return {
async run() { async run() {
await form.submit(); await form.submit();
const options = form?.values?.uiSchema?.enum?.slice() || []; const options = form?.values?.uiSchema?.enum?.slice() || [];
if (options?.length) {
form.setValuesIn( form.setValuesIn(
'uiSchema.enum', 'uiSchema.enum',
options.map((option) => { options.map((option) => {
@ -91,7 +94,10 @@ const useCreateCollectionField = () => {
}; };
}), }),
); );
console.log('form.values', form.values); }
if (form?.values?.interface === 'linkTo' && title) {
form.setValuesIn('reverseField.uiSchema.title', title);
}
await run(); await run();
await refreshCM(); await refreshCM();
}, },

View File

@ -71,13 +71,13 @@ export const linkTo: IField = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Select', 'x-component': 'Select',
}, },
'reverseField.uiSchema.title': { // 'reverseField.uiSchema.title': {
type: 'string', // type: 'string',
title: '{{t("Reverse field display name")}}', // title: '{{t("Reverse field display name")}}',
required: true, // // required: true,
'x-decorator': 'FormItem', // 'x-decorator': 'FormItem',
'x-component': 'Input', // 'x-component': 'Input',
}, // },
// 'uiSchema.x-component-props.fieldNames.label': { // 'uiSchema.x-component-props.fieldNames.label': {
// type: 'string', // type: 'string',
// title: '要显示的标题字段', // title: '要显示的标题字段',