Skip to content

Commit

Permalink
fix: check for replacement using actual target
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac authored and fake-join[bot] committed Jul 13, 2022
1 parent c1d0e3d commit 9b66c97
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/features/modeling/behavior/ReplaceElementBehaviour.js
@@ -1,6 +1,6 @@
import inherits from 'inherits-browser';

import { forEach } from 'min-dash';
import { forEach, reduce } from 'min-dash';

import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

Expand Down Expand Up @@ -30,10 +30,14 @@ export default function ReplaceElementBehaviour(
target = context.parent,
elements = context.elements;

var canReplace = bpmnRules.canReplace(elements, target);
var elementReplacements = reduce(elements, function(replacements, element) {
var canReplace = bpmnRules.canReplace([ element ], element.host || element.parent || target);

if (canReplace) {
this.replaceElements(elements, canReplace.replacements);
return canReplace ? replacements.concat(canReplace.replacements) : replacements;
}, []);

if (elementReplacements.length) {
this.replaceElements(elements, elementReplacements);
}
}, this);

Expand Down
Expand Up @@ -7,8 +7,12 @@ import replacePreviewModule from 'lib/features/replace-preview';
import modelingModule from 'lib/features/modeling';
import moveModule from 'diagram-js/lib/features/move';
import coreModule from 'lib/core';
import copyPasteModule from 'lib/features/copy-paste';

import { is } from 'lib/util/ModelUtil';
import {
getBusinessObject,
is
} from 'lib/util/ModelUtil';

import {
createCanvasEvent as canvasEvent
Expand All @@ -29,7 +33,8 @@ describe('features/modeling - replace element behavior', function() {
replacePreviewModule,
modelingModule,
coreModule,
moveModule
moveModule,
copyPasteModule
];


Expand Down Expand Up @@ -110,6 +115,38 @@ describe('features/modeling - replace element behavior', function() {
})
);


it('should not replace non-interrupting start event after copy paste',
inject(function(canvas, copyPaste, elementRegistry) {

// given
var subProcess = elementRegistry.get('SubProcess_1'),
rootElement = canvas.getRootElement();

// when
copyPaste.copy(subProcess);

var elements = copyPaste.paste({
element: rootElement,
point: {
x: 100,
y: 100
}
});

// then
var startEvents = elements.filter(function(element) {
if (is(element, 'bpmn:StartEvent') && getBusinessObject(element).get('eventDefinitions').length) {
return true;
}
});

startEvents.forEach(function(startEvent) {
expect(getBusinessObject(startEvent).get('isInterrupting')).to.be.false;
});
})
);

});


Expand Down

0 comments on commit 9b66c97

Please sign in to comment.