feat(planes): ensure plane link after ID change

closes #1575
This commit is contained in:
Martin Stamm 2022-01-21 15:24:49 +01:00 committed by Philipp Fromme
parent 824d8c209a
commit eefa78240b
2 changed files with 58 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import { isExpanded } from '../../../util/DiUtil';
import { getBusinessObject, is } from '../../../util/ModelUtil';
import { getMid } from 'diagram-js/lib/layout/LayoutUtil';
import { getBBox } from 'diagram-js/lib/util/Elements';
import { asPlaneId, planeId } from '../../../util/DrilldownUtil';
import { asPlaneId, isPlane, planeId } from '../../../util/DrilldownUtil';
var LOW_PRIORITY = 400;
@ -158,12 +158,12 @@ export default function SubProcessPlaneBehavior(
}, true);
// rename secondary elements (roots) when the primary element changes
// rename primary elements when the secondary element changes
// this ensures rootElement.id = element.id + '_plane'
this.executed('element.updateProperties', function(context) {
var shape = context.element;
if (!isCollapsedSubProcess(shape)) {
if (!is(shape, 'bpmn:SubProcess')) {
return;
}
@ -177,13 +177,20 @@ export default function SubProcessPlaneBehavior(
return;
}
if (isPlane(shape)) {
elementRegistry.updateId(shape, asPlaneId(newId));
elementRegistry.updateId(oldId, newId);
return;
}
var planeElement = elementRegistry.get(asPlaneId(oldId));
if (!planeElement) {
return;
}
elementRegistry.updateId(planeElement, asPlaneId(newId));
elementRegistry.updateId(asPlaneId(oldId), asPlaneId(newId));
}, true);

View File

@ -262,6 +262,53 @@ describe('features/modeling/behavior - subprocess planes', function() {
});
describe('update', function() {
var multipleDiagramXML = require('./SubProcessBehavior.multiple-planes.bpmn');
beforeEach(bootstrapModeler(multipleDiagramXML, {
modules: [
coreModule,
modelingModule,
replaceModule
]
}));
it('should update plane id when primary shape is changed',
inject(function(modeling, elementRegistry) {
// given
var subProcess = elementRegistry.get('SubProcess_2'),
plane = elementRegistry.get('SubProcess_2_plane');
// when
modeling.updateProperties(subProcess, { id: 'new_name' });
// then
expect(subProcess.id).to.equal('new_name');
expect(plane.id).to.equal('new_name_plane');
}));
it('should update primary shape id when plane is changed',
inject(function(modeling, elementRegistry) {
// given
var subProcess = elementRegistry.get('SubProcess_2'),
plane = elementRegistry.get('SubProcess_2_plane');
// when
modeling.updateProperties(plane, { id: 'new_name' });
// then
expect(subProcess.id).to.equal('new_name');
expect(plane.id).to.equal('new_name_plane');
}));
});
});