From 9ada0e37d61ae838243920d15228d7fba3cb9240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rairn?= <958414905@qq.com> Date: Sun, 19 Mar 2023 10:52:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(Calendar):=20ensur=20to=20get=20correct=20g?= =?UTF-8?q?ridInitializer=20when=20adding=20a=20new=E2=80=A6=20(#1425)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(Calendar): ensur to get correct gridInitializer when adding a new tab (#1241) * perf: use useMemo --- .../buttons/TabPaneInitializers.tsx | 125 +++++++++--------- .../client/src/schema-initializer/utils.ts | 3 + 2 files changed, 65 insertions(+), 63 deletions(-) diff --git a/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx index d7546f048..b34a6454c 100644 --- a/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx @@ -1,5 +1,5 @@ import { useForm } from '@formily/react'; -import React from 'react'; +import React, { useMemo } from 'react'; import { SchemaComponent, useActionContext, useDesignable, useRecordIndex } from '../..'; export const TabPaneInitializers = (props?: any) => { @@ -46,69 +46,67 @@ export const TabPaneInitializers = (props?: any) => { }, }; }; - return ( - { + return { + type: 'void', + properties: { + action1: { + type: 'void', + 'x-component': 'Action', + 'x-component-props': { + icon: 'PlusOutlined', + style: { + borderColor: 'rgb(241, 139, 98)', + color: 'rgb(241, 139, 98)', }, - title: '{{t("Add tab")}}', - properties: { - drawer1: { - 'x-decorator': 'Form', - 'x-component': 'Action.Modal', - 'x-component-props': { - width: 520, + type: 'dashed', + }, + title: '{{t("Add tab")}}', + properties: { + drawer1: { + 'x-decorator': 'Form', + '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', - title: '{{t("Add tab")}}', - properties: { - title: { - title: '{{t("Tab name")}}', - required: true, - 'x-component': 'Input', - 'x-decorator': 'FormItem', - }, - icon: { - title: '{{t("Icon")}}', - 'x-component': 'IconPicker', - 'x-decorator': 'FormItem', - }, - footer: { - 'x-component': 'Action.Modal.Footer', - type: 'void', - properties: { - cancel: { - title: '{{t("Cancel")}}', - 'x-component': 'Action', - 'x-component-props': { - useAction: () => { - const ctx = useActionContext(); - return { - async run() { - ctx.setVisible(false); - }, - }; - }, + icon: { + title: '{{t("Icon")}}', + 'x-component': 'IconPicker', + 'x-decorator': 'FormItem', + }, + footer: { + 'x-component': 'Action.Modal.Footer', + type: 'void', + properties: { + cancel: { + title: '{{t("Cancel")}}', + 'x-component': 'Action', + 'x-component-props': { + useAction: () => { + const ctx = useActionContext(); + return { + async run() { + ctx.setVisible(false); + }, + }; }, }, - submit: { - title: '{{t("Submit")}}', - 'x-component': 'Action', - 'x-component-props': { - type: 'primary', - useAction: useSubmitAction, - }, + }, + submit: { + title: '{{t("Submit")}}', + 'x-component': 'Action', + 'x-component-props': { + type: 'primary', + useAction: useSubmitAction, }, }, }, @@ -117,9 +115,10 @@ export const TabPaneInitializers = (props?: any) => { }, }, }, - }} - /> - ); + }, + }; + }, []); + return ; }; export const TabPaneInitializersForCreateFormBlock = (props) => { diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 36bc962ba..156254738 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -1008,6 +1008,9 @@ export const createCalendarBlockSchema = (options) => { 'x-component': 'Tabs', 'x-component-props': {}, 'x-initializer': 'TabPaneInitializers', + 'x-initializer-props': { + gridInitializer: 'RecordBlockInitializers', + }, properties: { tab1: { type: 'void',