From 4274f605dd8e384f5739f04d68679c88537772d2 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 6 Apr 2023 12:49:11 +0800 Subject: [PATCH] chore: add new allowAddtoCurrent config (#1652) --- .../components/CreateRecordAction.tsx | 46 ++++++++++++------- .../src/schema-settings/SchemaSettings.tsx | 12 +++++ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx index c65310132..af63008cd 100644 --- a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx +++ b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx @@ -4,6 +4,7 @@ import { RecursionField, useFieldSchema, useField } from '@formily/react'; import { Dropdown, Menu, Button } from 'antd'; import { css } from '@emotion/css'; import { observer } from '@formily/react'; +import { useTranslation } from 'react-i18next'; import { useCollectionManager, useCollection, CollectionProvider } from '../../collection-manager'; import { ActionContext, useCompile, useActionContext } from '../../schema-component'; import { useRecordPkValue, useACLRolesCheck } from '../../acl/ACLProvider'; @@ -86,7 +87,9 @@ export const CreateRecordAction = observer((props) => { const collection = useCollection(); const fieldSchema = useFieldSchema(); const enableChildren = fieldSchema['x-enable-children'] || []; + const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current']; const field: any = useField(); + const { t } = useTranslation(); const componentType = field.componentProps.type || 'primary'; const { getChildrenCollections } = useCollectionManager(); const totalChildCollections = getChildrenCollections(collection.name); @@ -144,22 +147,32 @@ export const CreateRecordAction = observer((props) => {
{inheritsCollections?.length > 0 ? ( - } - buttonsRender={([leftButton, rightButton]) => [ - leftButton, - React.cloneElement(rightButton as React.ReactElement, { loading: false }), - ]} - overlay={menu} - onClick={(info) => { - setVisible(true); - setCurrentCollection(collection.name); - }} - > - - {props.children} - + allowAddToCurrent === undefined || allowAddToCurrent ? ( + } + buttonsRender={([leftButton, rightButton]) => [ + leftButton, + React.cloneElement(rightButton as React.ReactElement, { loading: false }), + ]} + overlay={menu} + onClick={(info) => { + setVisible(true); + setCurrentCollection(collection.name); + }} + > + + {props.children} + + ) : ( + + { + + } + + ) ) : (
); }); - diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index 2c1dfe158..030b9d579 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -1001,8 +1001,10 @@ SchemaSettings.LinkageRules = (props) => { SchemaSettings.EnableChildCollections = (props) => { const { collectionName } = props; const fieldSchema = useFieldSchema(); + console.log(fieldSchema); const { dn } = useDesignable(); const { t } = useTranslation(); + const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current']; return ( { }, }, }, + allowAddToCurrent: { + type: 'boolean', + 'x-content': "{{t('Allow adding records to the current collection')}}", + 'x-decorator': 'FormItem', + 'x-component': 'Checkbox', + default: allowAddToCurrent === undefined ? true : allowAddToCurrent, + }, }, } as ISchema } onSubmit={(v) => { + console.log(v); const enableChildren = []; for (const item of v.enableChildren.childrenCollections) { enableChildren.push(_.pickBy(item, _.identity)); @@ -1037,11 +1047,13 @@ SchemaSettings.EnableChildCollections = (props) => { ['x-uid']: uid, }; fieldSchema['x-enable-children'] = enableChildren; + fieldSchema['x-allow-add-to-current'] = v.allowAddToCurrent; fieldSchema['x-component-props'] = { openMode: 'drawer', component: 'CreateRecordAction', }; schema['x-enable-children'] = enableChildren; + schema['x-allow-add-to-current'] = v.allowAddToCurrent; schema['x-component-props'] = { openMode: 'drawer', component: 'CreateRecordAction',