Skip to content

Commit

Permalink
fix(modeling): do not remove connection that is being created
Browse files Browse the repository at this point in the history
Closes #2068
  • Loading branch information
philippfromme committed Jan 5, 2024
1 parent 028cd20 commit 3578990
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
21 changes: 12 additions & 9 deletions lib/features/modeling/behavior/CompensateBoundaryEventBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ export default function CompensateBoundaryEventBehavior(eventBus, modeling, bpmn
* Add `isForCompensation` property and make sure only a single compensation activity is connected.
*/
function handleNewConnection(context) {
const source = context.source,
const connection = context.connection,
source = context.source,
target = context.target;

if (isCompensationBoundaryEvent(source) && canBeForCompensation(target)) {
if (isCompensationBoundaryEvent(source) && isForCompensationAllowed(target)) {
addIsForCompensationProperty(target);
removeExistingAssociation(source);
removeExistingAssociations(source, [ connection ]);
}
}

Expand All @@ -69,7 +70,7 @@ export default function CompensateBoundaryEventBehavior(eventBus, modeling, bpmn
}

// newTarget perspective
if (isCompensationBoundaryEvent(source) && canBeForCompensation(newTarget)) {
if (isCompensationBoundaryEvent(source) && isForCompensationAllowed(newTarget)) {
addIsForCompensationProperty(newTarget);
}
}
Expand All @@ -81,7 +82,7 @@ export default function CompensateBoundaryEventBehavior(eventBus, modeling, bpmn
if (isForCompensation(element)) {
removeDisallowedConnections(element);
removeAttachments(element);
} else if (canBeForCompensation(element)) {
} else if (isForCompensationAllowed(element)) {
removeIncomingCompensationAssociations(element);
}
}
Expand Down Expand Up @@ -115,7 +116,7 @@ export default function CompensateBoundaryEventBehavior(eventBus, modeling, bpmn
targetElement.type === 'bpmn:BoundaryEvent'
) {
const targetConnection = oldShape.outgoing.find(
({ target }) => canBeForCompensation(target)
({ target }) => isForCompensationAllowed(target)
);

if (targetConnection && targetConnection.target) {
Expand Down Expand Up @@ -157,9 +158,11 @@ export default function CompensateBoundaryEventBehavior(eventBus, modeling, bpmn
}
}

function removeExistingAssociation(boundaryEvent) {
function removeExistingAssociations(boundaryEvent, ignoredAssociations) {
const associations = boundaryEvent.outgoing.filter(connection => is(connection, 'bpmn:Association'));
const associationsToRemove = associations.filter(association => isForCompensation(association.target));
const associationsToRemove = associations.filter(association => {
return isForCompensation(association.target) && !ignoredAssociations.includes(association);
});

// remove existing associations
associationsToRemove.forEach(association => modeling.removeConnection(association));
Expand Down Expand Up @@ -212,6 +215,6 @@ function isCompensationBoundaryEvent(element) {
hasEventDefinition(element, 'bpmn:CompensateEventDefinition');
}

function canBeForCompensation(element) {
function isForCompensationAllowed(element) {
return element && is(element, 'bpmn:Activity') && !isEventSubProcess(element);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import {
inject
} from 'test/TestHelper';

import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
import { is } from 'lib/util/ModelUtil';

import copyPasteModule from 'lib/features/copy-paste';
import coreModule from 'lib/core';
import modelingModule from 'lib/features/modeling';

import diagramXML from './CompensateBoundaryEventBehavior.bpmn';


describe('features/modeling/behavior - compensation boundary event', function() {

const testModules = [ coreModule, modelingModule ];
const testModules = [
copyPasteModule,
coreModule,
modelingModule
];

beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));

Expand Down Expand Up @@ -382,4 +388,33 @@ describe('features/modeling/behavior - compensation boundary event', function()
}
));


describe('copy and paste', function() {

it('should NOT break on copy and paste', inject(function(canvas, copyPaste, elementRegistry) {

// given
copyPaste.copy([
elementRegistry.get('Task_BoundaryEvent2'),
elementRegistry.get('Task_Compensation')
]);

// when
var copiedElements = copyPaste.paste({
element: canvas.getRootElement(),
point: {
x: 100,
y: 100
}
});

// then
expect(copiedElements).to.have.lengthOf(4);
expect(copiedElements.filter(element => is(element, 'bpmn:Association'))).to.have.length(1);
expect(copiedElements.filter(element => is(element, 'bpmn:BoundaryEvent'))).to.have.length(1);
expect(copiedElements.filter(element => is(element, 'bpmn:Task'))).to.have.length(2);
}));

});

});

0 comments on commit 3578990

Please sign in to comment.