Skip to content

Commit 99c3437

Browse files
authored
Fix Node Highlight on Task Hover (#1401)
## Description <!-- Please provide a brief description of the changes made in this pull request. Include any relevant context or reasoning for the changes. --> Fixes a bug where dragging from the component library over a node on the canvas to replace it would not highlight the replace-target node. ## Related Issue and Pull requests <!-- Link to any related issues using the format #<issue-number> --> Closes Shopify/oasis-frontend#326 ## Type of Change <!-- Please delete options that are not relevant --> - [x] Bug fix ## Checklist <!-- Please ensure the following are completed before submitting the PR --> - [ ] I have tested this does not break current pipelines / runs functionality - [ ] I have tested the changes on staging ## Screenshots (if applicable) <!-- Include any screenshots that might help explain the changes or provide visual context --> ## Test Instructions <!-- Detail steps and prerequisites for testing the changes in this PR --> 1. Drag a task from the library and hover over a node on the canvas, it should highlight orange. 2. It should un-highlight when you move off it 3. Replace flow should trigger if you release while it is highlighted ## Additional Comments Future: disable highlighting when an IO node is dragged over a task <!-- Add any additional context or information that reviewers might need to know regarding this PR -->
1 parent 2927f0a commit 99c3437

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/components/shared/ReactFlow/FlowCanvas/FlowCanvas.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,19 @@ const FlowCanvas = ({
575575
isPositionInNode(node, cursorPosition),
576576
);
577577

578-
if (hoveredNode?.id === replaceTarget?.id) return;
579-
if (hoveredNode?.type && !REPLACEABLE_NODES.has(hoveredNode.type)) {
578+
if (!hoveredNode && replaceTarget) {
580579
setReplaceTarget(null);
581580
return;
582581
}
583582

584-
setReplaceTarget(hoveredNode || null);
583+
if (!hoveredNode || hoveredNode.id === replaceTarget?.id) return;
584+
585+
if (hoveredNode.type && !REPLACEABLE_NODES.has(hoveredNode.type)) {
586+
setReplaceTarget(null);
587+
return;
588+
}
589+
590+
setReplaceTarget(hoveredNode);
585591
}
586592
},
587593
[reactFlowInstance, nodes, replaceTarget, setReplaceTarget],
@@ -912,7 +918,12 @@ const FlowCanvas = ({
912918
preserveIOSelectionOnSpecChange(componentSpec);
913919
updateReactFlow(componentSpec);
914920
initialCanvasLoaded.current = true;
915-
}, [componentSpec, currentSubgraphPath, preserveIOSelectionOnSpecChange]);
921+
}, [
922+
replaceTarget,
923+
componentSpec,
924+
currentSubgraphPath,
925+
preserveIOSelectionOnSpecChange,
926+
]);
916927

917928
useEffect(() => {
918929
reactFlowInstance?.fitView({

0 commit comments

Comments
 (0)