feat: default value of block template title

This commit is contained in:
chenos 2023-02-18 11:09:55 +08:00
parent 43e52843fa
commit 780f2d556e

View File

@ -14,7 +14,7 @@ import {
Modal,
Select,
Space,
Switch,
Switch
} from 'antd';
import classNames from 'classnames';
import { cloneDeep } from 'lodash';
@ -33,8 +33,9 @@ import {
useActionContext,
useAPIClient,
useCollection,
useCollectionManager,
useCompile,
useDesignable,
useDesignable
} from '..';
import { useSchemaTemplateManager } from '../schema-templates';
import { useBlockTemplateContext } from '../schema-templates/BlockTemplate';
@ -135,7 +136,9 @@ export const SchemaSettings: React.FC<SchemaSettingsProps> & SchemaSettingsNeste
SchemaSettings.Template = (props) => {
const { componentName, collectionName, resourceName } = props;
const { t } = useTranslation();
const { getCollection } = useCollectionManager();
const { dn, setVisible, template, fieldSchema } = useSchemaSettings();
const compile = useCompile();
const api = useAPIClient();
const { dn: tdn } = useBlockTemplateContext();
const { saveAsTemplate, copyTemplateSchema } = useSchemaTemplateManager();
@ -165,6 +168,7 @@ SchemaSettings.Template = (props) => {
<SchemaSettings.Item
onClick={async () => {
setVisible(false);
const { title } = getCollection(collectionName);
const values = await FormDialog(t('Save as template'), () => {
return (
<FormLayout layout={'vertical'}>
@ -176,6 +180,7 @@ SchemaSettings.Template = (props) => {
name: {
title: t('Template name'),
required: true,
default: `${compile(title)}_${t(componentName)}`,
'x-decorator': 'FormItem',
'x-component': 'Input',
},
@ -251,6 +256,8 @@ const findBlockTemplateSchema = (fieldSchema) => {
SchemaSettings.FormItemTemplate = (props) => {
const { insertAdjacentPosition = 'afterBegin', componentName, collectionName, resourceName } = props;
const { t } = useTranslation();
const compile = useCompile();
const { getCollection } = useCollectionManager();
const { dn, setVisible, template, fieldSchema } = useSchemaSettings();
const api = useAPIClient();
const { saveAsTemplate, copyTemplateSchema } = useSchemaTemplateManager();
@ -298,8 +305,13 @@ SchemaSettings.FormItemTemplate = (props) => {
<SchemaSettings.Item
onClick={async () => {
setVisible(false);
const { title } = getCollection(collectionName);
const gridSchema = findGridSchema(fieldSchema);
const values = await FormDialog(t('Save as template'), () => {
const componentTitle = {
FormItem: t('Form'),
ReadPrettyFormItem: t('Details'),
};
return (
<FormLayout layout={'vertical'}>
<SchemaComponent
@ -310,6 +322,7 @@ SchemaSettings.FormItemTemplate = (props) => {
name: {
title: t('Template name'),
required: true,
default: `${compile(title)}_${componentTitle[componentName] || componentName}`,
'x-decorator': 'FormItem',
'x-component': 'Input',
},