From 6ca685f0bf3a402a1246765eb4b4792714ce2037 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Tue, 9 Jan 2024 11:59:05 +0100 Subject: [PATCH] fix: support core replace in compensation behavior Closes #2073 --- .../CompensateBoundaryEventBehavior.js | 14 +++++++------ .../CompensateBoundaryEventBehaviorSpec.js | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/features/modeling/behavior/CompensateBoundaryEventBehavior.js b/lib/features/modeling/behavior/CompensateBoundaryEventBehavior.js index c3c5748aa7..4f56cd8343 100644 --- a/lib/features/modeling/behavior/CompensateBoundaryEventBehavior.js +++ b/lib/features/modeling/behavior/CompensateBoundaryEventBehavior.js @@ -92,13 +92,15 @@ export default function CompensateBoundaryEventBehavior(eventBus, modeling, bpmn * and remove the potential candidates for connection replacement to have a single compensation activity. */ function handleReplacement(context) { - const { targetElement } = context.hints || {}, - { oldShape } = context; + const { + newData, + oldShape + } = context; // from compensate boundary event if (isCompensationBoundaryEvent(context.oldShape) && - targetElement.eventDefinitionType !== 'bpmn:CompensateEventDefinition' || - targetElement.type !== 'bpmn:BoundaryEvent' + newData.eventDefinitionType !== 'bpmn:CompensateEventDefinition' || + newData.type !== 'bpmn:BoundaryEvent' ) { const targetConnection = oldShape.outgoing.find( ({ target }) => isForCompensation(target) @@ -112,8 +114,8 @@ export default function CompensateBoundaryEventBehavior(eventBus, modeling, bpmn // to compensate boundary event else if ( !isCompensationBoundaryEvent(context.oldShape) && - targetElement.eventDefinitionType === 'bpmn:CompensateEventDefinition' && - targetElement.type === 'bpmn:BoundaryEvent' + newData.eventDefinitionType === 'bpmn:CompensateEventDefinition' && + newData.type === 'bpmn:BoundaryEvent' ) { const targetConnection = oldShape.outgoing.find( ({ target }) => isForCompensationAllowed(target) diff --git a/test/spec/features/modeling/behavior/CompensateBoundaryEventBehaviorSpec.js b/test/spec/features/modeling/behavior/CompensateBoundaryEventBehaviorSpec.js index e431173a3a..198f516783 100644 --- a/test/spec/features/modeling/behavior/CompensateBoundaryEventBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/CompensateBoundaryEventBehaviorSpec.js @@ -389,6 +389,27 @@ describe('features/modeling/behavior - compensation boundary event', function() )); + it('should NOT crash when core `replace` component is used', inject( + function(elementRegistry, replace) { + + // given + const task = elementRegistry.get('Task_Compensation'); + + // when + const action = () => { + replace.replaceElement(task, + { + type: 'bpmn:ManualTask' + } + ); + }; + + // then + expect(action).not.to.throw(); + } + )); + + describe('copy and paste', function() { it('should NOT break on copy and paste', inject(function(canvas, copyPaste, elementRegistry) {