Skip to content

Commit

Permalink
#1549 Provide field to differentiate different updateLink gestures (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlyn authored Aug 18, 2023
1 parent 6c39e85 commit 5503e1f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 14 deletions.
100 changes: 89 additions & 11 deletions canvas_modules/common-canvas/src/common-canvas/svg-canvas-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4639,14 +4639,26 @@ export default class SVGCanvasRenderer {
const newLink = this.getNewLinkOnDrag(d3Event);

if (newLink) {
this.canvasController.editActionHandler({
editType: "updateLink",
editSource: "canvas",
newLink: newLink,
pipelineId: this.pipelineId });
const editSubType = this.getLinkEditSubType(newLink);
// If editSubType is set the user did a gesture that requires a change
// to the object model.
if (editSubType) {
this.canvasController.editActionHandler({
editType: "updateLink",
editSubType: editSubType,
editSource: "canvas",
newLink: newLink,
pipelineId: this.pipelineId });
// 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 {
this.snapBackOldLink();
}
// newLink might be null when we are dragging a link handle with
// enableLinkSelection not set to detachable. If that's the case the
// link needs to snap back (redrawn) to its original position.
} else {
this.activePipeline.replaceLink(this.draggingLinkData.oldLink);
this.displayLinks();
this.snapBackOldLink();
}

// Switch 'new link over node' highlighting off
Expand All @@ -4658,13 +4670,78 @@ export default class SVGCanvasRenderer {
this.stopDraggingLink();
}

// Resets and redraws the link being dragged back to its original position.
// This is necessary when the user performs a link drag gesture which should
// NOT be executed as an action -- therefore the link need to be drawn back
// in its original position.
snapBackOldLink() {
this.activePipeline.replaceLink(this.draggingLinkData.oldLink);
this.displayLinks();
}

// Returns the edit sub-type for the link action being performed to further
// explain the updateLink action.
getLinkEditSubType(newLink) {
const oldLink = this.draggingLinkData.oldLink;

if (oldLink.srcNodeId && !newLink.srcNodeId) {
return "detachFromSrcNode";

} else if (oldLink.trgNodeId && !newLink.trgNodeId) {
return "detachFromTrgNode";

} else if (!oldLink.srcNodeId && newLink.srcNodeId) {
return "attachToSrcNode";

} else if (!oldLink.trgNodeId && newLink.trgNodeId) {
return "attachToTrgNode";

} else if (!oldLink.srcNodeId && !newLink.srcNodeId &&
(oldLink.srcPos.x_pos !== newLink.srcPos.x_pos ||
oldLink.srcPos.y_pos !== newLink.srcPos.y_pos)) {
return "moveSrcPosition";

} else if (!oldLink.trgNodeId && !newLink.trgNodeId &&
(oldLink.trgPos.x_pos !== newLink.trgPos.x_pos ||
oldLink.trgPos.y_pos !== newLink.trgPos.y_pos)) {
return "moveTrgPosition";

} else if (oldLink.srcNodeId && newLink.srcNodeId &&
oldLink.srcNodeId !== newLink.srcNodeId) {
return "switchSrcNode";

} else if (oldLink.trgNodeId && newLink.trgNodeId &&
oldLink.trgNodeId !== newLink.trgNodeId) {
return "switchTrgNode";

} else if (oldLink.srcNodeId && newLink.srcNodeId &&
oldLink.srcNodeId === newLink.srcNodeId &&
oldLink.srcNodePortId !== newLink.srcNodePortId) {
return "switchSrcNodePort";

} else if (oldLink.trgNodeId && newLink.trgNodeId &&
oldLink.trgNodeId === newLink.trgNodeId &&
oldLink.trgNodePortId !== newLink.trgNodePortId) {
return "switchTrgNodePort";
}
// We arrive here, in two ways:
// 1. if the user dragged a link handle from a node/port and dropped it
// back on the same node/port.
// 2. If the user clicked on the unattached end of a detached link but did
// not move it anywhere
// In these cases, the updateLink action should NOT be performed and
// consequently NO command should be added to the command stack.
return null;
}

// Returns a new link if one can be created given the current data in the
// this.draggingLinkData object. Returns null if a link cannot be created.
getNewLinkOnDrag(d3Event, nodeProximity) {
const oldLink = this.draggingLinkData.oldLink;
const newLink = cloneDeep(oldLink);

if (this.draggingLinkData.endBeingDragged === "start") {
delete newLink.srcObj;
delete newLink.srcNodeId;
delete newLink.srcNodePortId;
delete newLink.srcPos;
Expand All @@ -4675,6 +4752,7 @@ export default class SVGCanvasRenderer {

if (srcNode) {
newLink.srcNodeId = srcNode.id;
newLink.srcObj = this.activePipeline.getNode(srcNode.id);
newLink.srcNodePortId = nodeProximity
? this.getNodePortIdNearMousePos(d3Event, OUTPUT_TYPE, srcNode)
: this.getOutputNodePortId(d3Event, srcNode);
Expand All @@ -4683,6 +4761,7 @@ export default class SVGCanvasRenderer {
}

} else {
delete newLink.trgNode;
delete newLink.trgNodeId;
delete newLink.trgNodePortId;
delete newLink.trgPos;
Expand All @@ -4693,6 +4772,7 @@ export default class SVGCanvasRenderer {

if (trgNode) {
newLink.trgNodeId = trgNode.id;
newLink.trgNode = this.activePipeline.getNode(trgNode.id);
newLink.trgNodePortId = nodeProximity
? this.getNodePortIdNearMousePos(d3Event, INPUT_TYPE, trgNode)
: this.getInputNodePortId(d3Event, trgNode);
Expand Down Expand Up @@ -6549,15 +6629,14 @@ export default class SVGCanvasRenderer {
: null;
const coords = this.linkUtils.getLinkCoords(link, srcObj, srcPortId, trgNode, trgPortId, assocLinkVariation);

// Set additional calculated fields on link object.
link.coordsUpdated =
link.x1 !== coords.x1 ||
link.y1 !== coords.y1 ||
link.x2 !== coords.x2 ||
link.y2 !== coords.y2;

link.assocLinkVariation = assocLinkVariation;
link.srcPortId = srcPortId;
link.trgPortId = trgPortId;
link.x1 = coords.x1;
link.y1 = coords.y1;
link.x2 = coords.x2;
Expand Down Expand Up @@ -6625,14 +6704,13 @@ export default class SVGCanvasRenderer {
}
}

// Set additional calculated fields on link object.
link.coordsUpdated =
link.x1 !== coords.x1 ||
link.y1 !== coords.y1 ||
link.x2 !== coords.x2 ||
link.y2 !== coords.y2;

link.srcPortId = srcPortId;
link.trgPortId = trgPortId;
link.x1 = coords.x1;
link.y1 = coords.y1;
link.x2 = coords.x2;
Expand Down
4 changes: 2 additions & 2 deletions canvas_modules/harness/src/client/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1686,15 +1686,15 @@ class App extends React.Component {
sourceString = "detached source";
if (data.link.srcObj && data.link.srcObj.outputs) {
const srcPort = !data.link.srcObj.outputs ? null : data.link.srcObj.outputs.find(function(port) {
return port.id === data.link.srcPortId;
return port.id === data.link.srcNodePortId;
});
sourceString = `'${data.link.srcObj.label}'` + (srcPort && srcPort.label ? `, port '${srcPort.label}'` : "");
}

targetString = "detached target";
if (data.link.trgNode && data.link.trgNode.inputs) {
const trgPort = data.link.trgNode.inputs.find(function(port) {
return port.id === data.link.trgPortId;
return port.id === data.link.trgNodePortId;
});
targetString = `'${data.link.trgNode.label}'` + (trgPort && trgPort.label ? `, port '${trgPort.label}'` : "");
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ setup_git_branch
checkout_branch ${MAIN}

cd ./canvas_modules/common-canvas
npm version patch
npm version minor
NPM_VERSION=`node -p "require('./package.json').version"`
echo "Updated main build $NPM_VERSION"
commit_changes ${MAIN} "Update Elyra Canvas to version ${NPM_VERSION} [skip ci]"
Expand Down

0 comments on commit 5503e1f

Please sign in to comment.