diff --git a/src/cloud-element-templates/CalledElementBehavior.js b/src/cloud-element-templates/CalledElementBehavior.js new file mode 100644 index 00000000..9995edce --- /dev/null +++ b/src/cloud-element-templates/CalledElementBehavior.js @@ -0,0 +1,46 @@ +import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; +import { is } from 'bpmn-js/lib/util/ModelUtil'; + +import { findExtension } from './Helper'; + +/** + * Enforces no variable propagation for templated call activities. + */ +export class CalledElementBehavior extends CommandInterceptor { + constructor(eventBus, modeling) { + super(eventBus, modeling); + + this._modeling = modeling; + + this.postExecuted( + 'propertiesPanel.zeebe.changeTemplate', this._handleTemplateChange, true, this); + } + + _handleTemplateChange(context) { + if (!context.newTemplate) { + return; + } + + const { element } = context; + + if (!is(element, 'bpmn:CallActivity')) { + return; + } + + const calledElement = findExtension(element, 'zeebe:CalledElement'); + + if (!calledElement) { + return; + } + + this._modeling.updateModdleProperties(element, calledElement, { + propagateAllChildVariables: false, + propagateAllParentVariables: false + }); + } +} + +CalledElementBehavior.$inject = [ + 'eventBus', + 'modeling' +]; diff --git a/src/cloud-element-templates/create/CalledElementBindingProvider.js b/src/cloud-element-templates/create/CalledElementBindingProvider.js index 101d995c..f02476f4 100644 --- a/src/cloud-element-templates/create/CalledElementBindingProvider.js +++ b/src/cloud-element-templates/create/CalledElementBindingProvider.js @@ -3,8 +3,6 @@ import { } from '../CreateHelper'; import { getDefaultValue } from '../Helper'; -import { ensureNoPropagation } from '../util/calledElement'; - export class CalledElementBindingProvider { static create(element, options) { @@ -30,4 +28,9 @@ export class CalledElementBindingProvider { calledElement.set(propertyName, value); } -} \ No newline at end of file +} + +function ensureNoPropagation(calledElement) { + calledElement.set('propagateAllChildVariables', false); + calledElement.set('propagateAllParentVariables', false); +} diff --git a/src/cloud-element-templates/index.js b/src/cloud-element-templates/index.js index 9dd32295..14fcc678 100644 --- a/src/cloud-element-templates/index.js +++ b/src/cloud-element-templates/index.js @@ -10,6 +10,7 @@ import ElementTemplatesPropertiesProvider from './ElementTemplatesPropertiesProv import UpdateTemplatePropertiesOrder from './UpdateTemplatePropertiesOrder'; import { ReferencedElementBehavior } from './ReferencedElementBehavior'; import { GeneratedValueBehavior } from './GeneratedValueBehavior'; +import { CalledElementBehavior } from './CalledElementBehavior'; export default { @@ -25,7 +26,8 @@ export default { 'elementTemplatesConditionChecker', 'generatedValueBehavior', 'referencedElementBehavior', - 'updateTemplatePropertiesOrder' + 'updateTemplatePropertiesOrder', + 'calledElementBehavior' ], elementTemplates: [ 'type', ElementTemplates ], elementTemplatesLoader: [ 'type', ElementTemplatesLoader ], @@ -34,5 +36,6 @@ export default { elementTemplatesConditionChecker: [ 'type', ElementTemplatesConditionChecker ], generatedValueBehavior: [ 'type', GeneratedValueBehavior ], referencedElementBehavior: [ 'type', ReferencedElementBehavior ], - updateTemplatePropertiesOrder: [ 'type', UpdateTemplatePropertiesOrder ] + updateTemplatePropertiesOrder: [ 'type', UpdateTemplatePropertiesOrder ], + calledElementBehavior: [ 'type', CalledElementBehavior ] }; diff --git a/src/cloud-element-templates/util/calledElement.js b/src/cloud-element-templates/util/calledElement.js deleted file mode 100644 index e39683dc..00000000 --- a/src/cloud-element-templates/util/calledElement.js +++ /dev/null @@ -1,4 +0,0 @@ -export function ensureNoPropagation(calledElement) { - calledElement.set('propagateAllChildVariables', false); - calledElement.set('propagateAllParentVariables', false); -} diff --git a/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js b/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js index e8397a68..c8d21a99 100644 --- a/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js +++ b/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js @@ -1722,12 +1722,9 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( const calledElement = findExtension(task, 'zeebe:CalledElement'); expect(calledElement).to.exist; - expect(calledElement).to.jsonEqual({ - $type: 'zeebe:CalledElement', - processId: 'paymentProcess', - propagateChildVariables: false, - propagateParentVariables: false - }); + expect(calledElement).to.have.property('processId', 'paymentProcess'); + expect(calledElement).to.have.property('propagateAllChildVariables', false); + expect(calledElement).to.have.property('propagateAllParentVariables', false); })); @@ -1769,12 +1766,9 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( const calledElement = findExtension(task, 'zeebe:CalledElement'); expect(calledElement).to.exist; - expect(calledElement).to.jsonEqual({ - $type: 'zeebe:CalledElement', - processId: 'paymentProcess', - propagateChildVariables: false, - propagateParentVariables: false - }); + expect(calledElement).to.have.property('processId', 'paymentProcess'); + expect(calledElement).to.have.property('propagateAllChildVariables', false); + expect(calledElement).to.have.property('propagateAllParentVariables', false); })); });