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 keys = Object.keys(record);
|
||||
if (keys.includes('__parent')) {
|
||||
|
@ -4,11 +4,10 @@ import { Menu } from 'antd';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useDesignable } from '../..';
|
||||
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||
import { useRecord } from '../../../record-provider';
|
||||
import { OpenModeSchemaItems } from '../../../schema-items';
|
||||
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
||||
import { useLinkageAction } from './hooks';
|
||||
|
||||
import { requestSettingsSchema } from './utils';
|
||||
|
||||
@ -49,10 +48,7 @@ export const ActionDesigner = (props) => {
|
||||
const isUpdateModePopupAction = ['customize:bulkUpdate', 'customize:bulkEdit'].includes(fieldSchema['x-action']);
|
||||
const [initialSchema, setInitialSchema] = useState<ISchema>();
|
||||
const actionType = fieldSchema['x-action'] ?? '';
|
||||
const isLinkageAction =
|
||||
linkageAction ||
|
||||
(Object.keys(useFormBlockContext()).length > 0 && Object.keys(useRecord()).length > 0) ||
|
||||
fieldSchema?.parent?.['x-initializer'] === 'DetailsActionInitializers';
|
||||
const isLinkageAction = linkageAction || useLinkageAction();
|
||||
const isChildCollectionAction = getChildrenCollections(name).length > 0 && fieldSchema['x-action'] === 'create';
|
||||
const isSupportEditButton = fieldSchema['x-action'] !== 'expandAll';
|
||||
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 { useContext } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ActionContext } from './context';
|
||||
import { useIsEmptyRecord } from '../../../block-provider/FormBlockProvider';
|
||||
|
||||
export const useA = () => {
|
||||
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,
|
||||
required: displayResult,
|
||||
display: displayResult,
|
||||
};
|
||||
field.display = last(displayResult);
|
||||
break;
|
||||
@ -100,7 +100,7 @@ export const linkageAction = (operator, field, condition, values) => {
|
||||
}
|
||||
field.linkageProperty = {
|
||||
...field.linkageProperty,
|
||||
required: disableResult,
|
||||
disabled: disableResult,
|
||||
};
|
||||
field.disabled = last(disableResult);
|
||||
break;
|
||||
@ -110,7 +110,7 @@ export const linkageAction = (operator, field, condition, values) => {
|
||||
}
|
||||
field.linkageProperty = {
|
||||
...field.linkageProperty,
|
||||
required: disableResult,
|
||||
disabled: disableResult,
|
||||
};
|
||||
field.disabled = last(disableResult);
|
||||
break;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { DownOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { RecursionField, useFieldSchema, useField } from '@formily/react';
|
||||
import { Dropdown, Menu, Button } from 'antd';
|
||||
@ -7,6 +7,9 @@ import { observer } from '@formily/react';
|
||||
import { useCollectionManager, useCollection, CollectionProvider } from '../../collection-manager';
|
||||
import { ActionContext, useCompile, useActionContext } from '../../schema-component';
|
||||
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`
|
||||
position: relative;
|
||||
@ -83,7 +86,7 @@ export const CreateRecordAction = observer((props) => {
|
||||
const collection = useCollection();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const enableChildren = fieldSchema['x-enable-children'] || [];
|
||||
const field = useField();
|
||||
const field: any = useField();
|
||||
const componentType = field.componentProps.type || 'primary';
|
||||
const { getChildrenCollections } = useCollectionManager();
|
||||
const totalChildCollections = getChildrenCollections(collection.name);
|
||||
@ -105,8 +108,11 @@ export const CreateRecordAction = observer((props) => {
|
||||
return v && actionAclCheck(`${v.name}:create`);
|
||||
});
|
||||
const [currentCollection, setCurrentCollection] = useState(collection.name);
|
||||
const linkageRules = fieldSchema?.['x-linkage-rules'] || [];
|
||||
const values = useRecord();
|
||||
const ctx = useActionContext();
|
||||
const compile = useCompile();
|
||||
const { designable } = useDesignable();
|
||||
const menu = (
|
||||
<Menu>
|
||||
{inheritsCollections.map((option) => {
|
||||
@ -124,6 +130,16 @@ export const CreateRecordAction = observer((props) => {
|
||||
})}
|
||||
</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 (
|
||||
<div className={actionDesignerCss}>
|
||||
<ActionContext.Provider value={{ ...ctx, visible, setVisible }}>
|
||||
@ -147,12 +163,17 @@ export const CreateRecordAction = observer((props) => {
|
||||
) : (
|
||||
<Button
|
||||
type={componentType}
|
||||
disabled={field.disabled}
|
||||
danger={componentType === 'danger'}
|
||||
icon={<PlusOutlined />}
|
||||
onClick={(info) => {
|
||||
setVisible(true);
|
||||
setCurrentCollection(collection.name);
|
||||
}}
|
||||
style={{
|
||||
display: !designable && field?.data?.hidden && 'none',
|
||||
opacity: designable && field?.data?.hidden && 0.1,
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</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