From 93a4a579dd5568370f37f0aac1a5da12927c40c5 Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Wed, 22 May 2019 08:46:11 +0200 Subject: [PATCH] feat(label-editing): create categoryValue if not exist Relates to #955 --- .../label-editing/LabelEditingProvider.js | 31 ++++++++++++++++-- .../label-editing/LabelEditingProviderSpec.js | 32 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/lib/features/label-editing/LabelEditingProvider.js b/lib/features/label-editing/LabelEditingProvider.js index 85024341..35263c62 100644 --- a/lib/features/label-editing/LabelEditingProvider.js +++ b/lib/features/label-editing/LabelEditingProvider.js @@ -6,7 +6,15 @@ import { getLabel } from './LabelUtil'; -import { is } from '../../util/ModelUtil'; +import { + getBusinessObject, + is +} from '../../util/ModelUtil'; + +import { + createCategoryValue +} from '../modeling/behavior/util/CategoryUtil'; + import { isAny } from '../modeling/util/ModelingUtil'; import { isExpanded } from '../../util/DiUtil'; @@ -19,9 +27,10 @@ import { export default function LabelEditingProvider( - eventBus, canvas, directEditing, + eventBus, bpmnFactory, canvas, directEditing, modeling, resizeHandles, textRenderer) { + this._bpmnFactory = bpmnFactory; this._canvas = canvas; this._modeling = modeling; this._textRenderer = textRenderer; @@ -102,6 +111,7 @@ export default function LabelEditingProvider( LabelEditingProvider.$inject = [ 'eventBus', + 'bpmnFactory', 'canvas', 'directEditing', 'modeling', @@ -370,6 +380,23 @@ LabelEditingProvider.prototype.update = function( }; } + if (is(element, 'bpmn:Group')) { + + var businessObject = getBusinessObject(element); + + // initialize categoryValue if not existing + if (!businessObject.categoryValueRef) { + + var rootElement = this._canvas.getRootElement(), + definitions = getBusinessObject(rootElement).$parent; + + var categoryValue = createCategoryValue(definitions, this._bpmnFactory); + + getBusinessObject(element).categoryValueRef = categoryValue; + } + + } + if (isEmptyText(newLabel)) { newLabel = null; } diff --git a/test/spec/features/label-editing/LabelEditingProviderSpec.js b/test/spec/features/label-editing/LabelEditingProviderSpec.js index e1d40c9b..9f3a003c 100644 --- a/test/spec/features/label-editing/LabelEditingProviderSpec.js +++ b/test/spec/features/label-editing/LabelEditingProviderSpec.js @@ -421,6 +421,38 @@ describe('features - label-editing', function() { }); + describe('group support', function() { + + beforeEach(bootstrapModeler(diagramXML, { + modules: [ + labelEditingModule, + coreModule, + modelingModule + ], + canvas: { deferUpdate: false } + })); + + it('should initialize categoryValue for empty group', inject( + function(elementRegistry, directEditing) { + + // given + var shape = elementRegistry.get('Group_2'); + + // when + directEditing.activate(shape); + directEditing._textbox.content.innerText = 'FOO'; + directEditing.complete(); + + // then + var label = getLabel(shape); + + expect(shape.businessObject.categoryValueRef).to.exist; + expect(label).to.equal('FOO'); + } + )); + + }); + describe('sizes', function() { beforeEach(bootstrapModeler(diagramXML, {