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 <chenlinxh@gmail.com>
This commit is contained in:
parent
35d34bb427
commit
e7d0e49b8e
@ -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<ISchema>();
|
||||
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';
|
||||
|
@ -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 = () => (
|
||||
<SortableItem
|
||||
{...others}
|
||||
loading={field?.data?.loading}
|
||||
icon={<Icon type={icon} />}
|
||||
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) => {
|
||||
<Designer {...designerProps} />
|
||||
</SortableItem>
|
||||
);
|
||||
|
||||
return (
|
||||
<ActionContext.Provider
|
||||
value={{
|
||||
|
@ -69,37 +69,49 @@ export const requestSettingsSchema: ISchema = {
|
||||
},
|
||||
};
|
||||
|
||||
export const linkageAction = (operator, field, condition, values, designable) => {
|
||||
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;
|
||||
} 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:
|
||||
|
@ -821,7 +821,7 @@ export const createDetailsBlockSchema = (options) => {
|
||||
useProps: '{{ useDetailsBlockProps }}',
|
||||
},
|
||||
properties: {
|
||||
actions: {
|
||||
[uid()]: {
|
||||
type: 'void',
|
||||
'x-initializer': actionInitializers,
|
||||
'x-component': 'ActionBar',
|
||||
|
Loading…
Reference in New Issue
Block a user