Skip to content

Commit 883d3b2

Browse files
committed
fix(sidebar): enhance node selection to show details for single nodes
Signed-off-by: Maystern <12112910@mail.sustech.edu.cn>
1 parent 5e7d3eb commit 883d3b2

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

‎graph-ui/src/components/GraphTab.tsx‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,35 @@ export function GraphTab({ project }: GraphTabProps) {
262262
if (!filteredData || !path || nodeIds.size === 0) {
263263
setHighlightedIds(null);
264264
setSelectedPath(null);
265+
setSelectedNode(null);
265266
setCameraTarget(null);
266267
return;
267268
}
268269
setSelectedPath(path);
269-
setHighlightedIds(nodeIds);
270-
setCameraTarget(computeCameraTarget(filteredData.nodes, nodeIds));
270+
271+
/* Single node picked from the sidebar → also show the detail panel
272+
* on the right and highlight its direct connections, matching the
273+
* behaviour of clicking a node in the 3D scene. */
274+
if (nodeIds.size === 1) {
275+
const nodeId = [...nodeIds][0];
276+
const node = filteredData.nodes.find((n) => n.id === nodeId) ?? null;
277+
setSelectedNode(node);
278+
279+
const connectedIds = new Set<number>([nodeId]);
280+
for (const edge of filteredData.edges) {
281+
if (edge.source === nodeId) connectedIds.add(edge.target);
282+
if (edge.target === nodeId) connectedIds.add(edge.source);
283+
}
284+
setHighlightedIds(connectedIds);
285+
setCameraTarget(
286+
computeCameraTarget(filteredData.nodes, connectedIds),
287+
);
288+
} else {
289+
/* Directory with multiple nodes → don't show a detail panel. */
290+
setSelectedNode(null);
291+
setHighlightedIds(nodeIds);
292+
setCameraTarget(computeCameraTarget(filteredData.nodes, nodeIds));
293+
}
271294
},
272295
[filteredData],
273296
);

‎graph-ui/src/components/Sidebar.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useUiMessages } from "../lib/i18n";
55

66
interface SidebarProps {
77
nodes: GraphNode[];
8-
onSelectPath: (path: string, nodeIds: Set<number>) => void;
8+
onSelectPath: (path: string, nodeIds: Set<number>, node?: GraphNode) => void;
99
selectedPath: string | null;
1010
}
1111

@@ -61,7 +61,7 @@ function flattenSingleChild(dir: DirNode): DirNode {
6161

6262
function TreeItem({ dir, depth, onSelect, selectedPath }: {
6363
dir: DirNode; depth: number;
64-
onSelect: (path: string, ids: Set<number>) => void;
64+
onSelect: (path: string, ids: Set<number>, node?: GraphNode) => void;
6565
selectedPath: string | null;
6666
}) {
6767
const [expanded, setExpanded] = useState(false);
@@ -72,7 +72,7 @@ function TreeItem({ dir, depth, onSelect, selectedPath }: {
7272
return (
7373
<div>
7474
<button
75-
onClick={() => { setExpanded(!expanded); onSelect(dir.fullPath, dir.nodeIds); }}
75+
onClick={() => { setExpanded(!expanded); onSelect(dir.fullPath, dir.nodeIds, undefined); }}
7676
className={`flex items-center gap-1.5 w-full text-left px-3 py-[5px] text-[12px] transition-colors ${
7777
isSelected ? "bg-primary/10 text-primary" : "text-foreground/60 hover:text-foreground/80 hover:bg-white/[0.03]"
7878
}`}
@@ -90,7 +90,7 @@ function TreeItem({ dir, depth, onSelect, selectedPath }: {
9090
{sortedNodes.map((gn) => (
9191
<button
9292
key={gn.id}
93-
onClick={() => onSelect(dir.fullPath + "/" + gn.name, new Set([gn.id]))}
93+
onClick={() => onSelect(dir.fullPath + "/" + gn.name, new Set([gn.id]), gn)}
9494
className="flex items-center gap-1.5 w-full text-left px-3 py-[3px] text-[11px] text-foreground/40 hover:text-foreground/60 hover:bg-white/[0.02] transition-colors"
9595
style={{ paddingLeft: `${(depth+1) * 16 + 12}px` }}
9696
>
@@ -148,7 +148,7 @@ export function Sidebar({ nodes, onSelectPath, selectedPath }: SidebarProps) {
148148
filtered.map((n) => (
149149
<button
150150
key={n.id}
151-
onClick={() => onSelectPath(n.file_path ?? "", new Set([n.id]))}
151+
onClick={() => onSelectPath(n.file_path ?? "", new Set([n.id]), n)}
152152
className="flex items-center gap-2 w-full text-left px-4 py-1.5 text-[11px] hover:bg-white/[0.03] transition-colors"
153153
>
154154
<span className="w-[5px] h-[5px] rounded-full shrink-0" style={{ backgroundColor: n.color }} />

0 commit comments

Comments
 (0)