fix(client): tab pane initializers for create form block

This commit is contained in:
chenos 2022-10-13 19:52:04 +08:00
parent ca2a6fecf0
commit 929a4f848a
3 changed files with 53 additions and 46 deletions

View File

@ -1,8 +1,8 @@
import { useForm } from '@formily/react';
import React from 'react';
import { SchemaComponent, useActionContext, useDesignable } from '../..';
import { SchemaComponent, useActionContext, useDesignable, useRecordIndex } from '../..';
export const TabPaneInitializers = () => {
export const TabPaneInitializers = (props?: any) => {
const { designable, insertBeforeEnd } = useDesignable();
if (!designable) {
return null;
@ -10,6 +10,7 @@ export const TabPaneInitializers = () => {
const useSubmitAction = () => {
const form = useForm();
const ctx = useActionContext();
const index = useRecordIndex();
return {
async run() {
await form.submit();
@ -26,7 +27,8 @@ export const TabPaneInitializers = () => {
grid: {
type: 'void',
'x-component': 'Grid',
'x-initializer': 'RecordBlockInitializers',
'x-initializer':
props.isCreate || index === null ? 'CreateFormBlockInitializers' : 'RecordBlockInitializers',
properties: {},
},
},
@ -111,3 +113,7 @@ export const TabPaneInitializers = () => {
/>
);
};
export const TabPaneInitializersForCreateFormBlock = () => {
return <TabPaneInitializers isCreate />;
};

View File

@ -16,3 +16,4 @@ export * from './TableActionInitializers';
export * from './TableColumnInitializers';
export * from './TableSelectorInitializers';
export * from './TabPaneInitializers';

View File

@ -1,46 +1,45 @@
import React from "react";
import { ActionInitializer } from "./ActionInitializer";
import React from 'react';
import { ActionInitializer } from './ActionInitializer';
export const CreateActionInitializer = (props) => {
const schema = {
type: 'void',
title: '{{ t("Add new") }}',
'x-action': 'create',
'x-designer': 'Action.Designer',
'x-component': 'Action',
'x-component-props': {
icon: 'PlusOutlined',
openMode: 'drawer',
type: 'primary',
},
properties: {
drawer: {
type: 'void',
title: '{{ t("Add record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'TabPaneInitializers',
properties: {
tab1: {
type: 'void',
title: '{{t("Add new")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
type: 'void',
'x-component': 'Grid',
'x-initializer': 'CreateFormBlockInitializers',
properties: {},
},
const schema = {
type: 'void',
title: '{{ t("Add new") }}',
'x-action': 'create',
'x-designer': 'Action.Designer',
'x-component': 'Action',
'x-component-props': {
icon: 'PlusOutlined',
openMode: 'drawer',
type: 'primary',
},
properties: {
drawer: {
type: 'void',
title: '{{ t("Add record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'TabPaneInitializersForCreateFormBlock',
properties: {
tab1: {
type: 'void',
title: '{{t("Add new")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
type: 'void',
'x-component': 'Grid',
'x-initializer': 'CreateFormBlockInitializers',
properties: {},
},
},
},
@ -48,6 +47,7 @@ export const CreateActionInitializer = (props) => {
},
},
},
};
return <ActionInitializer {...props} schema={schema} />;
},
};
return <ActionInitializer {...props} schema={schema} />;
};