From 134b4e7258e1a15734961f2848f0ade72a13da96 Mon Sep 17 00:00:00 2001
From: Daniel <150448993+sombrek@users.noreply.github.com>
Date: Wed, 31 Jul 2024 16:23:44 +0200
Subject: [PATCH] fix: keep direction when collapsing pools
Closes #2208
---
lib/features/modeling/ElementFactory.js | 11 +-
lib/features/replace/BpmnReplace.js | 17 ++-
.../BpmnReplace.collaboration.vertical.bpmn | 70 ++++++++++++
...BpmnReplace.poolMessageFlows.vertical.bpmn | 46 ++++++++
test/spec/features/replace/BpmnReplaceSpec.js | 101 ++++++++++++++++++
5 files changed, 239 insertions(+), 6 deletions(-)
create mode 100644 test/spec/features/replace/BpmnReplace.collaboration.vertical.bpmn
create mode 100644 test/spec/features/replace/BpmnReplace.poolMessageFlows.vertical.bpmn
diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js
index bcd2647fd5..246661597d 100644
--- a/lib/features/modeling/ElementFactory.js
+++ b/lib/features/modeling/ElementFactory.js
@@ -295,10 +295,17 @@ ElementFactory.prototype.getDefaultSize = function(element, di) {
}
if (is(bo, 'bpmn:Participant')) {
+ var isHorizontalPool = di.isHorizontal === undefined || di.isHorizontal === true;
if (isExpanded(bo, di)) {
- return { width: 600, height: 250 };
+ if (isHorizontalPool) {
+ return { width: 600, height: 250 };
+ }
+ return { width: 250, height: 600 };
} else {
- return { width: 400, height: 60 };
+ if (isHorizontalPool) {
+ return { width: 400, height: 60 };
+ }
+ return { width: 60, height: 400 };
}
}
diff --git a/lib/features/replace/BpmnReplace.js b/lib/features/replace/BpmnReplace.js
index 958bb7ebb4..8449614664 100644
--- a/lib/features/replace/BpmnReplace.js
+++ b/lib/features/replace/BpmnReplace.js
@@ -10,6 +10,7 @@ import {
import {
is,
+ getDi,
getBusinessObject
} from '../../util/ModelUtil';
@@ -19,7 +20,8 @@ import {
import {
isExpanded,
- isEventSubProcess
+ isEventSubProcess,
+ isHorizontal
} from '../../util/DiUtil';
import { getPropertyNames } from '../copy-paste/ModdleCopy';
@@ -284,9 +286,16 @@ export default function BpmnReplace(
hints.moveChildren = false;
}
- // apply same width and default height
- newElement.width = element.width;
- newElement.height = elementFactory.getDefaultSize(newElement).height;
+ // apply same directionality
+ var isHorizontalPool = isHorizontal(element);
+ if (!getDi(element).isHorizontal) {
+ getDi(newElement).isHorizontal = isHorizontalPool;
+ }
+
+ // keep the existing size of the pool's direction to
+ // prevent dangling message flows
+ newElement.width = isHorizontalPool ? element.width : elementFactory.getDefaultSize(newElement).width;
+ newElement.height = isHorizontalPool ? elementFactory.getDefaultSize(newElement).height : element.height;
}
if (!rules.allowed('shape.resize', { shape: newBusinessObject })) {
diff --git a/test/spec/features/replace/BpmnReplace.collaboration.vertical.bpmn b/test/spec/features/replace/BpmnReplace.collaboration.vertical.bpmn
new file mode 100644
index 0000000000..1c33fab2c1
--- /dev/null
+++ b/test/spec/features/replace/BpmnReplace.collaboration.vertical.bpmn
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ Task_1
+ EndEvent_1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/spec/features/replace/BpmnReplace.poolMessageFlows.vertical.bpmn b/test/spec/features/replace/BpmnReplace.poolMessageFlows.vertical.bpmn
new file mode 100644
index 0000000000..ae566ff744
--- /dev/null
+++ b/test/spec/features/replace/BpmnReplace.poolMessageFlows.vertical.bpmn
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/spec/features/replace/BpmnReplaceSpec.js b/test/spec/features/replace/BpmnReplaceSpec.js
index 9e400cbac0..88ee7053c6 100644
--- a/test/spec/features/replace/BpmnReplaceSpec.js
+++ b/test/spec/features/replace/BpmnReplaceSpec.js
@@ -440,6 +440,7 @@ describe('features/replace - bpmn replace', function() {
// then
expect(isExpanded(newShape)).to.be.false; // collapsed
expect(newShape.children).to.be.empty;
+ expect(newShape.di.isHorizontal).to.be.true;
expect(newShape).to.have.bounds(collapsedBounds);
@@ -466,6 +467,72 @@ describe('features/replace - bpmn replace', function() {
// then
expect(isExpanded(newShape)).to.be.true; // expanded
expect(newShape.children).to.be.empty;
+ expect(newShape.di.isHorizontal).to.be.true;
+
+ expect(newShape).to.have.bounds(expandedBounds);
+ }));
+
+ });
+
+
+ describe('should replace in vertical collaboration', function() {
+
+ var diagramXML = require('./BpmnReplace.collaboration.vertical.bpmn');
+
+ beforeEach(bootstrapModeler(diagramXML, {
+ modules: testModules,
+ moddleExtensions: {
+ camunda: camundaPackage
+ }
+ }));
+
+
+ it('expanded with collapsed pool', inject(function(elementRegistry, bpmnReplace) {
+
+ // given
+ var shape = elementRegistry.get('V_Participant_1');
+
+ var messageFlow = elementRegistry.get('V_MessageFlow_B_to_A');
+
+ var collapsedBounds = assign({}, getBounds(shape), { width: 60 });
+
+ // when
+ var newShape = bpmnReplace.replaceElement(shape, {
+ type: 'bpmn:Participant',
+ isExpanded: false
+ });
+
+ // then
+ expect(isExpanded(newShape)).to.be.false; // collapsed
+ expect(newShape.children).to.be.empty;
+ expect(newShape.di.isHorizontal).to.be.false;
+
+ expect(newShape).to.have.bounds(collapsedBounds);
+
+ expect(messageFlow).to.have.waypoints([
+ { x: 436, y: 368 },
+ { x: newShape.x + collapsedBounds.width, y: 368 }
+ ]);
+ }));
+
+
+ it('collapsed with expanded pool', inject(function(elementRegistry, bpmnReplace) {
+
+ // given
+ var shape = elementRegistry.get('V_Participant_2');
+
+ var expandedBounds = assign({}, getBounds(shape), { width: 250 });
+
+ // when
+ var newShape = bpmnReplace.replaceElement(shape, {
+ type: 'bpmn:Participant',
+ isExpanded: true
+ });
+
+ // then
+ expect(isExpanded(newShape)).to.be.true; // expanded
+ expect(newShape.children).to.be.empty;
+ expect(newShape.di.isHorizontal).to.be.false;
expect(newShape).to.have.bounds(expandedBounds);
}));
@@ -507,6 +574,40 @@ describe('features/replace - bpmn replace', function() {
});
+ describe('should collapse vertical pool, reconnecting message flows', function() {
+
+ var diagramXML = require('./BpmnReplace.poolMessageFlows.vertical.bpmn');
+
+ beforeEach(bootstrapModeler(diagramXML, {
+ modules: testModules,
+ moddleExtensions: {
+ camunda: camundaPackage
+ }
+ }));
+
+
+ it('expanded with collapsed pool', inject(function(elementRegistry, bpmnReplace) {
+
+ // given
+ var shape = elementRegistry.get('V_Participant_1');
+
+ // when
+ var newShape = bpmnReplace.replaceElement(shape, {
+ type: 'bpmn:Participant',
+ isExpanded: false
+ });
+
+ // then
+ expect(isExpanded(newShape)).to.be.false; // collapsed
+ expect(newShape.children).to.be.empty;
+
+ expect(elementRegistry.get('V_MessageFlow_1')).to.exist;
+ expect(elementRegistry.get('V_MessageFlow_2')).to.exist;
+ }));
+
+ });
+
+
describe('should replace with data objects', function() {
var diagramXML = require('./BpmnReplace.dataObjects.bpmn');