Skip to content

Commit 3588b52

Browse files
committed
fix(copy-paste): do not copy message flows without participant
Closes #1902
1 parent 22d59fd commit 3588b52

File tree

3 files changed

+61
-12
lines changed

3 files changed

+61
-12
lines changed

Diff for: lib/features/rules/BpmnRules.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -1143,16 +1143,6 @@ function canInsert(shape, connection, position) {
11431143
canDrop(shape, connection.parent, position));
11441144
}
11451145

1146-
/**
1147-
* @param {Element[]} elements
1148-
* @param {Element} element
1149-
*
1150-
* @return {boolean}
1151-
*/
1152-
function includes(elements, element) {
1153-
return (elements && element) && elements.indexOf(element) !== -1;
1154-
}
1155-
11561146
/**
11571147
* @param {Element[]} elements
11581148
* @param {Element} element
@@ -1164,10 +1154,18 @@ function canCopy(elements, element) {
11641154
return true;
11651155
}
11661156

1167-
if (is(element, 'bpmn:Lane') && !includes(elements, element.parent)) {
1157+
if (is(element, 'bpmn:Lane') && !elements.includes(element.parent)) {
11681158
return false;
11691159
}
11701160

1161+
if (is(element, 'bpmn:MessageFlow')) {
1162+
const source = element.source,
1163+
target = element.target;
1164+
1165+
return elements.includes(is(source, 'bpmn:Participant') ? source : getParent(source, 'bpmn:Participant'))
1166+
&& elements.includes(is(target, 'bpmn:Participant') ? target : getParent(target, 'bpmn:Participant'));
1167+
}
1168+
11711169
return true;
11721170
}
11731171

@@ -1178,4 +1176,4 @@ function canCopy(elements, element) {
11781176
*/
11791177
function getRootElement(element) {
11801178
return getParent(element, 'bpmn:Process') || getParent(element, 'bpmn:Collaboration');
1181-
}
1179+
}

Diff for: test/spec/features/copy-paste/BpmnCopyPasteSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,31 @@ describe('features/copy-paste', function() {
964964

965965
});
966966

967+
968+
describe('rules', function() {
969+
970+
beforeEach(bootstrapModeler(collaborationMultipleXML, {
971+
modules: testModules,
972+
moddleExtensions: {
973+
camunda: camundaPackage
974+
}
975+
}));
976+
977+
978+
it.only('should allow copying message flow with parent participants of source and target', inject(function(elementRegistry) {
979+
980+
// when
981+
var tree = copy([ 'IntermediateThrowEvent_1', 'Task_2', 'MessageFlow_1' ]);
982+
983+
console.log(tree, keys(tree));
984+
985+
// then
986+
expect(keys(tree)).to.have.length(1);
987+
expect(getAllElementsInTree(tree, 0)).to.have.length(2);
988+
}));
989+
990+
});
991+
967992
});
968993

969994

Diff for: test/spec/features/rules/BpmnRulesSpec.js

+26
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,32 @@ describe('features/modeling/rules - BpmnRules', function() {
220220
expectCanCopy(boundaryEvent, [ boundaryEvent ], true);
221221
}));
222222

223+
224+
it('copy message flow with parent participants of source and target', inject(function(elementFactory) {
225+
226+
// given
227+
var sourceParticipant = elementFactory.createShape({ type: 'bpmn:Participant' }),
228+
targetParticipant = elementFactory.createShape({ type: 'bpmn:Participant' }),
229+
source = elementFactory.createShape({ type: 'bpmn:Task', parent: sourceParticipant }),
230+
target = elementFactory.createShape({ type: 'bpmn:Task', parent: targetParticipant }),
231+
messageFlow = elementFactory.createConnection({ type: 'bpmn:MessageFlow', source: source, target: target, waypoints: [] });
232+
233+
// then
234+
expectCanCopy(messageFlow, [ sourceParticipant, targetParticipant, source, target, messageFlow ], true);
235+
}));
236+
237+
238+
it('copy message flow without parent participants of source and target', inject(function(elementFactory) {
239+
240+
// given
241+
var source = elementFactory.createShape({ type: 'bpmn:Task' }),
242+
target = elementFactory.createShape({ type: 'bpmn:Task' }),
243+
messageFlow = elementFactory.createConnection({ type: 'bpmn:MessageFlow', source: source, target: target, waypoints: [] });
244+
245+
// then
246+
expectCanCopy(messageFlow, [ source, target, messageFlow ], false);
247+
}));
248+
223249
});
224250

225251

0 commit comments

Comments
 (0)