From ac526ec5873c8128d30ac70a8401f74487f5d068 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 9 Oct 2023 15:57:59 +0200 Subject: [PATCH] fix: set `$parent` when creating message --- .../cmd/ChangeElementTemplateHandler.js | 11 +++++++++-- .../cmd/ChangeElementTemplateHandler.spec.js | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js b/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js index 851a0d63..2fb5aeb1 100644 --- a/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js +++ b/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js @@ -31,7 +31,11 @@ import { MESSAGE_PROPERTY_TYPE, MESSAGE_ZEEBE_SUBSCRIPTION_PROPERTY_TYPE } from '../util/bindingTypes'; -import { createElement } from '../../utils/ElementUtil'; + +import { + createElement, + getRoot +} from '../../utils/ElementUtil'; /** * Applies an element template to an element. Sets `zeebe:modelerTemplate` and @@ -654,6 +658,7 @@ export default class ChangeElementTemplateHandler { } const message = this._getOrCreateMessage(element, newTemplate); + newProperties.forEach((newProperty) => { const oldProperty = findOldProperty(oldTemplate, newProperty), newBinding = newProperty.binding, @@ -762,6 +767,8 @@ export default class ChangeElementTemplateHandler { if (!message) { message = this._bpmnFactory.create('bpmn:Message', { 'zeebe:modelerTemplate': template.id }); + message.$parent = getRoot(bo); + this._modeling.updateModdleProperties(element, bo, { messageRef: message }); } @@ -1091,4 +1098,4 @@ function remove(array, item) { array.splice(index, 1); return array; -} +} \ No newline at end of file diff --git a/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js b/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js index 30c50823..70bc8eca 100644 --- a/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js +++ b/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js @@ -1499,7 +1499,7 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( const newTemplate = require('./event-template-1.json'); - it('execute', inject(function(elementRegistry) { + it('execute', inject(function(bpmnjs, elementRegistry) { // given let event = elementRegistry.get('Event_1'); @@ -1515,6 +1515,8 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( expect(message).to.exist; expect(message.get('name')).to.equal('name'); + + expect(message.$parent).to.equal(bpmnjs.getDefinitions()); })); @@ -1537,7 +1539,7 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( })); - it('redo', inject(function(commandStack, elementRegistry) { + it('redo', inject(function(bpmnjs, commandStack, elementRegistry) { // given let event = elementRegistry.get('Event_1'); @@ -1555,7 +1557,10 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( expect(message).to.exist; expect(message.get('name')).to.equal('name'); + + expect(message.$parent).to.equal(bpmnjs.getDefinitions()); })); + });