From 5d6e5986f1f49fd4ce182a6d0bf0dd28f7296cb1 Mon Sep 17 00:00:00 2001 From: Oguz Eroglu Date: Tue, 1 Oct 2019 11:42:01 +0200 Subject: [PATCH] feat(create): allow attachment of shapes with labels on creation Related to https://github.com/bpmn-io/bpmn-js/issues/1204 --- lib/features/create/Create.js | 11 ++++++- test/spec/features/create/CreateSpec.js | 39 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/features/create/Create.js b/lib/features/create/Create.js index a77345cba..cd59324d6 100644 --- a/lib/features/create/Create.js +++ b/lib/features/create/Create.js @@ -55,6 +55,11 @@ export default function Create( return !element.parent; }); + // ignore labels being created with their targets + elements = filter(elements, function(element) { + return !(isLabel(element) && elements.indexOf(element.labelTarget) > -1); + }); + var shape = find(elements, function(element) { return !isConnection(element); }); @@ -330,4 +335,8 @@ function isConnection(element) { function isSingleShape(elements) { return elements && elements.length === 1 && !isConnection(elements[0]); -} \ No newline at end of file +} + +function isLabel(element) { + return !!element.labelTarget; +} diff --git a/test/spec/features/create/CreateSpec.js b/test/spec/features/create/CreateSpec.js index 8f2bf6917..f1be6aeba 100644 --- a/test/spec/features/create/CreateSpec.js +++ b/test/spec/features/create/CreateSpec.js @@ -277,6 +277,45 @@ describe('features/create - Create', function() { })); + it('should attach with label', inject(function(create, dragging, elementRegistry, elementFactory) { + + // given + var hostShapeGfx = elementRegistry.getGraphics('hostShape'); + + var label = elementFactory.createLabel({ + labelTarget: newShape, + x: 0, + y: 0, + width: 50, + height: 50 + }); + + // when + create.start(canvasEvent({ x: 0, y: 0 }), [ newShape, label ]); + + dragging.hover({ element: hostShape, gfx: hostShapeGfx }); + + dragging.move(canvasEvent(getMid(hostShape))); + + dragging.end(); + + // then + var createdShape = elementRegistry.get('newShape'); + + expect(createdShape).to.exist; + expect(createdShape).to.equal(newShape); + + expect(createdShape.parent).to.equal(rootShape); + expect(createdShape.host).to.equal(hostShape); + + expect(hostShape.attachers).to.have.length; + expect(hostShape.attachers[0]).to.equal(createdShape); + + expect(createdShape.labels).to.have.length(1); + expect(createdShape.labels[0]).to.equal(label); + })); + + it('should append AND attach', inject(function(create, dragging, elementRegistry) { // given