From 34e3fa33fd60773e521d9b8ed304de72753b74c2 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Tue, 18 Jan 2022 16:23:54 +0100 Subject: [PATCH] fix(modeling): ensure di for embedded labels closes #1540 --- .../label-editing/cmd/UpdateLabelHandler.js | 31 ++++++++++++- test/spec/features/modeling/UpdateLabel.bpmn | 7 ++- .../spec/features/modeling/UpdateLabelSpec.js | 46 +++++++++++++------ 3 files changed, 67 insertions(+), 17 deletions(-) diff --git a/lib/features/label-editing/cmd/UpdateLabelHandler.js b/lib/features/label-editing/cmd/UpdateLabelHandler.js index 8dfbb851..35159c2a 100644 --- a/lib/features/label-editing/cmd/UpdateLabelHandler.js +++ b/lib/features/label-editing/cmd/UpdateLabelHandler.js @@ -11,6 +11,7 @@ import { } from '../../../util/LabelUtil'; import { + getDi, is } from '../../../util/ModelUtil'; @@ -23,7 +24,30 @@ var NULL_DIMENSIONS = { /** * A handler that updates the text of a BPMN element. */ -export default function UpdateLabelHandler(modeling, textRenderer) { +export default function UpdateLabelHandler(modeling, textRenderer, bpmnFactory) { + + /** + * Creates an empty `diLabel` attribute for embedded labels. + * + * @param {djs.model.Base} element + * @param {string} text + */ + function ensureInternalLabelDi(element, text) { + if (isLabelExternal(element)) { + return; + } + + var di = getDi(element); + + if (text && !di.label) { + di.label = bpmnFactory.create('bpmndi:BPMNLabel'); + } + + if (!text && di.label) { + di.label = null; + } + } + /** * Set the label and return the changed elements. @@ -42,6 +66,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) { setLabel(label, text, labelTarget !== label); + ensureInternalLabelDi(element, text); + return [ label, labelTarget ]; } @@ -127,7 +153,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) { UpdateLabelHandler.$inject = [ 'modeling', - 'textRenderer' + 'textRenderer', + 'bpmnFactory' ]; diff --git a/test/spec/features/modeling/UpdateLabel.bpmn b/test/spec/features/modeling/UpdateLabel.bpmn index fadc448a..b869e231 100644 --- a/test/spec/features/modeling/UpdateLabel.bpmn +++ b/test/spec/features/modeling/UpdateLabel.bpmn @@ -1,9 +1,10 @@ - + + @@ -29,6 +30,10 @@ + + + + diff --git a/test/spec/features/modeling/UpdateLabelSpec.js b/test/spec/features/modeling/UpdateLabelSpec.js index 201e8c19..7bbac540 100644 --- a/test/spec/features/modeling/UpdateLabelSpec.js +++ b/test/spec/features/modeling/UpdateLabelSpec.js @@ -131,20 +131,6 @@ describe('features/modeling - update label', function() { )); - it('should change name of task', inject(function(modeling, elementRegistry) { - - // given - var task_1 = elementRegistry.get('Task_1'); - - // when - modeling.updateLabel(task_1, 'foo'); - - // then - expect(task_1.businessObject.name).to.equal('foo'); - expect(task_1.label).to.be.undefined; - })); - - it('should change text annotation text and bounds', inject( function(modeling, elementRegistry) { @@ -234,4 +220,36 @@ describe('features/modeling - update label', function() { expect(element).to.have.bounds(newBounds); })); + + describe('embedded labels', function() { + + it('should change name of task', inject(function(modeling, elementRegistry) { + + // given + var task_1 = elementRegistry.get('Task_1'); + + // when + modeling.updateLabel(task_1, 'foo'); + + // then + expect(task_1.businessObject.name).to.equal('foo'); + expect(task_1.di.label).to.exist; + })); + + + it('should delete label of task', inject(function(modeling, elementRegistry) { + + // given + var task_2 = elementRegistry.get('Task_2'); + + // when + modeling.updateLabel(task_2, ''); + + // then + expect(task_2.businessObject.name).to.equal(''); + expect(task_2.di.label).not.to.exist; + })); + + }); + }); \ No newline at end of file