From d769e6ddb0cb2dc8befb2e7b31682925089ba8f1 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sun, 1 Dec 2019 00:18:19 +0100 Subject: [PATCH 1/2] fix(grid-snapping): do not update waypoints on multiple create Related to https://github.com/camunda/camunda-modeler/issues/1617 --- .../behavior/LayoutConnectionBehavior.js | 2 +- .../behavior/LayoutConnectionBehaviorSpec.js | 84 ++++++++++++++++--- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/lib/features/grid-snapping/behavior/LayoutConnectionBehavior.js b/lib/features/grid-snapping/behavior/LayoutConnectionBehavior.js index 9c584a7e..828ddb30 100644 --- a/lib/features/grid-snapping/behavior/LayoutConnectionBehavior.js +++ b/lib/features/grid-snapping/behavior/LayoutConnectionBehavior.js @@ -30,7 +30,7 @@ export default function LayoutConnectionBehavior(eventBus, gridSnapping, modelin hints = context.hints || {}, waypoints = connection.waypoints; - if (hints.connectionStart || hints.connectionEnd) { + if (hints.connectionStart || hints.connectionEnd || hints.createElementsBehavior === false) { return; } diff --git a/test/spec/features/grid-snapping/behavior/LayoutConnectionBehaviorSpec.js b/test/spec/features/grid-snapping/behavior/LayoutConnectionBehaviorSpec.js index b8d43892..d1105a14 100644 --- a/test/spec/features/grid-snapping/behavior/LayoutConnectionBehaviorSpec.js +++ b/test/spec/features/grid-snapping/behavior/LayoutConnectionBehaviorSpec.js @@ -7,24 +7,27 @@ import coreModule from 'lib/core'; import gridSnappingModule from 'lib/features/grid-snapping'; import modelingModule from 'lib/features/modeling'; import moveModule from 'diagram-js/lib/features/move'; +import copyPasteModule from 'lib/features/copy-paste'; + +/* global sinon */ describe('features/grid-snapping - layout connection', function() { - var diagramXML = require('./LayoutConnectionBehavior.bpmn'); - - beforeEach(bootstrapModeler(diagramXML, { - modules: [ - coreModule, - gridSnappingModule, - modelingModule, - moveModule - ] - })); - - describe('on connection create', function() { + var diagramXML = require('./LayoutConnectionBehavior.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { + modules: [ + coreModule, + gridSnappingModule, + modelingModule, + moveModule + ] + })); + + it('should snap 3 segment connection (1 middle segment)', inject( function(elementRegistry, modeling) { @@ -64,6 +67,17 @@ describe('features/grid-snapping - layout connection', function() { describe('on connection layout', function() { + var diagramXML = require('./LayoutConnectionBehavior.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { + modules: [ + coreModule, + gridSnappingModule, + modelingModule, + moveModule + ] + })); + var task1, task2, connection; beforeEach(inject(function(elementRegistry, modeling) { @@ -129,4 +143,50 @@ describe('features/grid-snapping - layout connection', function() { }); + + describe('on paste multiple', function() { + + var diagramXML = require('./LayoutConnectionBehavior.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { + modules: [ + coreModule, + gridSnappingModule, + modelingModule, + moveModule, + copyPasteModule + ] + })); + + + it('should not update waypoints', inject( + function(canvas, eventBus, copyPaste, elementRegistry) { + + // given + var layoutSpy = sinon.spy(); + + copyPaste.copy([ + elementRegistry.get('Task_2'), + elementRegistry.get('SequenceFlow_1'), + elementRegistry.get('Task_5') + ]); + + eventBus.on('commandStack.connection.updateWaypoints.execute', layoutSpy); + + // when + copyPaste.paste({ + element: canvas.getRootElement(), + point: { + x: 100, + y: 200 + } + }); + + // then + expect(layoutSpy).not.to.have.been.called; + } + )); + + }); + }); \ No newline at end of file From 4455c3fc35290e51220566fb6539a1efc4d3612f Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sun, 1 Dec 2019 00:03:47 +0100 Subject: [PATCH 2/2] fix(modeling/behavior): hook UpdateFlowNodeRefs behavior in on elements.create --- .../behavior/UpdateFlowNodeRefsBehavior.js | 3 +- .../modeling/lanes/UpdateFlowNodeRefsSpec.js | 43 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/features/modeling/behavior/UpdateFlowNodeRefsBehavior.js b/lib/features/modeling/behavior/UpdateFlowNodeRefsBehavior.js index 1f1bbcde..b5d30832 100644 --- a/lib/features/modeling/behavior/UpdateFlowNodeRefsBehavior.js +++ b/lib/features/modeling/behavior/UpdateFlowNodeRefsBehavior.js @@ -72,8 +72,9 @@ export default function UpdateFlowNodeRefsBehavior(eventBus, modeling, translate 'lane.add', 'lane.resize', 'lane.split', - 'elements.move', + 'elements.create', 'elements.delete', + 'elements.move', 'shape.create', 'shape.delete', 'shape.move', diff --git a/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js b/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js index 3b32b9f9..1b08e605 100644 --- a/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js +++ b/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js @@ -5,15 +5,22 @@ import { import modelingModule from 'lib/features/modeling'; import coreModule from 'lib/core'; +import copyPasteModule from 'lib/features/copy-paste'; + +/* global sinon */ describe('features/modeling - lanes - flowNodeRefs', function() { var diagramXML = require('./flowNodeRefs.bpmn'); - var testModules = [ coreModule, modelingModule ]; - - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + beforeEach(bootstrapModeler(diagramXML, { + modules: [ + coreModule, + modelingModule, + copyPasteModule + ] + })); describe('should unwire during move', function() { @@ -290,4 +297,34 @@ describe('features/modeling - lanes - flowNodeRefs', function() { expect(lane1.flowNodeRef).to.have.length(1); expect(lane2.flowNodeRef).to.have.length(2); })); + + + describe('should wire once during paste', function() { + + it('execute', inject(function(canvas, eventBus, elementRegistry, copyPaste) { + + // given + var participant = elementRegistry.get('Participant_A'); + + var updateRefsSpy = sinon.spy(); + + eventBus.on('commandStack.lane.updateRefs.execute', updateRefsSpy); + + // when + copyPaste.copy(participant); + + copyPaste.paste({ + element: canvas.getRootElement(), + point: { + x: 350, + y: 150 + } + }); + + // then + expect(updateRefsSpy).to.have.been.calledOnce; + })); + + }); + });