Skip to content

Commit 168a149

Browse files
committed
fix(modeling): do not duplicate flow node refs
Closes: camunda/camunda-modeler#1504
1 parent 37bcd07 commit 168a149

File tree

3 files changed

+79
-22
lines changed

3 files changed

+79
-22
lines changed

lib/features/modeling/cmd/UpdateFlowNodeRefsHandler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ UpdateFlowNodeRefsHandler.$inject = [
3434

3535
UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, laneShapes) {
3636

37-
var handledNodes = {};
37+
var handledNodes = [];
3838

3939
var updates = [];
4040

@@ -58,9 +58,9 @@ UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, la
5858
}
5959

6060
function addFlowNodeShape(flowNodeShape) {
61-
if (!handledNodes[flowNodeShape.id]) {
61+
if (handledNodes.indexOf(flowNodeShape) === -1) {
6262
allFlowNodeShapes.push(flowNodeShape);
63-
handledNodes[flowNodeShape.id] = flowNodeShape;
63+
handledNodes.push(flowNodeShape);
6464
}
6565
}
6666

@@ -92,7 +92,7 @@ UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, la
9292
laneShapes.forEach(function(laneShape) {
9393
var root = getLanesRoot(laneShape);
9494

95-
if (!root || handledNodes[root.id]) {
95+
if (!root || handledNodes.indexOf(root) !== -1) {
9696
return;
9797
}
9898

@@ -102,7 +102,7 @@ UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, la
102102

103103
children.forEach(addFlowNodeShape);
104104

105-
handledNodes[root.id] = root;
105+
handledNodes.push(root);
106106
});
107107

108108
flowNodeShapes.forEach(addFlowNodeShape);
@@ -190,4 +190,4 @@ UpdateFlowNodeRefsHandler.prototype.revert = function(context) {
190190

191191
// TODO(nikku): return changed elements
192192
// return [ ... ];
193-
};
193+
};

test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,28 @@ describe('features/modeling - lanes - flowNodeRefs', function() {
266266
expect(sourceLane.flowNodeRef).not.to.contain(event);
267267
}));
268268

