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

fix: remove zeebe:subscription if no properties left #24

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 40 additions & 10 deletions src/cloud-element-templates/util/propertyUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,24 +729,38 @@ export function unsetProperty(commandStack, element, property) {
});
}

// bpmn:Message#property
// bpmn:Message#zeebe:subscription#property
if (type === MESSAGE_ZEEBE_SUBSCRIPTION_PROPERTY_TYPE) {
const subscription = findZeebeSubscription(businessObject);

if (!subscription) {
return;
}

commands.push({
cmd: 'element.updateModdleProperties',
context: {
...context,
moddleElement: subscription,
properties: {
[ binding.name ]: undefined
// remove subscription of none properties are left
if (noPropertiesLeft(subscription, binding.name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is to handle this via a behavior, cf. camunda-bpmn-js-behaviors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm perhaps it makes more sense. I declined this option initially because I thought it's an element-templates-only problem, but the cleanup is broken also in non-templated messages.

commands.push({
cmd: 'element.updateModdleProperties',
context: {
...context,
moddleElement: extensionElements,
properties: {
values: without(extensionElements.get('values'), subscription)
}
}
}
});
});
} else {
commands.push({
cmd: 'element.updateModdleProperties',
context: {
...context,
moddleElement: subscription,
properties: {
[ binding.name ]: undefined
}
}
});
}
}


Expand Down Expand Up @@ -828,3 +842,19 @@ function isEmpty(value) {
function matchesPattern(string, pattern) {
return new RegExp(pattern).test(string);
}

/**
* Check if no properties are left on element besides `ignored`.
*
* @param {ModdleElement} moddleElement
* @param {string} ignored
*/
function noPropertiesLeft(moddleElement, ignored) {
const descriptor = moddleElement.$descriptor;

return descriptor.properties.every((property) => {
const { name } = property;

return name === ignored || moddleElement.get(name) === undefined;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ describe('provider/cloud-element-templates - ElementTemplatesConditionChecker',
const message = findMessage(getBusinessObject(element));
const subscription = findZeebeSubscription(message);

expect(subscription).not.to.have.property('correlationKey');
expect(subscription).to.not.exist;
})
);

Expand Down Expand Up @@ -969,20 +969,24 @@ describe('provider/cloud-element-templates - ElementTemplatesConditionChecker',
// given
let element = elementRegistry.get('SubscriptionEvent_1');
const property = findExtension(element, 'zeebe:Properties').get('properties')[0];
const getSubscription = () => {
const message = findMessage(getBusinessObject(element));
return findZeebeSubscription(message);
};

// when
modeling.updateModdleProperties(element, property, {
value: 'three'
});

// assume
const message = findMessage(getBusinessObject(element));
const subscription = findZeebeSubscription(message);
expect(subscription).not.to.have.property('correlationKey');
let subscription = getSubscription();
expect(subscription).to.not.exist;

// when
commandStack.undo();

subscription = getSubscription();
expect(subscription).to.have.property('correlationKey', 'one');
}));

Expand All @@ -992,27 +996,33 @@ describe('provider/cloud-element-templates - ElementTemplatesConditionChecker',
// given
let element = elementRegistry.get('SubscriptionEvent_1');
const property = findExtension(element, 'zeebe:Properties').get('properties')[0];
const getSubscription = () => {
const message = findMessage(getBusinessObject(element));
return findZeebeSubscription(message);
};

// when
modeling.updateModdleProperties(element, property, {
value: 'three'
});

// assume
const message = findMessage(getBusinessObject(element));
const subscription = findZeebeSubscription(message);
let subscription = getSubscription();
expect(subscription).to.not.exist;

// when
commandStack.undo();

// assume
subscription = getSubscription();
expect(subscription).to.have.property('correlationKey', 'one');

// when
commandStack.redo();

// then
expect(subscription).not.to.have.property('correlationKey');
subscription = getSubscription();
expect(subscription).to.not.exist;
}));


Expand Down