feat(label-editing): create categoryValue if not exist

Relates to #955
This commit is contained in:
Niklas Kiefer 2019-05-22 08:46:11 +02:00 committed by merge-me[bot]
parent fb3398fa39
commit 93a4a579dd
2 changed files with 61 additions and 2 deletions

View File

@ -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;
}

View File

@ -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, {