fix(drilldown): prevent infinite loop on root property change

related to https://github.com/bpmn-io/bpmn-js-properties-panel/issues/569
This commit is contained in:
Martin Stamm 2022-02-09 08:22:33 +01:00 committed by GitHub
parent 069b1902c9
commit a696aa5953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 16 deletions

View File

@ -4,9 +4,7 @@ import { find } from 'min-dash';
import { escapeHTML } from 'diagram-js/lib/util/EscapeUtil';
import { getBusinessObject, is } from '../../util/ModelUtil';
import {
getPlaneIdFromShape,
getShapeIdFromPlane,
isPlane
getPlaneIdFromShape
} from '../../util/DrilldownUtil';
var OPEN_CLASS = 'bjs-breadcrumbs-shown';
@ -28,19 +26,6 @@ export default function DrilldownBreadcrumbs(eventBus, elementRegistry, overlays
var boParents = [];
// update primary shape if name or ID of the plane changes
eventBus.on('element.changed', function(e) {
var shape = e.element;
if (!isPlane(shape)) {
return;
}
var primary = elementRegistry.get(getShapeIdFromPlane(shape));
primary && eventBus.fire('element.changed', { element: primary });
});
// update breadcrumbs if name or ID of the primary shape changes
eventBus.on('element.changed', function(e) {
var shape = e.element,

View File

@ -239,6 +239,27 @@ export default function SubProcessPlaneBehavior(
elementRegistry.updateId(planeElement, toPlaneId(oldId));
}, true);
// re-throw element.changed to re-render primary shape if associated plane has
// changed (e.g. bpmn:name property has changed)
eventBus.on('element.changed', function(context) {
var element = context.element;
if (!isPlane(element)) {
return;
}
var plane = element;
var primaryShape = elementRegistry.get(getShapeIdFromPlane(plane));
// do not re-throw if no associated primary shape (e.g. bpmn:Process)
if (!primaryShape || primaryShape === plane) {
return;
}
eventBus.fire('element.changed', { element: primaryShape });
});
// create/remove plane for the subprocess
this.executed('shape.toggleCollapse', LOW_PRIORITY, function(context) {

View File

@ -151,6 +151,27 @@ describe('features - drilldown', function() {
})
);
it('should update on process name change',
inject(function(canvas, elementRegistry, modeling) {
// given
canvas.setRootElement(canvas.findRoot('collapsedProcess_2_plane'));
var shape = elementRegistry.get('rootProcess');
// when
modeling.updateProperties(shape, { name: 'new name' });
// then
expectBreadcrumbs([
'new name',
'Collapsed Process',
'Expanded Process',
'Collapsed Process 2'
]);
})
);
});
});

View File

@ -336,6 +336,27 @@ describe('features/modeling/behavior - subprocess planes', function() {
expect(plane.id).to.equal('new_name_plane');
}));
it('should rerender primary shape name when plane is changed',
inject(function(modeling, elementRegistry, eventBus) {
// given
var subProcess = elementRegistry.get('SubProcess_2'),
plane = elementRegistry.get('SubProcess_2_plane');
var changedSpy = sinon.spy();
eventBus.on('element.changed', 5000, changedSpy);
// when
modeling.updateProperties(plane, { name: 'new name' });
// then
expect(changedSpy).to.have.been.calledTwice;
expect(changedSpy.secondCall.args[0].element).to.eql(subProcess);
})
);
});