From 6fbdee356799da1a0bbe61919df7e3dcec9d497f Mon Sep 17 00:00:00 2001 From: CTomlyn Date: Mon, 12 Feb 2024 14:17:26 -0800 Subject: [PATCH] #1691 Link temporarily visually connected to new target when cancelling updateLink via beforeEditActionHandler (#1692) --- .../src/common-canvas/canvas-controller.js | 15 +++++++++++---- .../svg-canvas-utils-drag-det-link.js | 9 ++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/canvas_modules/common-canvas/src/common-canvas/canvas-controller.js b/canvas_modules/common-canvas/src/common-canvas/canvas-controller.js index a4831a2a90..6f4a1b2fad 100644 --- a/canvas_modules/common-canvas/src/common-canvas/canvas-controller.js +++ b/canvas_modules/common-canvas/src/common-canvas/canvas-controller.js @@ -2168,6 +2168,11 @@ export default class CanvasController { } } + // Performs edit actions, based on the cmndData passed in, to the object + // model which result in changes to the displayed canvas. Returns true if + // the action completes successfully and false if it does not complete, + // for example, if the host application cancels the action by returning + // false from the beforeEditActionHanlder. editActionHandler(cmndData) { this.logger.log("editActionHandler - " + cmndData.editType); this.logger.log(cmndData); @@ -2203,17 +2208,17 @@ export default class CanvasController { data = this.handlers.beforeEditActionHandler(data, cmnd); // If the host app returns null, it doesn't want the action to proceed. if (!data) { - return; + return false; } // If an external pipeline flow was requested, we need to make sure it // was provided by the host app. We can't proceed if it was not. if (!this.wasExtPipelineFlowLoadSuccessful(data)) { - return; + return false; } } // Now preprocessing is complete, execuete the action itself. - this.editAction(data); + return this.editAction(data); } // Performs the edit action using the 'data' parameter, which contains the @@ -2232,7 +2237,7 @@ export default class CanvasController { // 'delete' is pressed on the keyboard. if (data.editType === "deleteSelectedObjects" && data.selectedObjectIds.length === 0) { - return; + return false; } // These commands are supported for the external AND internal object models. @@ -2561,6 +2566,8 @@ export default class CanvasController { // pipeline visible they will be loaded one by one when this check is // encountered. this.ensureVisibleExpandedPipelinesAreLoaded(); + + return true; } // Sets the appropriate values when handling an external pipleine flow diff --git a/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-drag-det-link.js b/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-drag-det-link.js index 7700e437ab..d5b72e7448 100644 --- a/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-drag-det-link.js +++ b/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-drag-det-link.js @@ -168,12 +168,19 @@ export default class SVGCanvasUtilsDragDetLink { // If editSubType is set the user did a gesture that requires a change // to the object model. if (editSubType) { - this.ren.canvasController.editActionHandler({ + const success = this.ren.canvasController.editActionHandler({ editType: "updateLink", editSubType: editSubType, editSource: "canvas", newLink: newLink, pipelineId: this.ren.activePipeline.id }); + + // The call to editActionHandler might "fail" if the host app + // uses beforeEditActionHandler to cancel the edit action. In + // this case, we snap the link back to its old position. + if (!success) { + this.snapBackOldLink(draggingLinkData.oldLink); + } // If editSubType is null, the user performed a gesture which should // not be executed as an action so draw the link back in its old position. } else {