269+
270+
it('should not create duplicate refs on attaching / detaching', inject(function(elementRegistry, modeling) {
271+
272+
// given
273+
var eventID = 'IntermediateThrowEvent',
274+
throwEvent = elementRegistry.get(eventID),
275+
task1 = elementRegistry.get('Task_1'),
276+
task2 = elementRegistry.get('Task_2'),
277+
lane1 = elementRegistry.get('Participant_C_Lane_1').businessObject,
278+
lane2 = elementRegistry.get('Participant_C_Lane_2').businessObject;
279+
280+
// when
281+
modeling.moveElements([ throwEvent ], { x: -280, y: 30 }, task1, { attach: true });
282+
283+
var boundaryEvent = elementRegistry.get(eventID);
284+
285+
modeling.moveElements([ boundaryEvent ], { x: 0, y: 150 }, task2, { attach: true });
286+
287+
// then
288+
expect(lane1.flowNodeRef).not.to.contain(boundaryEvent.businessObject);
289+
expect(lane2.flowNodeRef).to.contain(boundaryEvent.businessObject);
290+
expect(lane1.flowNodeRef).to.have.length(1);
291+
expect(lane2.flowNodeRef).to.have.length(2);
292+
}));
269293
});
Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="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" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_2_FUoE-xEeWT0c1N_GlSWA" exporter="camunda modeler" exporterVersion="2.6.0" targetNamespace="http://activiti.org/bpmn">
2+
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="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="_2_FUoE-xEeWT0c1N_GlSWA" targetNamespace="http://activiti.org/bpmn" exporter="Camunda Modeler" exporterVersion="3.4.0-dev" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
33
<bpmn2:collaboration id="_Collaboration_2">
4-
<bpmn2:participant id="Participant_A" name="Participant_A" processRef="Process_A"/>
5-
<bpmn2:participant id="Participant_B" name="Participant_B" processRef="Process_B"/>
4+
<bpmn2:participant id="Participant_A" name="Participant_A" processRef="Process_A" />
5+
<bpmn2:participant id="Participant_B" name="Participant_B" processRef="Process_B" />
6+
<bpmn2:participant id="Participant_0emukbw" name="Participant_C" processRef="Process_1gjk6nk" />
67
</bpmn2:collaboration>
78
<bpmn2:process id="Process_A" isExecutable="false">
89
<bpmn2:laneSet id="LaneSet_1" name="Lane Set 1">
@@ -14,44 +15,76 @@
1415
<bpmn2:task id="Task_A" name="Task_A">
1516
<bpmn2:outgoing>SequenceFlow</bpmn2:outgoing>
1617
</bpmn2:task>
17-
<bpmn2:sequenceFlow id="SequenceFlow" name="" sourceRef="Task_A" targetRef="Event"/>
1818
<bpmn2:intermediateCatchEvent id="Event" name="Event">
1919
<bpmn2:incoming>SequenceFlow</bpmn2:incoming>
2020
</bpmn2:intermediateCatchEvent>
21+
<bpmn2:sequenceFlow id="SequenceFlow" name="" sourceRef="Task_A" targetRef="Event" />
2122
</bpmn2:process>
2223
<bpmn2:process id="Process_B" isExecutable="false">
23-
<bpmn2:task id="Task_B" name="Task_B"/>
24+
<bpmn2:task id="Task_B" name="Task_B" />
25+
</bpmn2:process>
26+
<bpmn2:process id="Process_1gjk6nk" isExecutable="false">
27+
<bpmn2:laneSet id="LaneSet_06y7y48">
28+
<bpmn2:lane id="Participant_C_Lane_1">
29+
<bpmn2:flowNodeRef>Task_1</bpmn2:flowNodeRef>
30+
<bpmn2:flowNodeRef>IntermediateThrowEvent</bpmn2:flowNodeRef>
31+
</bpmn2:lane>
32+
<bpmn2:lane id="Participant_C_Lane_2">
33+
<bpmn2:flowNodeRef>Task_2</bpmn2:flowNodeRef>
34+
</bpmn2:lane>
35+
</bpmn2:laneSet>
36+
<bpmn2:task id="Task_1" />
37+
<bpmn2:task id="Task_2" />
38+
<bpmn2:intermediateThrowEvent id="IntermediateThrowEvent" />
2439
</bpmn2:process>
2540
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
2641
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="_Collaboration_2">
2742
<bpmndi:BPMNShape id="_BPMNShape_Participant_2" bpmnElement="Participant_A" isHorizontal="true">
28-
<dc:Bounds height="145.0" width="540.0" x="84.0" y="96.0"/>
43+
<dc:Bounds x="154" y="96" width="540" height="145" />
2944
</bpmndi:BPMNShape>
3045
<bpmndi:BPMNShape id="_BPMNShape_Participant_3" bpmnElement="Participant_B" isHorizontal="true">
31-
<dc:Bounds height="133.0" width="540.0" x="84.0" y="312.0"/>
46+
<dc:Bounds x="154" y="312" width="540" height="133" />
3247
</bpmndi:BPMNShape>
3348
<bpmndi:BPMNShape id="_BPMNShape_Task_2" bpmnElement="Task_A">
34-
<dc:Bounds height="80.0" width="100.0" x="168.0" y="129.0"/>
49+
<dc:Bounds x="238" y="129" width="100" height="80" />
3550
</bpmndi:BPMNShape>
3651
<bpmndi:BPMNShape id="_BPMNShape_Lane_2" bpmnElement="Lane" isHorizontal="true">
37-
<dc:Bounds height="145.0" width="510.0" x="114.0" y="96.0"/>
52+
<dc:Bounds x="184" y="96" width="510" height="145" />
3853
</bpmndi:BPMNShape>
3954
<bpmndi:BPMNShape id="_BPMNShape_IntermediateCatchEvent_2" bpmnElement="Event">
40-
<dc:Bounds height="36.0" width="36.0" x="384.0" y="151.0"/>
55+
<dc:Bounds x="454" y="151" width="36" height="36" />
4156
<bpmndi:BPMNLabel>
42-
<dc:Bounds height="21.0" width="112.0" x="346.0" y="192.0"/>
57+
<dc:Bounds x="458" y="192" width="29" height="14" />
4358
</bpmndi:BPMNLabel>
4459
</bpmndi:BPMNShape>
4560
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow" sourceElement="_BPMNShape_Task_2" targetElement="_BPMNShape_IntermediateCatchEvent_2">
46-
<di:waypoint xsi:type="dc:Point" x="268.0" y="169.0"/>
47-
<di:waypoint xsi:type="dc:Point" x="384.0" y="169.0"/>
61+
<di:waypoint x="338" y="169" />
62+
<di:waypoint x="454" y="169" />
4863
<bpmndi:BPMNLabel>
49-
<dc:Bounds height="6.0" width="6.0" x="290.0" y="169.0"/>
64+
<dc:Bounds x="290" y="169" width="6" height="6" />
5065
</bpmndi:BPMNLabel>
5166
</bpmndi:BPMNEdge>
5267
<bpmndi:BPMNShape id="_BPMNShape_Task_3" bpmnElement="Task_B">
53-
<dc:Bounds height="80.0" width="100.0" x="492.0" y="339.0"/>
68+
<dc:Bounds x="562" y="339" width="100" height="80" />
69+
</bpmndi:BPMNShape>
70+
<bpmndi:BPMNShape id="Participant_0emukbw_di" bpmnElement="Participant_0emukbw" isHorizontal="true">
71+
<dc:Bounds x="154" y="475" width="540" height="285" />
72+
</bpmndi:BPMNShape>
73+
<bpmndi:BPMNShape id="Lane_0lsm3hs_di" bpmnElement="Participant_C_Lane_1" isHorizontal="true">
74+
<dc:Bounds x="184" y="475" width="510" height="150" />
75+
</bpmndi:BPMNShape>
76+
<bpmndi:BPMNShape id="Lane_16dmnot_di" bpmnElement="Participant_C_Lane_2" isHorizontal="true">
77+
<dc:Bounds x="184" y="625" width="510" height="135" />
78+
</bpmndi:BPMNShape>
79+
<bpmndi:BPMNShape id="Task_1abs8bh_di" bpmnElement="Task_1">
80+
<dc:Bounds x="230" y="510" width="100" height="80" />
81+
</bpmndi:BPMNShape>
82+
<bpmndi:BPMNShape id="IntermediateThrowEvent_0oto7vx_di" bpmnElement="IntermediateThrowEvent">
83+
<dc:Bounds x="592" y="532" width="36" height="36" />
84+
</bpmndi:BPMNShape>
85+
<bpmndi:BPMNShape id="Task_0j7a294_di" bpmnElement="Task_2">
86+
<dc:Bounds x="230" y="650" width="100" height="80" />
5487
</bpmndi:BPMNShape>
5588
</bpmndi:BPMNPlane>
5689
</bpmndi:BPMNDiagram>
57-
</bpmn2:definitions>
90+
</bpmn2:definitions>

0 commit comments

Comments
 (0)