fix(modeling): ensure IDs are claimed when used

closes #1555
This commit is contained in:
Martin Stamm 2022-01-18 13:51:08 +01:00 committed by fake-join[bot]
parent 9366700235
commit 4e161427b8
4 changed files with 34 additions and 1 deletions

View File

@ -42,6 +42,10 @@ BpmnFactory.prototype._needsId = function(element) {
};
BpmnFactory.prototype._ensureId = function(element) {
if (element.id) {
this._model.ids.claim(element.id, element);
return;
}
// generate semantic ids for elements
// bpmn:SequenceFlow -> SequenceFlow_ID

View File

@ -47,7 +47,9 @@ export default function UnclaimIdBehavior(canvas, injector, moddle, modeling) {
var rootElement = canvas.getRootElement(),
rootElementBo = rootElement.businessObject;
if (is(rootElement, 'bpmn:Collaboration')) {
moddle.ids.unclaim(rootElementBo.id);
}
});
}

View File

@ -116,6 +116,16 @@ describe('features - bpmn-factory', function() {
})
);
});
it('should claim provided id', inject(function(bpmnFactory, moddle) {
var task = bpmnFactory.create('bpmn:Task', { id: 'foo' });
expect(task).to.exist;
expect(task.id).to.eql('foo');
expect(moddle.ids.assigned('foo')).to.exist;
}));
});

View File

@ -82,4 +82,21 @@ describe('features/modeling - unclaim id', function() {
expect(moddle.ids.assigned('Collaboration_1')).to.be.false;
}));
describe('morphing', function() {
var simpleXML = require('../../../../fixtures/bpmn/simple.bpmn');
beforeEach(bootstrapModeler(simpleXML, { modules: testModules }));
it('should keep ID of root', inject(function(moddle, modeling) {
// when
modeling.makeCollaboration();
// then
expect(moddle.ids.assigned('Process_1')).to.exist;
}));
});
});