From 530b940a64ffaf2eb94f590f8e46a7e09dfda97b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 29 Mar 2016 19:41:43 -0700 Subject: [PATCH] [Timeline] Fix reordering Fix reordering behavior when dragging-and-dropping within timelines; addresses #789. --- .../swimlane/TimelineSwimlaneDropHandler.js | 22 ++++++++++--------- .../TimelineSwimlaneDropHandlerSpec.js | 11 ++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js b/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js index 4db30c4c23..619232539f 100644 --- a/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js +++ b/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js @@ -100,6 +100,13 @@ define( return swimlane.highlight() || expandedForDropInto(); } + function isReorder(targetObject, droppedObject) { + var droppedContext = droppedObject.getCapability('context'), + droppedParent = + droppedContext && droppedContext.getParent(), + droppedParentId = droppedParent && droppedParent.getId(); + return targetObject.getId() === droppedParentId; + } // Choose an appropriate composition action for the drag-and-drop function chooseAction(targetObject, droppedObject) { @@ -142,26 +149,21 @@ define( } function canDrop(targetObject, droppedObject) { - var droppedContext = droppedObject.getCapability('context'), - droppedParent = - droppedContext && droppedContext.getParent(), - droppedParentId = droppedParent && droppedParent.getId(); - return (targetObject.getId() === droppedParentId) || + return isReorder(targetObject, droppedObject) || !!chooseAction(targetObject, droppedObject); } function drop(domainObject, targetObject, indexOffset) { - var action = chooseAction(targetObject, domainObject); - function changeIndex() { var id = domainObject.getId(); return insert(id, targetObject, indexOffset); } - return action ? - action.perform().then(changeIndex) : - changeIndex(); + return isReorder(targetObject, domainObject) ? + changeIndex() : + chooseAction(targetObject, domainObject) + .perform().then(changeIndex); } return { diff --git a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js index 38df244c34..14bff75a16 100644 --- a/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js +++ b/platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js @@ -206,6 +206,7 @@ define( it("allows reordering within a parent", function () { var testModel = { composition: [ 'x', 'b', 'y', 'd' ] }; + mockSwimlane.highlightBottom.andReturn(true); mockSwimlane.expanded = true; mockSwimlane.children = []; @@ -225,6 +226,16 @@ define( }); }); + it("does not invoke an action when reordering", function () { + mockSwimlane.highlightBottom.andReturn(true); + mockSwimlane.expanded = true; + mockSwimlane.children = []; + mockContext.getParent + .andReturn(mockSwimlane.parent.domainObject); + handler.drop('d', mockOtherObject); + expect(mockAction.perform).not.toHaveBeenCalled(); + }); + }); } );