Skip to content

Commit

Permalink
refactor: update MultiInstanceProps to use createOrUpdateFormalExpres…
Browse files Browse the repository at this point in the history
…sion helper
  • Loading branch information
maff committed Mar 6, 2025
1 parent 362a08c commit 533f220
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 93 deletions.
86 changes: 16 additions & 70 deletions src/provider/bpmn/properties/MultiInstanceProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
} from '../../../hooks';

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

/**
* @typedef { import('@bpmn-io/properties-panel').EntryDefinition } Entry
Expand Down Expand Up @@ -58,9 +58,13 @@ function LoopCardinality(props) {
};

const setValue = (value) => {
return commandStack.execute(
'element.updateModdleProperties',
updateFormalExpression(element, 'loopCardinality', value, bpmnFactory)
return createOrUpdateFormalExpression(
element,
getLoopCharacteristics(element),
'loopCardinality',
value,
bpmnFactory,
commandStack
);
};

Expand All @@ -87,9 +91,13 @@ function CompletionCondition(props) {
};

const setValue = (value) => {
return commandStack.execute(
'element.updateModdleProperties',
updateFormalExpression(element, 'completionCondition', value, bpmnFactory)
return createOrUpdateFormalExpression(
element,
getLoopCharacteristics(element),
'completionCondition',
value,
bpmnFactory,
commandStack
);
};

Expand Down Expand Up @@ -153,68 +161,6 @@ function getLoopCharacteristics(element) {
return bo.loopCharacteristics;
}

/**
* createFormalExpression - creates a 'bpmn:FormalExpression' element.
*
* @param {ModdleElement} parent
* @param {string} body
* @param {BpmnFactory} bpmnFactory
*
* @result {ModdleElement<bpmn:FormalExpression>} a formal expression
*/
function createFormalExpression(parent, body, bpmnFactory) {
return createElement('bpmn:FormalExpression', { body: body }, parent, bpmnFactory);
}

/**
* updateFormalExpression - updates a specific formal expression of the loop characteristics.
*
* @param {djs.model.Base} element
* @param {string} propertyName
* @param {string} newValue
* @param {BpmnFactory} bpmnFactory
*/
function updateFormalExpression(element, propertyName, newValue, bpmnFactory) {
const loopCharacteristics = getLoopCharacteristics(element);

const expressionProps = {};

if (!newValue) {

// remove formal expression
expressionProps[ propertyName ] = undefined;

return {
element,
moddleElement: loopCharacteristics,
properties: expressionProps
};
}

const existingExpression = loopCharacteristics.get(propertyName);

if (!existingExpression) {

// add formal expression
expressionProps[ propertyName ] = createFormalExpression(loopCharacteristics, newValue, bpmnFactory);

return {
element,
moddleElement: loopCharacteristics,
properties: expressionProps
};
}

// edit existing formal expression
return {
element,
moddleElement: existingExpression,
properties: {
body: newValue
}
};
}

// loopCardinality

/**
Expand Down
34 changes: 11 additions & 23 deletions src/provider/zeebe/properties/MultiInstanceProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import {
import {
createElement
} from '../../../utils/ElementUtil';
import {
createOrUpdateFormalExpression
} from '../../../utils/FormalExpressionUtil';

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

import { FeelEntryWithVariableContext } from '../../../entries/FeelEntryWithContext';


export function MultiInstanceProps(props) {
const {
element
Expand Down Expand Up @@ -188,18 +190,14 @@ function CompletionCondition(props) {
};

const setValue = (value) => {
if (value && value !== '') {
const loopCharacteristics = getLoopCharacteristics(element);
const completionCondition = createElement(
'bpmn:FormalExpression',
{ body: value },
loopCharacteristics,
bpmnFactory
);
setCompletionCondition(element, commandStack, completionCondition);
} else {
setCompletionCondition(element, commandStack, undefined);
}
return createOrUpdateFormalExpression(
element,
getLoopCharacteristics(element),
'completionCondition',
value,
bpmnFactory,
commandStack
);
};

return FeelEntryWithVariableContext({
Expand Down Expand Up @@ -234,16 +232,6 @@ function getCompletionCondition(element) {
return getLoopCharacteristics(element).get('completionCondition');
}

function setCompletionCondition(element, commandStack, completionCondition = undefined) {
commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: getLoopCharacteristics(element),
properties: {
completionCondition
}
});
}

function getProperty(element, propertyName) {
const loopCharacteristics = getLoopCharacteristics(element),
zeebeLoopCharacteristics = getZeebeLoopCharacteristics(loopCharacteristics);
Expand Down

0 comments on commit 533f220

Please sign in to comment.