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 { useTranslation } from 'react-i18next';
import { useRequest } from '../../api-client';
import { useRecord } from '../../record-provider';
import { ActionContext, SchemaComponent, useCompile } from '../../schema-component';
import { useCreateAction } from '../action-hooks';
import { useCollectionManager } from '../hooks';
@ -78,10 +79,12 @@ const useCreateCollectionField = () => {
const form = useForm();
const { run } = useCreateAction();
const { refreshCM } = useCollectionManager();
const { title } = useRecord();
return {
async run() {
await form.submit();
const options = form?.values?.uiSchema?.enum?.slice() || [];
if (options?.length) {
form.setValuesIn(
'uiSchema.enum',
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 refreshCM();
},

View File

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