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

Optional zeebe:input and zeebe:output #565

Merged
merged 2 commits into from
Feb 7, 2022
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
17 changes: 17 additions & 0 deletions src/provider/cloud-element-templates/CreateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,20 @@ export function createTaskDefinitionWithType(value, bpmnFactory) {
type: value
});
}

/**
* Retrieves whether an element should be updated for a given property.
*
* That matches once
* a) the property value is not empty, or
* b) the property is not optional
*
* @param {String} value
* @param {Object} property
* @returns {Boolean}
*/
export function shouldUpdate(value, property) {
const { optional } = property;

return value || !optional;
}
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 @@ -279,7 +280,23 @@ export default class ChangeElementTemplateHandler {
// (2) update old inputs and outputs
if (oldProperty && oldInputOrOutput) {

// (2a) exclude old inputs and outputs from cleanup, unless
// a) optional and has empty value, and
// b) not changed
if (
shouldUpdate(newPropertyValue, newProperty) ||
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 +313,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