fix(linkage rule):linkage rule not display in action (#1644)
* fix: islinageActionlogical judgment * fix: add new linkage rule setting is not effective
This commit is contained in:
parent
fff11df2ba
commit
b7abdfb9e6
@ -49,7 +49,7 @@ const InternalFormBlockProvider = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const useIsEmptyRecord = () => {
|
export const useIsEmptyRecord = () => {
|
||||||
const record = useRecord();
|
const record = useRecord();
|
||||||
const keys = Object.keys(record);
|
const keys = Object.keys(record);
|
||||||
if (keys.includes('__parent')) {
|
if (keys.includes('__parent')) {
|
||||||
|
@ -4,11 +4,10 @@ import { Menu } from 'antd';
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useDesignable } from '../..';
|
import { useDesignable } from '../..';
|
||||||
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
|
||||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||||
import { useRecord } from '../../../record-provider';
|
|
||||||
import { OpenModeSchemaItems } from '../../../schema-items';
|
import { OpenModeSchemaItems } from '../../../schema-items';
|
||||||
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
||||||
|
import { useLinkageAction } from './hooks';
|
||||||
|
|
||||||
import { requestSettingsSchema } from './utils';
|
import { requestSettingsSchema } from './utils';
|
||||||
|
|
||||||
@ -49,10 +48,7 @@ export const ActionDesigner = (props) => {
|
|||||||
const isUpdateModePopupAction = ['customize:bulkUpdate', 'customize:bulkEdit'].includes(fieldSchema['x-action']);
|
const isUpdateModePopupAction = ['customize:bulkUpdate', 'customize:bulkEdit'].includes(fieldSchema['x-action']);
|
||||||
const [initialSchema, setInitialSchema] = useState<ISchema>();
|
const [initialSchema, setInitialSchema] = useState<ISchema>();
|
||||||
const actionType = fieldSchema['x-action'] ?? '';
|
const actionType = fieldSchema['x-action'] ?? '';
|
||||||
const isLinkageAction =
|
const isLinkageAction = linkageAction || useLinkageAction();
|
||||||
linkageAction ||
|
|
||||||
(Object.keys(useFormBlockContext()).length > 0 && Object.keys(useRecord()).length > 0) ||
|
|
||||||
fieldSchema?.parent?.['x-initializer'] === 'DetailsActionInitializers';
|
|
||||||
const isChildCollectionAction = getChildrenCollections(name).length > 0 && fieldSchema['x-action'] === 'create';
|
const isChildCollectionAction = getChildrenCollections(name).length > 0 && fieldSchema['x-action'] === 'create';
|
||||||
const isSupportEditButton = fieldSchema['x-action'] !== 'expandAll';
|
const isSupportEditButton = fieldSchema['x-action'] !== 'expandAll';
|
||||||
const isLink = fieldSchema['x-component'] === 'Action.Link';
|
const isLink = fieldSchema['x-component'] === 'Action.Link';
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { useForm } from '@formily/react';
|
import { useForm, useFieldSchema } from '@formily/react';
|
||||||
import { Modal as AntdModal } from 'antd';
|
import { Modal as AntdModal } from 'antd';
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ActionContext } from './context';
|
import { ActionContext } from './context';
|
||||||
|
import { useIsEmptyRecord } from '../../../block-provider/FormBlockProvider';
|
||||||
|
|
||||||
export const useA = () => {
|
export const useA = () => {
|
||||||
return {
|
return {
|
||||||
@ -51,3 +52,10 @@ export const useCloseAction = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useLinkageAction = () => {
|
||||||
|
const fieldSchema = useFieldSchema();
|
||||||
|
const isRecordAction = useIsEmptyRecord();
|
||||||
|
const isAction = ['Action.Link', 'Action'].includes(fieldSchema['x-component']);
|
||||||
|
return isAction && isRecordAction;
|
||||||
|
};
|
||||||
|
@ -81,7 +81,7 @@ export const linkageAction = (operator, field, condition, values) => {
|
|||||||
}
|
}
|
||||||
field.linkageProperty = {
|
field.linkageProperty = {
|
||||||
...field.linkageProperty,
|
...field.linkageProperty,
|
||||||
required: displayResult,
|
display: displayResult,
|
||||||
};
|
};
|
||||||
field.display = last(displayResult);
|
field.display = last(displayResult);
|
||||||
break;
|
break;
|
||||||
@ -100,7 +100,7 @@ export const linkageAction = (operator, field, condition, values) => {
|
|||||||
}
|
}
|
||||||
field.linkageProperty = {
|
field.linkageProperty = {
|
||||||
...field.linkageProperty,
|
...field.linkageProperty,
|
||||||
required: disableResult,
|
disabled: disableResult,
|
||||||
};
|
};
|
||||||
field.disabled = last(disableResult);
|
field.disabled = last(disableResult);
|
||||||
break;
|
break;
|
||||||
@ -110,7 +110,7 @@ export const linkageAction = (operator, field, condition, values) => {
|
|||||||
}
|
}
|
||||||
field.linkageProperty = {
|
field.linkageProperty = {
|
||||||
...field.linkageProperty,
|
...field.linkageProperty,
|
||||||
required: disableResult,
|
disabled: disableResult,
|
||||||
};
|
};
|
||||||
field.disabled = last(disableResult);
|
field.disabled = last(disableResult);
|
||||||
break;
|
break;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { DownOutlined, PlusOutlined } from '@ant-design/icons';
|
import { DownOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
import { RecursionField, useFieldSchema, useField } from '@formily/react';
|
import { RecursionField, useFieldSchema, useField } from '@formily/react';
|
||||||
import { Dropdown, Menu, Button } from 'antd';
|
import { Dropdown, Menu, Button } from 'antd';
|
||||||
@ -7,6 +7,9 @@ import { observer } from '@formily/react';
|
|||||||
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';
|
||||||
|
import { useRecord } from '../../record-provider';
|
||||||
|
import { useDesignable } from '../../';
|
||||||
|
import { linkageAction } from '../../schema-component/antd/action/utils';
|
||||||
|
|
||||||
export const actionDesignerCss = css`
|
export const actionDesignerCss = css`
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -83,7 +86,7 @@ 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 field = useField();
|
const field: any = useField();
|
||||||
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);
|
||||||
@ -105,8 +108,11 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
return v && actionAclCheck(`${v.name}:create`);
|
return v && actionAclCheck(`${v.name}:create`);
|
||||||
});
|
});
|
||||||
const [currentCollection, setCurrentCollection] = useState(collection.name);
|
const [currentCollection, setCurrentCollection] = useState(collection.name);
|
||||||
|
const linkageRules = fieldSchema?.['x-linkage-rules'] || [];
|
||||||
|
const values = useRecord();
|
||||||
const ctx = useActionContext();
|
const ctx = useActionContext();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
|
const { designable } = useDesignable();
|
||||||
const menu = (
|
const menu = (
|
||||||
<Menu>
|
<Menu>
|
||||||
{inheritsCollections.map((option) => {
|
{inheritsCollections.map((option) => {
|
||||||
@ -124,6 +130,16 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
})}
|
})}
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
field.linkageProperty = {};
|
||||||
|
linkageRules
|
||||||
|
.filter((k) => !k.disabled)
|
||||||
|
.map((v) => {
|
||||||
|
return v.actions?.map((h) => {
|
||||||
|
linkageAction(h.operator, field, v.condition, values);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [linkageRules, values]);
|
||||||
return (
|
return (
|
||||||
<div className={actionDesignerCss}>
|
<div className={actionDesignerCss}>
|
||||||
<ActionContext.Provider value={{ ...ctx, visible, setVisible }}>
|
<ActionContext.Provider value={{ ...ctx, visible, setVisible }}>
|
||||||
@ -147,12 +163,17 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
type={componentType}
|
type={componentType}
|
||||||
|
disabled={field.disabled}
|
||||||
danger={componentType === 'danger'}
|
danger={componentType === 'danger'}
|
||||||
icon={<PlusOutlined />}
|
icon={<PlusOutlined />}
|
||||||
onClick={(info) => {
|
onClick={(info) => {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setCurrentCollection(collection.name);
|
setCurrentCollection(collection.name);
|
||||||
}}
|
}}
|
||||||
|
style={{
|
||||||
|
display: !designable && field?.data?.hidden && 'none',
|
||||||
|
opacity: designable && field?.data?.hidden && 0.1,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</Button>
|
</Button>
|
||||||
@ -165,10 +186,3 @@ export const CreateRecordAction = observer((props) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// export const CreateRecordAction = observer((props: any) => {
|
|
||||||
// return (
|
|
||||||
// <Action {...props} component={CreateAction}>
|
|
||||||
// {props.children}
|
|
||||||
// </Action>
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
|
Loading…
Reference in New Issue
Block a user