Skip to content

Commit

Permalink
feat(cloud-element-templates/cmd): handle optional inputs and outputs
Browse files Browse the repository at this point in the history
Closes #559
  • Loading branch information
Niklas Kiefer committed Feb 3, 2022
1 parent e353a33 commit a108a24
Show file tree
Hide file tree
Showing 4 changed files with 586 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
createInputParameter,
createOutputParameter,
createTaskDefinitionWithType,
createTaskHeader
createTaskHeader,
shouldUpdate
} from '../CreateHelper';

import {
Expand Down Expand Up @@ -270,6 +271,7 @@ export default class ChangeElementTemplateHandler {
const oldProperty = findOldProperty(oldTemplate, newProperty),
oldInputOrOutput = oldProperty && findOldBusinessObject(businessObject, oldProperty),
newPropertyValue = newProperty.value,
isOptional = newProperty.optional,
newBinding = newProperty.binding,
newBindingType = newBinding.type;

Expand All @@ -279,7 +281,21 @@ export default class ChangeElementTemplateHandler {
// (2) update old inputs and outputs
if (oldProperty && oldInputOrOutput) {

// (2a) exclude old inputs and outputs from cleanup (unless optional)
if (
shouldUpdate(newPropertyValue, newProperty) ||
(isOptional && propertyChanged(oldInputOrOutput, oldProperty))
) {
if (is(oldInputOrOutput, 'zeebe:Input')) {
remove(oldInputs, oldInputOrOutput);
} else {
remove(oldOutputs, oldInputOrOutput);
}
}

// (2a) do updates (unless changed)
if (!propertyChanged(oldInputOrOutput, oldProperty)) {

if (is(oldInputOrOutput, 'zeebe:Input')) {
properties = {
source: newPropertyValue
Expand All @@ -296,16 +312,10 @@ export default class ChangeElementTemplateHandler {
properties
});
}

if (is(oldInputOrOutput, 'zeebe:Input')) {
remove(oldInputs, oldInputOrOutput);
} else {
remove(oldOutputs, oldInputOrOutput);
}
}

// (3) add new inputs and outputs
else {
// (3) add new inputs and outputs (unless optional)
else if (shouldUpdate(newPropertyValue, newProperty)) {
if (newBindingType === 'zeebe:input') {
propertyName = 'inputParameters';

Expand Down
36 changes: 24 additions & 12 deletions src/provider/cloud-element-templates/properties/CustomProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
createInputParameter,
createOutputParameter,
createTaskDefinitionWithType,
createTaskHeader
createTaskHeader,
shouldUpdate
} from '../CreateHelper';

import { createElement } from '../../../utils/ElementUtil';
Expand Down Expand Up @@ -337,6 +338,7 @@ function propertyGetter(element, property) {

const {
binding,
optional,
value: defaultValue = ''
} = property;

Expand Down Expand Up @@ -384,7 +386,8 @@ function propertyGetter(element, property) {
return inputParameter.get('source');
}

return defaultValue;
// allow empty values for optional parameters
return optional ? '' : defaultValue;
}

// zeebe:Output
Expand All @@ -395,7 +398,8 @@ function propertyGetter(element, property) {
return outputParameter.get('target');
}

return defaultValue;
// allow empty values for optional parameters
return optional ? '' : defaultValue;
}
}

Expand Down Expand Up @@ -425,7 +429,9 @@ function propertySetter(bpmnFactory, commandStack, element, property) {
return function setValue(value) {
let businessObject = getBusinessObject(element);

const { binding } = property;
const {
binding
} = property;

const {
name,
Expand Down Expand Up @@ -539,35 +545,41 @@ function propertySetter(bpmnFactory, commandStack, element, property) {
// zeebe:Input
if (type === ZEBBE_INPUT_TYPE) {
const oldZeebeInputParameter = findInputParameter(ioMapping, binding);

const newZeebeInputParameter = createInputParameter(binding, value, bpmnFactory);

const values = ioMapping.get('inputParameters').filter((value) => value !== oldZeebeInputParameter);

// do not persist empty parameters when configured as <optional>
if (shouldUpdate(value, property)) {
const newZeebeInputParameter = createInputParameter(binding, value, bpmnFactory);
values.push(newZeebeInputParameter);
}

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: ioMapping,
properties: { inputParameters: [ ...values, newZeebeInputParameter ] }
properties: { inputParameters: [ ...values ] }
}
});
}

// zeebe:Output
if (type === ZEEBE_OUTPUT_TYPE) {
const oldZeebeOutputParameter = findOutputParameter(ioMapping, binding);

const newZeebeOutputParameter = createOutputParameter(binding, value, bpmnFactory);

const values = ioMapping.get('outputParameters').filter((value) => value !== oldZeebeOutputParameter);

// do not persist empty parameters when configured as <optional>
if (shouldUpdate(value, property)) {
const newZeebeOutputParameter = createOutputParameter(binding, value, bpmnFactory);
values.push(newZeebeOutputParameter);
}

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: ioMapping,
properties: { 'outputParameters': [ ...values, newZeebeOutputParameter ] }
properties: { 'outputParameters': [ ...values ] }
}
});
}
Expand Down
Loading

0 comments on commit a108a24

Please sign in to comment.