fix(copy-paste): do not create new id if unnecessary

Related to https://github.com/camunda/camunda-modeler/issues/1410
This commit is contained in:
Maciej Barelkowski 2021-10-15 10:54:03 +02:00 committed by Maciej Barelkowski
parent b4bd6557b1
commit 1253326768
2 changed files with 31 additions and 8 deletions

View File

@ -215,8 +215,13 @@ ModdleCopy.prototype.copyProperty = function(property, parent, propertyName) {
var propertyDescriptor = this._moddle.getPropertyDescriptor(parent, propertyName); var propertyDescriptor = this._moddle.getPropertyDescriptor(parent, propertyName);
// do NOT copy Ids and references // do NOT copy references
if (propertyDescriptor.isId || propertyDescriptor.isReference) { if (propertyDescriptor.isReference) {
return;
}
// disallow copying IDs if already assigned
if (propertyDescriptor.isId && this._moddle.ids.assigned(property)) {
return; return;
} }

View File

@ -98,18 +98,36 @@ describe('features/copy-paste/ModdleCopy', function() {
)); ));
it('should NOT copy IDs', inject(function(moddle, moddleCopy) { it('should NOT copy IDs if taken', inject(function(moddle, moddleCopy, canvas, modeling) {
// given // given
var task = moddle.create('bpmn:Task', { var task = modeling.createShape({ type: 'bpmn:Task' },
id: 'foo' { x: 0, y: 0 }, canvas.getRootElement());
}); var taskId = task.id;
// when // when
var userTask = moddleCopy.copyElement(task, moddle.create('bpmn:UserTask')); var userTask = moddleCopy.copyElement(task.businessObject, moddle.create('bpmn:UserTask'));
// then // then
expect(userTask.id).not.to.equal('foo'); expect(userTask.id).not.to.equal(taskId);
expectNoAttrs(userTask);
}));
it('should copy IDs if free', inject(function(moddle, moddleCopy, canvas, modeling) {
// given
var task = modeling.createShape({ type: 'bpmn:Task' },
{ x: 0, y: 0 }, canvas.getRootElement());
var taskId = task.id;
// when
modeling.removeShape(task);
var userTask = moddleCopy.copyElement(task.businessObject, moddle.create('bpmn:UserTask'));
// then
expect(userTask.id).to.equal(taskId);
expectNoAttrs(userTask); expectNoAttrs(userTask);
})); }));