Skip to content

Commit

Permalink
fix(copy-paste): do not create new id if unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Oct 15, 2021
1 parent b4bd655 commit 1253326
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/features/copy-paste/ModdleCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,13 @@ ModdleCopy.prototype.copyProperty = function(property, parent, propertyName) {

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

// do NOT copy Ids and references
if (propertyDescriptor.isId || propertyDescriptor.isReference) {
// do NOT copy references
if (propertyDescriptor.isReference) {
return;
}

// disallow copying IDs if already assigned
if (propertyDescriptor.isId && this._moddle.ids.assigned(property)) {
return;
}

Expand Down
30 changes: 24 additions & 6 deletions test/spec/features/copy-paste/ModdleCopySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
var task = moddle.create('bpmn:Task', {
id: 'foo'
});
var task = modeling.createShape({ type: 'bpmn:Task' },
{ x: 0, y: 0 }, canvas.getRootElement());
var taskId = task.id;

// when
var userTask = moddleCopy.copyElement(task, moddle.create('bpmn:UserTask'));
var userTask = moddleCopy.copyElement(task.businessObject, moddle.create('bpmn:UserTask'));

// then
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).not.to.equal('foo');
expect(userTask.id).to.equal(taskId);

expectNoAttrs(userTask);
}));
Expand Down

0 comments on commit 1253326

Please sign in to comment.