fix(Calendar): ensur to get correct gridInitializer when adding a new… (#1425)

* fix(Calendar): ensur to get correct gridInitializer when adding a new tab (#1241)

* perf: use useMemo
This commit is contained in:
被雨水过滤的空气-Rairn 2023-03-19 10:52:56 +08:00 committed by GitHub
parent c68caf105e
commit 9ada0e37d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 63 deletions

View File

@ -1,5 +1,5 @@
import { useForm } from '@formily/react'; import { useForm } from '@formily/react';
import React from 'react'; import React, { useMemo } from 'react';
import { SchemaComponent, useActionContext, useDesignable, useRecordIndex } from '../..'; import { SchemaComponent, useActionContext, useDesignable, useRecordIndex } from '../..';
export const TabPaneInitializers = (props?: any) => { export const TabPaneInitializers = (props?: any) => {
@ -46,69 +46,67 @@ export const TabPaneInitializers = (props?: any) => {
}, },
}; };
}; };
return ( const schema = useMemo(() => {
<SchemaComponent return {
schema={{ type: 'void',
type: 'void', properties: {
properties: { action1: {
action1: { type: 'void',
type: 'void', 'x-component': 'Action',
'x-component': 'Action', 'x-component-props': {
'x-component-props': { icon: 'PlusOutlined',
icon: 'PlusOutlined', style: {
style: { borderColor: 'rgb(241, 139, 98)',
borderColor: 'rgb(241, 139, 98)', color: 'rgb(241, 139, 98)',
color: 'rgb(241, 139, 98)',
},
type: 'dashed',
}, },
title: '{{t("Add tab")}}', type: 'dashed',
properties: { },
drawer1: { title: '{{t("Add tab")}}',
'x-decorator': 'Form', properties: {
'x-component': 'Action.Modal', drawer1: {
'x-component-props': { 'x-decorator': 'Form',
width: 520, 'x-component': 'Action.Modal',
'x-component-props': {
width: 520,
},
type: 'void',
title: '{{t("Add tab")}}',
properties: {
title: {
title: '{{t("Tab name")}}',
required: true,
'x-component': 'Input',
'x-decorator': 'FormItem',
}, },
type: 'void', icon: {
title: '{{t("Add tab")}}', title: '{{t("Icon")}}',
properties: { 'x-component': 'IconPicker',
title: { 'x-decorator': 'FormItem',
title: '{{t("Tab name")}}', },
required: true, footer: {
'x-component': 'Input', 'x-component': 'Action.Modal.Footer',
'x-decorator': 'FormItem', type: 'void',
}, properties: {
icon: { cancel: {
title: '{{t("Icon")}}', title: '{{t("Cancel")}}',
'x-component': 'IconPicker', 'x-component': 'Action',
'x-decorator': 'FormItem', 'x-component-props': {
}, useAction: () => {
footer: { const ctx = useActionContext();
'x-component': 'Action.Modal.Footer', return {
type: 'void', async run() {
properties: { ctx.setVisible(false);
cancel: { },
title: '{{t("Cancel")}}', };
'x-component': 'Action',
'x-component-props': {
useAction: () => {
const ctx = useActionContext();
return {
async run() {
ctx.setVisible(false);
},
};
},
}, },
}, },
submit: { },
title: '{{t("Submit")}}', submit: {
'x-component': 'Action', title: '{{t("Submit")}}',
'x-component-props': { 'x-component': 'Action',
type: 'primary', 'x-component-props': {
useAction: useSubmitAction, type: 'primary',
}, useAction: useSubmitAction,
}, },
}, },
}, },
@ -117,9 +115,10 @@ export const TabPaneInitializers = (props?: any) => {
}, },
}, },
}, },
}} },
/> };
); }, []);
return <SchemaComponent schema={schema} />;
}; };
export const TabPaneInitializersForCreateFormBlock = (props) => { export const TabPaneInitializersForCreateFormBlock = (props) => {

View File

@ -1008,6 +1008,9 @@ export const createCalendarBlockSchema = (options) => {
'x-component': 'Tabs', 'x-component': 'Tabs',
'x-component-props': {}, 'x-component-props': {},
'x-initializer': 'TabPaneInitializers', 'x-initializer': 'TabPaneInitializers',
'x-initializer-props': {
gridInitializer: 'RecordBlockInitializers',
},
properties: { properties: {
tab1: { tab1: {
type: 'void', type: 'void',