From 0c48463e531955ebc4a7aeb2f2b843ff60c85f31 Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 5 Mar 2022 23:47:44 +0800 Subject: [PATCH] feat(client): action schema settings --- .../antd/action/Action.Designer.tsx | 78 +++++++++++++++++++ .../antd/action/Action.Link.tsx | 4 +- .../antd/action/Action.Modal.tsx | 2 +- .../schema-component/antd/action/Action.tsx | 22 +----- .../TableRecordActionInitializers.tsx | 14 ++-- .../src/schema-settings/SchemaSettings.tsx | 37 ++++++++- 6 files changed, 127 insertions(+), 30 deletions(-) create mode 100644 packages/client/src/schema-component/antd/action/Action.Designer.tsx diff --git a/packages/client/src/schema-component/antd/action/Action.Designer.tsx b/packages/client/src/schema-component/antd/action/Action.Designer.tsx new file mode 100644 index 000000000..2479bbca9 --- /dev/null +++ b/packages/client/src/schema-component/antd/action/Action.Designer.tsx @@ -0,0 +1,78 @@ +import { ISchema, useField, useFieldSchema } from '@formily/react'; +import React from 'react'; +import { useDesignable } from '../..'; +import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; + +export const ActionDesigner = () => { + const initialValue = {}; + const field = useField(); + const fieldSchema = useFieldSchema(); + const { dn } = useDesignable(); + const isPopupAction = ['create', 'update', 'view'].includes(fieldSchema['x-action'] || ''); + return ( + + { + if (title) { + fieldSchema.title = title; + field.title = title; + dn.emit('patch', { + schema: { + ['x-uid']: fieldSchema['x-uid'], + title, + }, + }); + dn.refresh(); + } + }} + /> + {isPopupAction && ( + { + field.componentProps.openMode = value; + fieldSchema['x-component-props']['openMode'] = value; + dn.emit('patch', { + schema: { + 'x-uid': fieldSchema['x-uid'], + 'x-component-props': { + openMode: value, + }, + }, + }); + dn.refresh(); + }} + /> + )} + + { + return s['x-component'] === 'Space' || s['x-component'] === 'ActionBar'; + }} + /> + + ); +}; diff --git a/packages/client/src/schema-component/antd/action/Action.Link.tsx b/packages/client/src/schema-component/antd/action/Action.Link.tsx index e25cdc3b3..bdd7f0609 100644 --- a/packages/client/src/schema-component/antd/action/Action.Link.tsx +++ b/packages/client/src/schema-component/antd/action/Action.Link.tsx @@ -4,7 +4,5 @@ import Action from './Action'; import { ComposedAction } from './types'; export const ActionLink: ComposedAction = observer((props: any) => { - return ; + return ; }); - -export default ActionLink; diff --git a/packages/client/src/schema-component/antd/action/Action.Modal.tsx b/packages/client/src/schema-component/antd/action/Action.Modal.tsx index 42a2819b1..825d24361 100644 --- a/packages/client/src/schema-component/antd/action/Action.Modal.tsx +++ b/packages/client/src/schema-component/antd/action/Action.Modal.tsx @@ -22,7 +22,7 @@ export const ActionModal: ComposedActionDrawer = observer((props) => { {createPortal( { ); }); -Action.Designer = () => { - return ( - - { - return s['x-component'] === 'Space' || s['x-component'] === 'ActionBar'; - }} - /> - - ); -}; - -Action.Link = observer((props) => { - return ; -}); - +Action.Link = ActionLink; +Action.Designer = ActionDesigner; Action.Drawer = ActionDrawer; Action.Modal = ActionModal; Action.Container = ActionContainer; diff --git a/packages/client/src/schema-initializer/Initializers/TableRecordActionInitializers.tsx b/packages/client/src/schema-initializer/Initializers/TableRecordActionInitializers.tsx index 163a8203c..623621370 100644 --- a/packages/client/src/schema-initializer/Initializers/TableRecordActionInitializers.tsx +++ b/packages/client/src/schema-initializer/Initializers/TableRecordActionInitializers.tsx @@ -47,11 +47,13 @@ export const TableRecordActionInitializers = (props: any) => { 'x-action': 'view', 'x-designer': 'Action.Designer', 'x-component': 'Action.Link', - 'x-component-props': {}, + 'x-component-props': { + openMode: 'drawer', + }, properties: { drawer: { type: 'void', - 'x-component': 'Action.Drawer', + 'x-component': 'Action.Container', 'x-component-props': { className: 'nb-action-popup', }, @@ -95,7 +97,9 @@ export const TableRecordActionInitializers = (props: any) => { 'x-action': 'update', 'x-designer': 'Action.Designer', 'x-component': 'Action.Link', - 'x-component-props': {}, + 'x-component-props': { + openMode: 'drawer', + }, properties: { drawer: { type: 'void', @@ -103,7 +107,7 @@ export const TableRecordActionInitializers = (props: any) => { 'x-decorator-props': { useValues: '{{ cm.useValuesFromRecord }}', }, - 'x-component': 'Action.Drawer', + 'x-component': 'Action.Container', title: '{{ t("Edit record") }}', properties: { grid: { @@ -114,7 +118,7 @@ export const TableRecordActionInitializers = (props: any) => { }, footer: { type: 'void', - 'x-component': 'Action.Drawer.Footer', + 'x-component': 'Action.Container.Footer', properties: { actions: { type: 'void', diff --git a/packages/client/src/schema-settings/SchemaSettings.tsx b/packages/client/src/schema-settings/SchemaSettings.tsx index 11b00c410..696df88be 100644 --- a/packages/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/client/src/schema-settings/SchemaSettings.tsx @@ -1,10 +1,11 @@ +import { FormDialog, FormLayout } from '@formily/antd'; import { GeneralField } from '@formily/core'; -import { ISchema, Schema } from '@formily/react'; +import { ISchema, Schema, SchemaOptionsContext } from '@formily/react'; import { uid } from '@formily/shared'; import { Dropdown, Menu, MenuItemProps, Modal, Select } from 'antd'; import React, { createContext, useContext, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { ActionContext, Designable, SchemaComponent } from '..'; +import { ActionContext, Designable, SchemaComponent, SchemaComponentOptions, useActionContext } from '..'; interface SchemaSettingsProps { title?: any; @@ -86,7 +87,6 @@ SchemaSettings.Item = (props) => { { - // info.domEvent.preventDefault(); info.domEvent.stopPropagation(); props?.onClick?.(info); @@ -153,11 +153,13 @@ SchemaSettings.PopupItem = (props) => { const { schema, ...others } = props; const [visible, setVisible] = useState(false); const ctx = useContext(SchemaSettingsContext); + const actx = useActionContext(); return ( { + // actx.setVisible(false); ctx.setVisible(false); setVisible(true); }} @@ -173,3 +175,32 @@ SchemaSettings.PopupItem = (props) => { ); }; + +SchemaSettings.ModalItem = (props) => { + const { title, schema, onSubmit, initialValues, ...others } = props; + const options = useContext(SchemaOptionsContext); + return ( + { + FormDialog(schema.title || title, () => { + return ( + + + + + + ); + }) + .open({ + initialValues, + }) + .then((values) => { + onSubmit(values); + }); + }} + > + {props.children || props.title} + + ); +};