From bac7d5e1cdf68996a188af4fe836d4b517fade98 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Mon, 14 Feb 2022 14:20:29 +0100 Subject: [PATCH] fix(modeling): ensure plane ID change is undoable related to https://github.com/camunda/camunda-modeler/issues/2750 --- .../behavior/SubProcessPlaneBehavior.js | 9 +- .../behavior/SubProcessPlaneBehaviorSpec.js | 126 +++++++++++++++--- 2 files changed, 112 insertions(+), 23 deletions(-) diff --git a/lib/features/modeling/behavior/SubProcessPlaneBehavior.js b/lib/features/modeling/behavior/SubProcessPlaneBehavior.js index c1448a91..f519d5ea 100644 --- a/lib/features/modeling/behavior/SubProcessPlaneBehavior.js +++ b/lib/features/modeling/behavior/SubProcessPlaneBehavior.js @@ -216,7 +216,7 @@ export default function SubProcessPlaneBehavior( this.reverted('element.updateProperties', function(context) { var shape = context.element; - if (!isCollapsedSubProcess(shape)) { + if (!is(shape, 'bpmn:SubProcess')) { return; } @@ -230,6 +230,13 @@ export default function SubProcessPlaneBehavior( return; } + if (isPlane(shape)) { + elementRegistry.updateId(shape, toPlaneId(oldId)); + elementRegistry.updateId(newId, oldId); + + return; + } + var planeElement = elementRegistry.get(toPlaneId(newId)); if (!planeElement) { diff --git a/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js b/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js index 9712741e..2e9f7640 100644 --- a/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js @@ -305,36 +305,118 @@ describe('features/modeling/behavior - subprocess planes', function() { })); - it('should update plane id when primary shape is changed', - inject(function(modeling, elementRegistry) { + describe('do', function() { - // given - var subProcess = elementRegistry.get('SubProcess_2'), - plane = elementRegistry.get('SubProcess_2_plane'); + it('should update plane id when primary shape is changed', + inject(function(modeling, elementRegistry) { - // when - modeling.updateProperties(subProcess, { id: 'new_name' }); + // given + var subProcess = elementRegistry.get('SubProcess_2'), + plane = elementRegistry.get('SubProcess_2_plane'); - // then - expect(subProcess.id).to.equal('new_name'); - expect(plane.id).to.equal('new_name_plane'); - })); + // when + modeling.updateProperties(subProcess, { id: 'new_name' }); + + // then + expect(subProcess.id).to.equal('new_name'); + expect(plane.id).to.equal('new_name_plane'); + })); - it('should update primary shape id when plane is changed', - inject(function(modeling, elementRegistry) { + it('should update primary shape id when plane is changed', + inject(function(modeling, elementRegistry) { - // given - var subProcess = elementRegistry.get('SubProcess_2'), - plane = elementRegistry.get('SubProcess_2_plane'); + // given + var subProcess = elementRegistry.get('SubProcess_2'), + plane = elementRegistry.get('SubProcess_2_plane'); - // when - modeling.updateProperties(plane, { id: 'new_name' }); + // when + modeling.updateProperties(plane, { id: 'new_name' }); - // then - expect(subProcess.id).to.equal('new_name'); - expect(plane.id).to.equal('new_name_plane'); - })); + // then + expect(subProcess.id).to.equal('new_name'); + expect(plane.id).to.equal('new_name_plane'); + })); + + }); + + + describe('undo', function() { + + it('should update plane id when primary shape is changed', + inject(function(modeling, elementRegistry, commandStack) { + + // given + var subProcess = elementRegistry.get('SubProcess_2'), + plane = elementRegistry.get('SubProcess_2_plane'); + + // when + modeling.updateProperties(subProcess, { id: 'new_name' }); + commandStack.undo(); + + // then + expect(subProcess.id).to.equal('SubProcess_2'); + expect(plane.id).to.equal('SubProcess_2_plane'); + })); + + + it('should update primary shape id when plane is changed', + inject(function(modeling, elementRegistry, commandStack) { + + // given + var subProcess = elementRegistry.get('SubProcess_2'), + plane = elementRegistry.get('SubProcess_2_plane'); + + // when + modeling.updateProperties(plane, { id: 'new_name' }); + commandStack.undo(); + + // then + expect(subProcess.id).to.equal('SubProcess_2'); + expect(plane.id).to.equal('SubProcess_2_plane'); + })); + + }); + + + describe('redo', function() { + + it('should update plane id when primary shape is changed', + inject(function(modeling, elementRegistry, commandStack) { + + // given + var subProcess = elementRegistry.get('SubProcess_2'), + plane = elementRegistry.get('SubProcess_2_plane'); + + // when + modeling.updateProperties(subProcess, { id: 'new_name' }); + commandStack.undo(); + commandStack.redo(); + + // then + expect(subProcess.id).to.equal('new_name'); + expect(plane.id).to.equal('new_name_plane'); + })); + + + it('should update primary shape id when plane is changed', + inject(function(modeling, elementRegistry, commandStack) { + + // given + var subProcess = elementRegistry.get('SubProcess_2'), + plane = elementRegistry.get('SubProcess_2_plane'); + + // when + modeling.updateProperties(plane, { id: 'new_name' }); + commandStack.undo(); + commandStack.redo(); + + // then + expect(subProcess.id).to.equal('new_name'); + expect(plane.id).to.equal('new_name_plane'); + })); + + }); it('should rerender primary shape name when plane is changed',