Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for CalledElement#propagateAllParentVariables #954

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/provider/zeebe/ZeebePropertiesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EscalationProps,
FormProps,
HeaderProps,
InputPropagationProps,
InputProps,
MessageProps,
MultiInstanceProps,
Expand Down Expand Up @@ -43,6 +44,7 @@ const ZEEBE_GROUPS = [
FormGroup,
ConditionGroup,
TargetGroup,
InputPropagationGroup,
InputGroup,
OutputPropagationGroup,
OutputGroup,
Expand Down Expand Up @@ -214,6 +216,19 @@ function OutputPropagationGroup(element) {
return group.entries.length ? group : null;
}

function InputPropagationGroup(element) {
const group = {
id: 'inputPropagation',
label: 'Input propagation',
entries: [
...InputPropagationProps({ element })
],
component: Group
};

return group.entries.length ? group : null;
}

function BusinessRuleImplementationGroup(element) {
const group = {
id: 'businessRuleImplementation',
Expand Down
158 changes: 158 additions & 0 deletions src/provider/zeebe/properties/InputPropagationProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import {
getBusinessObject,
is
} from 'bpmn-js/lib/util/ModelUtil';

import {
getCalledElement
} from '../utils/CalledElementUtil.js';

import {
has
} from 'min-dash';

import {
createElement
} from '../../../utils/ElementUtil';

import {
useService
} from '../../../hooks';

import { ToggleSwitchEntry, isToggleSwitchEntryEdited } from '@bpmn-io/properties-panel';


export function InputPropagationProps(props) {
const {
element
} = props;

if (!is(element, 'bpmn:CallActivity')) {
return [];
}

return [
{
id: 'propagateAllParentVariables',
component: PropagateAllParentVariables,
isEdited: isToggleSwitchEntryEdited
}
];
}

function PropagateAllParentVariables(props) {
const {
element
} = props;

const commandStack = useService('commandStack'),
bpmnFactory = useService('bpmnFactory'),
translate = useService('translate');

const propagateAllParentVariables = isPropagateAllParentVariables(element);

const getValue = () => {
return propagateAllParentVariables;
};

const setValue = (value) => {
const commands = [];

const businessObject = getBusinessObject(element);

// (1) ensure extension elements
let extensionElements = businessObject.get('extensionElements');

if (!extensionElements) {
extensionElements = createElement(
'bpmn:ExtensionElements',
{ values: [] },
businessObject,
bpmnFactory
);

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: businessObject,
properties: { extensionElements }
}
});
}

// (2) ensure zeebe:calledElement
let calledElement = getCalledElement(businessObject);

if (!calledElement) {
calledElement = createElement(
'zeebe:CalledElement',
{ },
extensionElements,
bpmnFactory);

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: extensionElements,
properties: {
values: [ ...extensionElements.get('values'), calledElement ]
}
}
});

}

// (3) Update propagateAllParentVariables attribute
commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: calledElement,
properties: {
propagateAllParentVariables: value
}
}
});

// (4) Execute the commands
commandStack.execute('properties-panel.multi-command-executor', commands);
};

return ToggleSwitchEntry({
id: 'propagateAllParentVariables',
label: translate('Propagate all variables'),
switcherLabel: propagateAllParentVariables ?
translate('On') :
translate('Off'),
tooltip: <div>
<p>{translate('If turned on, all variables from this process instance will be propagated to the child process instance.')}</p>
<p>{translate('Otherwise, only variables defined via input mappings will be propagated.')}</p>
</div>,
getValue,
setValue
});
}


// helper //////////////////////////

/**
* Check whether the propagateAllParentVariables attribute is set on an element.
* @param {Object} element
*
* @returns {boolean}
*/
export function isPropagateAllParentVariables(element) {
if (!is(element, 'bpmn:CallActivity')) {
return undefined;
}

const bo = getBusinessObject(element),
calledElement = getCalledElement(bo);

return calledElement && has(calledElement, 'propagateAllParentVariables') ?
calledElement.get('propagateAllParentVariables') :
/* default value */ true;
}
1 change: 1 addition & 0 deletions src/provider/zeebe/properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { ErrorProps } from './ErrorProps';
export { EscalationProps } from './EscalationProps';
export { FormProps } from './FormProps';
export { HeaderProps } from './HeaderProps';
export { InputPropagationProps } from './InputPropagationProps';
export { InputProps } from './InputProps';
export { MessageProps } from './MessageProps';
export { MultiInstanceProps } from './MultiInstanceProps';
Expand Down
6 changes: 6 additions & 0 deletions src/provider/zeebe/utils/CalledElementUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export function getPropagateAllChildVariables(element) {
return calledElement ? calledElement.get('propagateAllChildVariables') : undefined;
}

export function getPropagateAllParentVariables(element) {
const calledElement = getCalledElement(element);

return calledElement ? calledElement.get('propagateAllParentVariables') : undefined;
}

export function getProcessId(element) {
const calledElement = getCalledElement(element);

Expand Down
76 changes: 76 additions & 0 deletions test/spec/provider/zeebe/InputPropagationProps.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0xepdnf" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.0.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="1.0.0">
<bpmn:process id="Process_1ca0499" isExecutable="true">
<bpmn:callActivity id="CallActivity_1" name="CallActivity_1">
<bpmn:extensionElements>
<zeebe:calledElement propagateAllParentVariables="false" />
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:callActivity id="CallActivity_2" name="CallActivity_2">
<bpmn:extensionElements>
<zeebe:calledElement />
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:callActivity id="CallActivity_3" name="CallActivity_3" />
<bpmn:callActivity id="CallActivity_4" name="CallActivity_4">
<bpmn:extensionElements>
<zeebe:calledElement processId="someProcessId" />
<zeebe:ioMapping>
<zeebe:output source="= source" target="target" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:task id="Task_1" name="Task_1" />
<bpmn:callActivity id="CallActivity_5" name="CallActivity_5">
<bpmn:extensionElements>
<zeebe:ioMapping>
<zeebe:input source="= source" target="target" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:callActivity id="CallActivity_6" name="CallActivity_6">
<bpmn:extensionElements>
<zeebe:calledElement propagateAllParentVariables="false" />
<zeebe:ioMapping>
<zeebe:output source="= source" target="target" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:group id="Group_0g7mvor" categoryValueRef="CategoryValue_0i5rzi3" />
</bpmn:process>
<bpmn:category id="Category_028vbmh">
<bpmn:categoryValue id="CategoryValue_0i5rzi3" value="Legacy Formats" />
</bpmn:category>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1ca0499">
<bpmndi:BPMNShape id="Activity_148gene_di" bpmnElement="CallActivity_1">
<dc:Bounds x="160" y="230" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_17u01kh_di" bpmnElement="CallActivity_2">
<dc:Bounds x="160" y="360" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_04g6ntf_di" bpmnElement="CallActivity_3">
<dc:Bounds x="490" y="230" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_09v4buk_di" bpmnElement="CallActivity_4">
<dc:Bounds x="490" y="350" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1qlrc91_di" bpmnElement="Task_1">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ucjhow_di" bpmnElement="CallActivity_5">
<dc:Bounds x="160" y="490" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ax67yw_di" bpmnElement="CallActivity_6">
<dc:Bounds x="160" y="620" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Group_0g7mvor_di" bpmnElement="Group_0g7mvor">
<dc:Bounds x="390" y="180" width="300" height="300" />
<bpmndi:BPMNLabel>
<dc:Bounds x="500" y="187" width="80" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading