chore: add new allowAddtoCurrent config (#1652)

This commit is contained in:
katherinehhh 2023-04-06 12:49:11 +08:00 committed by GitHub
parent 53d0c2dd23
commit 4274f605dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 17 deletions

View File

@ -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) => {
<div className={actionDesignerCss}>
<ActionContext.Provider value={{ ...ctx, visible, setVisible }}>
{inheritsCollections?.length > 0 ? (
<Dropdown.Button
type={componentType}
icon={<DownOutlined />}
buttonsRender={([leftButton, rightButton]) => [
leftButton,
React.cloneElement(rightButton as React.ReactElement<any, string>, { loading: false }),
]}
overlay={menu}
onClick={(info) => {
setVisible(true);
setCurrentCollection(collection.name);
}}
>
<PlusOutlined />
{props.children}
</Dropdown.Button>
allowAddToCurrent === undefined || allowAddToCurrent ? (
<Dropdown.Button
type={componentType}
icon={<DownOutlined />}
buttonsRender={([leftButton, rightButton]) => [
leftButton,
React.cloneElement(rightButton as React.ReactElement<any, string>, { loading: false }),
]}
overlay={menu}
onClick={(info) => {
setVisible(true);
setCurrentCollection(collection.name);
}}
>
<PlusOutlined />
{props.children}
</Dropdown.Button>
) : (
<Dropdown overlay={menu}>
{
<Button icon={<PlusOutlined />} type={'primary'}>
{props.children} <DownOutlined />
</Button>
}
</Dropdown>
)
) : (
<Button
type={componentType}
@ -185,4 +198,3 @@ export const CreateRecordAction = observer((props) => {
</div>
);
});

View File

@ -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 (
<SchemaSettings.ModalItem
title={t('Enable child collections')}
@ -1024,10 +1026,18 @@ SchemaSettings.EnableChildCollections = (props) => {
},
},
},
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',