From 0e1aa0843e1d8beb84255d6c9eb10edb95f074d3 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Fri, 7 Jun 2024 11:03:44 +0200 Subject: [PATCH] fix(attach-create-pad): do not show for compensation activities Related to https://github.com/camunda/camunda-modeler/issues/4348 --- lib/bpmn/attachCreatePad/AttachCreatePad.js | 18 ++++++++++++++-- .../bpmn/attachCreatePad/AttachCreatePad.bpmn | 21 ++++++++++++++----- .../attachCreatePad/AttachCreatePad.spec.js | 13 ++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/bpmn/attachCreatePad/AttachCreatePad.js b/lib/bpmn/attachCreatePad/AttachCreatePad.js index 1d6fffb..0b9520a 100644 --- a/lib/bpmn/attachCreatePad/AttachCreatePad.js +++ b/lib/bpmn/attachCreatePad/AttachCreatePad.js @@ -1,7 +1,11 @@ import { getBBox } from 'diagram-js/lib/util/Elements'; import { isEventSubProcess } from 'bpmn-js/lib/util/DiUtil'; -import { is } from 'bpmn-js/lib/util/ModelUtil'; + +import { + getBusinessObject, + is +} from 'bpmn-js/lib/util/ModelUtil'; import CreatePad from '../../common/createPad/CreatePad'; @@ -29,6 +33,10 @@ export default class AttachCreatePad extends CreatePad { return false; } + if (isCompensationActivity(target)) { + return false; + } + return is(target, 'bpmn:Task') || (is(target, 'bpmn:SubProcess') && !isEventSubProcess(target)); } @@ -143,4 +151,10 @@ AttachCreatePad.$inject = [ 'modeling', 'selection', 'translate' -]; \ No newline at end of file +]; + +function isCompensationActivity(element) { + const businessObject = getBusinessObject(element); + + return businessObject.get('isForCompensation'); +} \ No newline at end of file diff --git a/test/spec/bpmn/attachCreatePad/AttachCreatePad.bpmn b/test/spec/bpmn/attachCreatePad/AttachCreatePad.bpmn index d910c85..daeee28 100644 --- a/test/spec/bpmn/attachCreatePad/AttachCreatePad.bpmn +++ b/test/spec/bpmn/attachCreatePad/AttachCreatePad.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1 @@ -23,8 +23,12 @@ SequenceFlow_4 - + + + + + @@ -37,16 +41,23 @@ - - + + + + + - + + + + + diff --git a/test/spec/bpmn/attachCreatePad/AttachCreatePad.spec.js b/test/spec/bpmn/attachCreatePad/AttachCreatePad.spec.js index c99a3da..b4527ec 100644 --- a/test/spec/bpmn/attachCreatePad/AttachCreatePad.spec.js +++ b/test/spec/bpmn/attachCreatePad/AttachCreatePad.spec.js @@ -50,6 +50,19 @@ describe('', function() { })); + it('should return false if attach not allowed (compensation activity)', inject(function(attachCreatePad, elementRegistry) { + + // given + const compensationTask = elementRegistry.get('CompensationTask_1'); + + // when + const canOpen = attachCreatePad.canOpen(compensationTask); + + // then + expect(canOpen).to.be.false; + })); + + it('should return false if attach not allowed (event subprocess)', inject(function(attachCreatePad, elementRegistry) { // given