Skip to content

Commit 61ee0d4

Browse files
committed
fix: event references are not lost when switching elements
Closes #2249, 1906 Related to: camunda/camunda-modeler#4863
1 parent 17bedb2 commit 61ee0d4

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

lib/features/copy-paste/ModdleCopy.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212

1313
import { is } from '../../util/ModelUtil';
1414

15+
import { hasAnyEventDefinition } from '../../util/DiUtil';
16+
1517
var DISALLOWED_PROPERTIES = [
1618
'artifacts',
1719
'dataInputAssociations',
@@ -198,8 +200,16 @@ ModdleCopy.prototype.copyProperty = function(property, parent, propertyName, clo
198200

199201
var propertyDescriptor = this._moddle.getPropertyDescriptor(parent, propertyName);
200202

201-
// do NOT copy references
203+
// do NOT copy references except given event definitions
202204
if (propertyDescriptor.isReference) {
205+
if (hasAnyEventDefinition(parent, [
206+
'bpmn:ErrorEventDefinition',
207+
'bpmn:EscalationEventDefinition',
208+
'bpmn:MessageEventDefinition',
209+
'bpmn:SignalEventDefinition'
210+
])) {
211+
return property;
212+
}
203213
return;
204214
}
205215

lib/util/DiUtil.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
} from './ModelUtil';
66

77
import {
8-
some
8+
some,
9+
isArray
910
} from 'min-dash';
1011

1112
/**
@@ -120,3 +121,19 @@ export function hasEscalationEventDefinition(element) {
120121
export function hasCompensateEventDefinition(element) {
121122
return hasEventDefinition(element, 'bpmn:CompensateEventDefinition');
122123
}
124+
125+
/**
126+
* @param {ModdleElement} moddleElement
127+
* @param {string[]} types
128+
*
129+
* @return {boolean}
130+
*/
131+
export function hasAnyEventDefinition(moddleElement, types) {
132+
if (!isArray(types)) {
133+
types = [ types ];
134+
}
135+
136+
return some(types, function(type) {
137+
return is(moddleElement, type);
138+
});
139+
}

test/spec/features/modeling/behavior/BoundaryEventBehaviorSpec.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('features/modeling/behavior - boundary event', function() {
6464
});
6565

6666

67-
describe.skip('should keep root element reference on replace', function() {
67+
describe('should keep root element reference on replace', function() {
6868

6969
describe('interrupting to non-interrupting', function() {
7070

@@ -85,7 +85,7 @@ describe('features/modeling/behavior - boundary event', function() {
8585
});
8686

8787
// then
88-
expect(getReferencedRootElement(nonInterruptingBoundaryEvent, 'messageRef')).to.equal(message);
88+
expectRefEquals(interruptingBoundaryEvent, nonInterruptingBoundaryEvent, 'messageRef');
8989
}));
9090

9191

@@ -106,7 +106,7 @@ describe('features/modeling/behavior - boundary event', function() {
106106
});
107107

108108
// then
109-
expect(getReferencedRootElement(nonInterruptingBoundaryEvent, 'escalationRef')).to.equal(escalation);
109+
expectRefEquals(interruptingBoundaryEvent, nonInterruptingBoundaryEvent, 'escalationRef');
110110
}));
111111

112112

@@ -127,7 +127,7 @@ describe('features/modeling/behavior - boundary event', function() {
127127
});
128128

129129
// then
130-
expect(getReferencedRootElement(nonInterruptingBoundaryEvent, 'errorRef')).to.equal(error);
130+
expectRefEquals(interruptingBoundaryEvent, nonInterruptingBoundaryEvent, 'errorRef');
131131
}));
132132

133133

@@ -148,7 +148,7 @@ describe('features/modeling/behavior - boundary event', function() {
148148
});
149149

150150
// then
151-
expect(getReferencedRootElement(nonInterruptingBoundaryEvent, 'signalRef')).to.equal(signal);
151+
expectRefEquals(interruptingBoundaryEvent, nonInterruptingBoundaryEvent, 'signalRef');
152152
}));
153153

154154
});
@@ -173,7 +173,7 @@ describe('features/modeling/behavior - boundary event', function() {
173173
});
174174

175175
// then
176-
expect(getReferencedRootElement(nonInterruptingBoundaryEvent, 'messageRef')).to.equal(message);
176+
expectRefEquals(interruptingBoundaryEvent, nonInterruptingBoundaryEvent, 'messageRef');
177177
}));
178178

179179
});
@@ -190,4 +190,13 @@ function getReferencedRootElement(element, propertyName) {
190190
eventDefinition = businessObject.eventDefinitions[ 0 ];
191191

192192
return eventDefinition.get(propertyName);
193+
}
194+
195+
function expectRefEquals(element, newElement, propertyName) {
196+
const previousRefElement = getReferencedRootElement(element, propertyName);
197+
const newRefElement = getReferencedRootElement(newElement, propertyName);
198+
199+
// expect name to be same
200+
expect(previousRefElement).to.equal(newRefElement);
201+
193202
}

0 commit comments

Comments
 (0)