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

feat: relax zeebe:TaskListeners cleanup based on event types #92

Merged
merged 1 commit into from
Dec 13, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to [camunda-bpmn-js-behaviors](https://github.com/camunda/ca

___Note:__ Yet to be released changes appear here._

## 1.9.0

* `FEAT`: relax `zeebe:TaskListeners` cleanup based on event types ([#92](https://github.com/camunda/camunda-bpmn-js-behaviors/pull/92))

## 1.8.0

* `FEAT`: make `Zeebe user task` the default implementation of user task ([#86](https://github.com/camunda/camunda-bpmn-js-behaviors/pull/86))
Expand Down
2 changes: 0 additions & 2 deletions lib/camunda-cloud/CleanUpTaskListenersBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { without } from 'min-dash';

import { getExtensionElementsList } from '../util/ExtensionElementsUtil';

const ALLOWED_EVENT_TYPES = [ 'complete', 'assignment' ];

export default class CleanUpTaskListenersBehavior extends CommandInterceptor {
constructor(eventBus, modeling) {
Expand Down Expand Up @@ -74,7 +73,6 @@ function withoutDisallowedListeners(element, listeners) {
return listeners.filter(listener => {
if (
!is(element, 'bpmn:UserTask') ||
!ALLOWED_EVENT_TYPES.includes(listener.eventType) ||
Copy link
Member

Choose a reason for hiding this comment

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

I think this is generally a better behavior now. We should not cleanup everything, rigidly, always, and this is such a case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

!hasZeebeTaskExtensionElement(element)
) {
return false;
Expand Down
77 changes: 17 additions & 60 deletions test/camunda-cloud/CleanUpTaskListenersBehaviorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,66 +94,7 @@ describe('camunda-cloud/features/modeling - CleanUpTaskListenersBehavior', funct
}
});

describe('should remove task listeners of disallowed type', function() {

it('should execute', inject(function(bpmnReplace, elementRegistry) {

// given
let el = elementRegistry.get('UserTaskWrongType');

// when
bpmnReplace.replaceElement(el, {
type: 'bpmn:UserTask'
});

// then
el = elementRegistry.get('UserTaskWrongType');
const taskListenersContainer = getTaskListenersContainer(el);

expect(taskListenersContainer.get('listeners')).to.have.lengthOf(1);
}));


it('should undo', inject(function(bpmnReplace, commandStack, elementRegistry) {

// given
let el = elementRegistry.get('UserTaskWrongType');

// when
bpmnReplace.replaceElement(el, {
type: 'bpmn:UserTask'
});

commandStack.undo();

// then
el = elementRegistry.get('UserTaskWrongType');
const taskListenersContainer = getTaskListenersContainer(el);

expect(taskListenersContainer.get('listeners')).to.have.lengthOf(2);
}));


it('should redo', inject(function(bpmnReplace, commandStack, elementRegistry) {

// given
let el = elementRegistry.get('UserTaskWrongType');

// when
bpmnReplace.replaceElement(el, {
type: 'bpmn:UserTask'
});

commandStack.undo();
commandStack.redo();

// then
el = elementRegistry.get('UserTaskWrongType');
const taskListenersContainer = getTaskListenersContainer(el);

expect(taskListenersContainer.get('listeners')).to.have.lengthOf(1);
}));

describe('zeebe:TaskListeners removal', function() {

it('should remove zeebe:TaskListeners container when empty', inject(function(elementRegistry, modeling) {

Expand Down Expand Up @@ -206,6 +147,22 @@ describe('camunda-cloud/features/modeling - CleanUpTaskListenersBehavior', funct
expect(userTask).to.exist;
expect(formDefinition).to.exist;
}));


it('should NOT remove task listeners of unknown event type', inject(function(elementRegistry, modeling) {

// given
const el = elementRegistry.get('UserTaskWrongType');

// when
modeling.updateModdleProperties(el, getBusinessObject(el), { name: 'newName' });

// then
const taskListenersContainer = getTaskListenersContainer(el);

expect(taskListenersContainer).to.exist;
expect(taskListenersContainer.get('listeners')).to.have.lengthOf(2);
}));
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/camunda-cloud/task-listeners.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>
Loading