Skip to content

Commit

Permalink
fix: move labels to new plane when collapsing sub process
Browse files Browse the repository at this point in the history
Closes #1695
  • Loading branch information
philippfromme committed Aug 18, 2022
1 parent 8950d42 commit 5206dc8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/features/modeling/behavior/SubProcessPlaneBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,15 @@ SubProcessPlaneBehavior.prototype._moveChildrenToShape = function(source, target
return;
}

// add external labels that weren't children of sub process
children = children.concat(children.reduce((labels, child) => {
if (child.label && child.label.parent !== source) {
return labels.concat(child.label);
}

return labels;
}, []));

// only change plane if there are no visible children, but don't move them
var visibleChildren = children.filter(function(child) {
return !child.hidden;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_007va6i" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.2.0-dev">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_007va6i" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.2.0">
<bpmn:process id="Process_1giw3j5" isExecutable="true">
<bpmn:task id="Task_1" />
<bpmn:subProcess id="SubProcess_1" />
<bpmn:subProcess id="SubProcess_2">
<bpmn:startEvent id="StartEvent_1" name="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Task_2">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="Task_2" />
</bpmn:subProcess>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1giw3j5">
Expand All @@ -12,6 +21,22 @@
<bpmndi:BPMNShape id="SubProcess_01nq2r1_di" bpmnElement="SubProcess_1" isExpanded="true">
<dc:Bounds x="160" y="280" width="350" height="200" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_169gyur_di" bpmnElement="SubProcess_2" isExpanded="true">
<dc:Bounds x="160" y="550" width="350" height="200" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1660c5c_di" bpmnElement="SequenceFlow_1">
<di:waypoint x="236" y="650" />
<di:waypoint x="290" y="650" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_017zosw_di" bpmnElement="StartEvent_1">
<dc:Bounds x="200" y="632" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="187" y="675" width="64" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_05ptqa9_di" bpmnElement="Task_2">
<dc:Bounds x="290" y="610" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,41 @@ describe('features/modeling/behavior - subprocess planes', function() {
}));


it('should move labels to plane for collapsed subprocess', inject(
function(canvas, bpmnReplace, elementRegistry, modeling) {

// given
var sequenceFlow = elementRegistry.get('SequenceFlow_1'),
startEvent = elementRegistry.get('StartEvent_1'),
subProcess = elementRegistry.get('SubProcess_2'),
task = elementRegistry.get('Task_2');

// moving label will set its parent to root element
modeling.moveShape(startEvent.label, { x: 0, y: 100 }, subProcess);

// assume
expect(sequenceFlow.parent).to.equal(subProcess);
expect(startEvent.parent).to.equal(subProcess);
expect(startEvent.label.parent).to.equal(canvas.getRootElement());
expect(task.parent).to.equal(subProcess);

// when
bpmnReplace.replaceElement(subProcess, {
type: 'bpmn:SubProcess',
isExpanded: false
});

// then
const plane = elementRegistry.get('SubProcess_2_plane');

expect(sequenceFlow.parent).to.equal(plane);
expect(startEvent.parent).to.equal(plane);
expect(startEvent.label.parent).to.equal(plane);
expect(task.parent).to.equal(plane);
}
));


it('should undo', inject(function(elementFactory, modeling, commandStack, canvas, bpmnjs) {

// given
Expand Down

0 comments on commit 5206dc8

Please sign in to comment.