chore: add new allowAddtoCurrent config (#1652)
This commit is contained in:
parent
53d0c2dd23
commit
4274f605dd
@ -4,6 +4,7 @@ import { RecursionField, useFieldSchema, useField } from '@formily/react';
|
|||||||
import { Dropdown, Menu, Button } from 'antd';
|
import { Dropdown, Menu, Button } from 'antd';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { observer } from '@formily/react';
|
import { observer } from '@formily/react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useCollectionManager, useCollection, CollectionProvider } from '../../collection-manager';
|
import { useCollectionManager, useCollection, CollectionProvider } from '../../collection-manager';
|
||||||
import { ActionContext, useCompile, useActionContext } from '../../schema-component';
|
import { ActionContext, useCompile, useActionContext } from '../../schema-component';
|
||||||
import { useRecordPkValue, useACLRolesCheck } from '../../acl/ACLProvider';
|
import { useRecordPkValue, useACLRolesCheck } from '../../acl/ACLProvider';
|
||||||
@ -86,7 +87,9 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
const collection = useCollection();
|
const collection = useCollection();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const enableChildren = fieldSchema['x-enable-children'] || [];
|
const enableChildren = fieldSchema['x-enable-children'] || [];
|
||||||
|
const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current'];
|
||||||
const field: any = useField();
|
const field: any = useField();
|
||||||
|
const { t } = useTranslation();
|
||||||
const componentType = field.componentProps.type || 'primary';
|
const componentType = field.componentProps.type || 'primary';
|
||||||
const { getChildrenCollections } = useCollectionManager();
|
const { getChildrenCollections } = useCollectionManager();
|
||||||
const totalChildCollections = getChildrenCollections(collection.name);
|
const totalChildCollections = getChildrenCollections(collection.name);
|
||||||
@ -144,6 +147,7 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
<div className={actionDesignerCss}>
|
<div className={actionDesignerCss}>
|
||||||
<ActionContext.Provider value={{ ...ctx, visible, setVisible }}>
|
<ActionContext.Provider value={{ ...ctx, visible, setVisible }}>
|
||||||
{inheritsCollections?.length > 0 ? (
|
{inheritsCollections?.length > 0 ? (
|
||||||
|
allowAddToCurrent === undefined || allowAddToCurrent ? (
|
||||||
<Dropdown.Button
|
<Dropdown.Button
|
||||||
type={componentType}
|
type={componentType}
|
||||||
icon={<DownOutlined />}
|
icon={<DownOutlined />}
|
||||||
@ -160,6 +164,15 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
<PlusOutlined />
|
<PlusOutlined />
|
||||||
{props.children}
|
{props.children}
|
||||||
</Dropdown.Button>
|
</Dropdown.Button>
|
||||||
|
) : (
|
||||||
|
<Dropdown overlay={menu}>
|
||||||
|
{
|
||||||
|
<Button icon={<PlusOutlined />} type={'primary'}>
|
||||||
|
{props.children} <DownOutlined />
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
</Dropdown>
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
type={componentType}
|
type={componentType}
|
||||||
@ -185,4 +198,3 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1001,8 +1001,10 @@ SchemaSettings.LinkageRules = (props) => {
|
|||||||
SchemaSettings.EnableChildCollections = (props) => {
|
SchemaSettings.EnableChildCollections = (props) => {
|
||||||
const { collectionName } = props;
|
const { collectionName } = props;
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
|
console.log(fieldSchema);
|
||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current'];
|
||||||
return (
|
return (
|
||||||
<SchemaSettings.ModalItem
|
<SchemaSettings.ModalItem
|
||||||
title={t('Enable child collections')}
|
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
|
} as ISchema
|
||||||
}
|
}
|
||||||
onSubmit={(v) => {
|
onSubmit={(v) => {
|
||||||
|
console.log(v);
|
||||||
const enableChildren = [];
|
const enableChildren = [];
|
||||||
for (const item of v.enableChildren.childrenCollections) {
|
for (const item of v.enableChildren.childrenCollections) {
|
||||||
enableChildren.push(_.pickBy(item, _.identity));
|
enableChildren.push(_.pickBy(item, _.identity));
|
||||||
@ -1037,11 +1047,13 @@ SchemaSettings.EnableChildCollections = (props) => {
|
|||||||
['x-uid']: uid,
|
['x-uid']: uid,
|
||||||
};
|
};
|
||||||
fieldSchema['x-enable-children'] = enableChildren;
|
fieldSchema['x-enable-children'] = enableChildren;
|
||||||
|
fieldSchema['x-allow-add-to-current'] = v.allowAddToCurrent;
|
||||||
fieldSchema['x-component-props'] = {
|
fieldSchema['x-component-props'] = {
|
||||||
openMode: 'drawer',
|
openMode: 'drawer',
|
||||||
component: 'CreateRecordAction',
|
component: 'CreateRecordAction',
|
||||||
};
|
};
|
||||||
schema['x-enable-children'] = enableChildren;
|
schema['x-enable-children'] = enableChildren;
|
||||||
|
schema['x-allow-add-to-current'] = v.allowAddToCurrent;
|
||||||
schema['x-component-props'] = {
|
schema['x-component-props'] = {
|
||||||
openMode: 'drawer',
|
openMode: 'drawer',
|
||||||
component: 'CreateRecordAction',
|
component: 'CreateRecordAction',
|
||||||
|
Loading…
Reference in New Issue
Block a user