fix: auto generate reverseField uiSchema title
This commit is contained in:
parent
683b63826a
commit
ffe3463dc2
@ -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,20 +79,25 @@ 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() || [];
|
||||||
form.setValuesIn(
|
if (options?.length) {
|
||||||
'uiSchema.enum',
|
form.setValuesIn(
|
||||||
options.map((option) => {
|
'uiSchema.enum',
|
||||||
return {
|
options.map((option) => {
|
||||||
value: uid(),
|
return {
|
||||||
...option,
|
value: uid(),
|
||||||
};
|
...option,
|
||||||
}),
|
};
|
||||||
);
|
}),
|
||||||
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();
|
||||||
},
|
},
|
||||||
|
@ -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: '要显示的标题字段',
|
||||||
|
Loading…
Reference in New Issue
Block a user