Skip to content

Commit

Permalink
feat(cloud): remove unused properties from linkedResources
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Jan 9, 2025
1 parent 8dafb95 commit 4b0ff34
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 20 deletions.
45 changes: 32 additions & 13 deletions src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {

import {
find,
isUndefined,
without
} from 'min-dash';

Expand Down Expand Up @@ -1045,7 +1044,7 @@ export default class ChangeElementTemplateHandler {
const newBinding = newProperty.binding,
newBindingType = newBinding.type;

return newBindingType === 'zeebe:linkedResource#property';
return newBindingType === 'zeebe:linkedResource';
});

const extensionElements = this._getOrCreateExtensionElements(element);
Expand Down Expand Up @@ -1082,25 +1081,26 @@ export default class ChangeElementTemplateHandler {
});
}

const oldLinkedResources = linkedResources.get('values')?.slice() || [];
const unusedLinkedResources = linkedResources.get('values')?.slice() || [];
const unusedResourceProperties = oldTemplate?.properties.slice() || [];

newLinkedResources.forEach((newLinkedResource) => {
const oldProperty = findOldProperty(oldTemplate, newLinkedResource),
oldLinkedResource = findBusinessObject(extensionElements, newLinkedResource),
newPropertyValue = getDefaultValue(newLinkedResource),
newBinding = newLinkedResource.binding;

if (oldProperty) {
remove(unusedResourceProperties, oldProperty);
}

// (2) update old LinkesResources
if (oldLinkedResource) {

// debugger;
console.log(oldLinkedResource, oldLinkedResource, oldProperty, newLinkedResource, shouldKeepValue(oldLinkedResource, oldProperty, newLinkedResource));

if (
shouldUpdate(newPropertyValue, newLinkedResource)
|| shouldKeepValue(oldLinkedResource, oldProperty, newLinkedResource)
) {
remove(oldLinkedResources, oldLinkedResource);
remove(unusedLinkedResources, oldLinkedResource);
}

if (!shouldKeepValue(oldLinkedResource, oldProperty, newLinkedResource)) {
Expand Down Expand Up @@ -1134,17 +1134,36 @@ export default class ChangeElementTemplateHandler {
});


// (4) remove old linkedResources
// TODO: remove single properties as well as complete linkedResources elements
if (oldLinkedResources.length) {
// (4) remove unused linkedResources
if (unusedLinkedResources.length) {
commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: linkedResources,
properties: {
properties: without(linkedResources.get('values'), linkedResource => oldLinkedResources.includes(linkedResource))
values: without(linkedResources.get('values'), linkedResource => unusedLinkedResources.includes(linkedResource))
}
});
}

// (5) remove unused resource properties
unusedResourceProperties.forEach((unusedResourceProperty) => {
const oldLinkedResource = findBusinessObject(extensionElements, unusedResourceProperty);

const oldBinding = unusedResourceProperty.binding;

// No property was reused and element was removed in previous step
if (!oldLinkedResource) {
return;
}

commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: oldLinkedResource,
properties: {
[oldBinding.property]: undefined
}
});
});
}

}
Expand Down Expand Up @@ -1473,7 +1492,7 @@ function getPropertyValue(element, property) {
function remove(array, item) {
const index = array.indexOf(item);

if (isUndefined(index)) {
if (index < 0) {
return array;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cloud-element-templates/util/bindingTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ZEEBE_TASK_HEADER_TYPE = 'zeebe:taskHeader';
export const MESSAGE_PROPERTY_TYPE = 'bpmn:Message#property';
export const MESSAGE_ZEEBE_SUBSCRIPTION_PROPERTY_TYPE = 'bpmn:Message#zeebe:subscription#property';
export const ZEEBE_CALLED_ELEMENT = 'zeebe:calledElement';
export const ZEEBE_LINKED_RESOURCE_PROPERTY = 'zeebe:linkedResource#property';
export const ZEEBE_LINKED_RESOURCE_PROPERTY = 'zeebe:linkedResource';

export const EXTENSION_BINDING_TYPES = [
MESSAGE_ZEEBE_SUBSCRIPTION_PROPERTY_TYPE,
Expand Down
Loading

0 comments on commit 4b0ff34

Please sign in to comment.