fix(dashboard): restrict Path Finder "To" dropdown to reachable nodes#197
fix(dashboard): restrict Path Finder "To" dropdown to reachable nodes#197ShresthSamyak wants to merge 1 commit into
Conversation
The Dependency Path Finder modal listed every node in both the "From" and "To" selects, so users could pick a destination that was not reachable from the source and only learn "no path found" after clicking Find Path. Compute the reachable set from the chosen "From" node via the same undirected adjacency used by findPath (memoized on the graph), and filter the "To" dropdown to that set. Disable "To" until a source is picked, surface the reachable count, and clear a stale "To" selection when the source changes. Closes Lum1104#188
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates PathFinderModal to prevent users from selecting an unreachable destination node by precomputing reachability from the selected source and filtering the “To” dropdown accordingly.
Changes:
- Memoized an undirected adjacency map derived from the graph edges.
- Added a memoized BFS reachability set from the selected “From” node and filtered “To” candidates.
- Disabled/annotated the “To” selector when no source is chosen or when no destinations are reachable, and auto-cleared stale “To” selections.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const reachableFromSource = useMemo(() => { | ||
| if (!fromNodeId) return null; | ||
| const reachable = new Set<string>(); | ||
| const queue: string[] = [fromNodeId]; | ||
| reachable.add(fromNodeId); | ||
| while (queue.length > 0) { | ||
| const nodeId = queue.shift()!; | ||
| const neighbors = adjacency.get(nodeId) ?? []; | ||
| for (const n of neighbors) { | ||
| if (!reachable.has(n)) { | ||
| reachable.add(n); | ||
| queue.push(n); | ||
| } | ||
| } | ||
| } | ||
| reachable.delete(fromNodeId); | ||
| return reachable; | ||
| }, [fromNodeId, adjacency]); |
| useEffect(() => { | ||
| if (toNodeId && reachableFromSource && !reachableFromSource.has(toNodeId)) { | ||
| setToNodeId(""); | ||
| setPath(null); | ||
| } | ||
| }, [reachableFromSource, toNodeId]); |
| reachable.add(fromNodeId); | ||
| while (queue.length > 0) { | ||
| const nodeId = queue.shift()!; |
|
@codex review this |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
findPathagree and the work isn't redone on every render.Before
Both selects listed every node. Pairs with no connecting path only failed after clicking Find Path, requiring the user to manually scan edges to find working destinations.
After
Once From is picked, To only shows nodes actually reachable from it —
N reachableis shown next to the label. Selecting To before From is disabled with a placeholder hinting at the order. If the source has no neighbors, To showsNo reachable nodes from sourceinstead of empty options.Notes
findPath(treats graph edges as undirected) so the filter and the BFS result can never disagree.Test plan
pnpm installpnpm --filter @understand-anything/dashboard exec tsc --noEmit— cleanpnpm --filter @understand-anything/dashboard build— succeedspnpm --filter @understand-anything/dashboard test— 42 passedpnpm lint— clean