From e7d0e49b8e8b1d06dee0a8695ab149b06b57e0de Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 30 Mar 2023 17:31:55 +0800 Subject: [PATCH] fix/(linkages-action): detail block actions does not support linkage rules (#1504) * fix: condiction suport empty * fix: condiction suport empty * fix: condiction suport empty * fix: condiction suport empty * feat: detailed operations support linkage rules * fix: button linkage failed during page change of detail block * fix: button linkage failed during page change of detail block * fix: action automatically closes * fix: action automatically closes * fix: details block chang page action linkage failed * fix: details block chang page action linkage failed --------- Co-authored-by: chenos --- .../antd/action/Action.Designer.tsx | 10 +++--- .../schema-component/antd/action/Action.tsx | 11 +++++-- .../src/schema-component/antd/action/utils.ts | 32 +++++++++++++------ .../client/src/schema-initializer/utils.ts | 2 +- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx index acb1a0a32..f10970cd3 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx @@ -1,14 +1,14 @@ import { ISchema, useField, useFieldSchema } from '@formily/react'; import { isValid, uid } from '@formily/shared'; -import { Menu, Select } from 'antd'; +import { Menu } from 'antd'; import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useDesignable } from '../..'; -import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; +import { useFormBlockContext } from '../../../block-provider/FormBlockProvider'; import { useCollection, useCollectionManager } from '../../../collection-manager'; import { useRecord } from '../../../record-provider'; -import { useFormBlockContext } from '../../../block-provider/FormBlockProvider'; import { OpenModeSchemaItems } from '../../../schema-items'; +import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; import { requestSettingsSchema } from './utils'; @@ -49,7 +49,9 @@ export const ActionDesigner = (props) => { const isUpdateModePopupAction = ['customize:bulkUpdate', 'customize:bulkEdit'].includes(fieldSchema['x-action']); const [initialSchema, setInitialSchema] = useState(); const actionType = fieldSchema['x-action'] ?? ''; - const isLinkageAction = Object.keys(useFormBlockContext()).length > 0 && Object.keys(useRecord()).length > 0; + const isLinkageAction = + (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 isSupportEditButton = fieldSchema['x-action'] !== 'expandAll'; const isLink = fieldSchema['x-component'] === 'Action.Link'; diff --git a/packages/core/client/src/schema-component/antd/action/Action.tsx b/packages/core/client/src/schema-component/antd/action/Action.tsx index b96ed3ae7..62a447e51 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.tsx @@ -99,19 +99,23 @@ export const Action: ComposedAction = observer((props: any) => { const { designable, } = useDesignable(); const tarComponent=useComponent(component)||component; useEffect(() => { + field.linkageProperty = {}; linkageRules.map((v) => { return v.actions?.map((h) => { - linkageAction(h.operator, field, v.condition, values, designable); + linkageAction(h.operator, field, v.condition, values); }); }); - }, [linkageRules]); + }, [linkageRules, values]); const renderButton = () => ( } disabled={disabled} - style={{ border: field?.data?.hidden && '1px dashed #ede9e9' }} + style={{ + display: !designable && field?.data?.hidden && 'none', + opacity: designable && field?.data?.hidden && 0.1, + }} onClick={(e: React.MouseEvent) => { if (!disabled) { e.preventDefault(); @@ -138,6 +142,7 @@ export const Action: ComposedAction = observer((props: any) => { ); + return ( { - const displayResult = [field.display]; - const disableResult = [field.disabled]; +export const linkageAction = (operator, field, condition, values) => { + const disableResult = field?.linkageProperty?.disabled || [false]; + const displayResult = field?.linkageProperty?.display || ['visible']; switch (operator) { case ActionType.Visible: if (conditionAnalyse(condition, values)) { displayResult.push(operator); + field.data = field.data || {}; + field.data.hidden = false; } + field.linkageProperty = { + ...field.linkageProperty, + required: displayResult, + }; field.display = last(displayResult); break; case ActionType.Hidden: if (conditionAnalyse(condition, values)) { - if (!designable) { - displayResult.push(operator); - } else { - field.data = field.data || {}; - field.data.hidden = true; - } + field.data = field.data || {}; + field.data.hidden = true; + } else { + field.data = field.data || {}; + field.data.hidden = false; } - field.display = last(displayResult); break; case ActionType.Disabled: if (conditionAnalyse(condition, values)) { disableResult.push(true); } + field.linkageProperty = { + ...field.linkageProperty, + required: disableResult, + }; field.disabled = last(disableResult); break; case ActionType.Active: if (conditionAnalyse(condition, values)) { disableResult.push(false); } + field.linkageProperty = { + ...field.linkageProperty, + required: disableResult, + }; field.disabled = last(disableResult); break; default: diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 2f654d852..344fbefb0 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -821,7 +821,7 @@ export const createDetailsBlockSchema = (options) => { useProps: '{{ useDetailsBlockProps }}', }, properties: { - actions: { + [uid()]: { type: 'void', 'x-initializer': actionInitializers, 'x-component': 'ActionBar',