Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(ui): project switcher — searchable, properly elevated

Martin Vogel8b467e7e57a3
diff --git a/graph-ui/src/components/ProjectSwitcher.tsx b/graph-ui/src/components/ProjectSwitcher.tsx
index b61773faf..f62b08ab1 100644
--- a/graph-ui/src/components/ProjectSwitcher.tsx
+++ b/graph-ui/src/components/ProjectSwitcher.tsx
@@ -1,4 +1,5 @@
-import { useCallback, useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { createPortal } from "react-dom";
import { callTool } from "../api/rpc";
import type { Project } from "../lib/types";
@@ -18,7 +19,9 @@ export function ProjectSwitcher({
}) {
const [open, setOpen] = useState(false);
const [projects, setProjects] = useState<Project[] | null>(null);
+ const [query, setQuery] = useState("");
const rootRef = useRef<HTMLDivElement | null>(null);
+ const inputRef = useRef<HTMLInputElement | null>(null);
const load = useCallback(() => {
if (projects !== null) return;
@@ -29,6 +32,9 @@ export function ProjectSwitcher({
useEffect(() => {
if (!open) return;
+ setQuery("");
+ /* Focus lands in the filter so typing narrows immediately. */
+ const focusTimer = setTimeout(() => inputRef.current?.focus(), 0);
const onDocClick = (event: MouseEvent) => {
if (rootRef.current && !rootRef.current.contains(event.target as Node))
setOpen(false);
@@ -39,11 +45,19 @@ export function ProjectSwitcher({
document.addEventListener("mousedown", onDocClick);
document.addEventListener("keydown", onKey);
return () => {
+ clearTimeout(focusTimer);
document.removeEventListener("mousedown", onDocClick);
document.removeEventListener("keydown", onKey);
};
}, [open]);
+ const filtered = useMemo(() => {
+ if (projects === null) return null;
+ const needle = query.trim().toLowerCase();
+ if (!needle) return projects;
+ return projects.filter((project) => project.name.toLowerCase().includes(needle));
+ }, [projects, query]);
+
return (
<div ref={rootRef} className="relative shrink-0">
<button
@@ -62,44 +76,75 @@ export function ProjectSwitcher({
<span className="text-foreground/40 text-[11px] shrink-0">▾</span>
</button>
{open && (
- <div className="absolute top-full left-0 mt-1 w-[320px] bg-popover border border-border/60 rounded-md shadow-xl z-30 py-1 max-h-[60vh] overflow-y-auto">
- {projects === null && (
- <p className="px-3 py-2 text-[13px] text-foreground/40">Loading…</p>
- )}
- {projects !== null && projects.length === 0 && (
- <p className="px-3 py-2 text-[13px] text-foreground/40">
- No indexed projects yet.
- </p>
+ <>
+ {/* Backdrop: dims the page so the panel reads as a layer, and
+ * makes click-away obvious. Portaled to <body> — the header's
+ * backdrop-filter makes it the containing block for fixed
+ * children, which would clamp the overlay to the header bar. */}
+ {createPortal(
+ <div
+ className="fixed inset-0 bg-black/50 z-20"
+ onMouseDown={() => setOpen(false)}
+ />,
+ document.body,
)}
- {(projects ?? []).map((project) => (
- <button
- key={project.name}
- onClick={() => {
- setOpen(false);
- onSelect(project.name);
- }}
- className={`flex items-center gap-2 w-full text-left px-3 py-1.5 transition-colors hover:bg-surface-3 ${
- project.name === selected ? "text-primary" : "text-foreground/70"
- }`}
- >
- <span className="text-[13px] font-mono truncate">{project.name}</span>
- {project.name === selected && (
- <span className="ml-auto text-[11px] shrink-0">●</span>
+ <div className="absolute top-full left-0 mt-1.5 w-[340px] bg-surface-3 border border-border rounded-md shadow-2xl shadow-black/60 z-30 overflow-hidden">
+ <div className="p-2 border-b border-border/60">
+ <input
+ ref={inputRef}
+ type="text"
+ value={query}
+ onChange={(event) => setQuery(event.target.value)}
+ onKeyDown={(event) => {
+ if (event.key === "Enter" && filtered && filtered.length > 0) {
+ setOpen(false);
+ onSelect(filtered[0].name);
+ }
+ }}
+ placeholder="Search projects…"
+ className="w-full bg-background border border-border/60 rounded-md px-2.5 py-1.5 text-[13px] text-foreground placeholder-foreground/35 outline-none focus:border-primary/60 transition-all"
+ />
+ </div>
+ <div className="py-1 max-h-[50vh] overflow-y-auto">
+ {filtered === null && (
+ <p className="px-3 py-2 text-[13px] text-foreground/40">Loading…</p>
+ )}
+ {filtered !== null && filtered.length === 0 && (
+ <p className="px-3 py-2 text-[13px] text-foreground/40">
+ {query ? `Nothing matches "${query}".` : "No indexed projects yet."}
+ </p>
)}
- </button>
- ))}
- <div className="border-t border-border/40 mt-1 pt-1">
- <button
- onClick={() => {
- setOpen(false);
- onAllProjects();
- }}
- className="w-full text-left px-3 py-1.5 text-[13px] text-foreground/55 hover:text-foreground/85 hover:bg-surface-3 transition-colors"
- >
- {allProjectsLabel} — manage &amp; index →
- </button>
+ {(filtered ?? []).map((project) => (
+ <button
+ key={project.name}
+ onClick={() => {
+ setOpen(false);
+ onSelect(project.name);
+ }}
+ className={`flex items-center gap-2 w-full text-left px-3 py-1.5 transition-colors hover:bg-surface-4 ${
+ project.name === selected ? "text-primary" : "text-foreground/75"
+ }`}
+ >
+ <span className="text-[13px] font-mono truncate">{project.name}</span>
+ {project.name === selected && (
+ <span className="ml-auto text-[11px] shrink-0">●</span>
+ )}
+ </button>
+ ))}
+ </div>
+ <div className="border-t border-border/60 py-1 bg-surface-3">
+ <button
+ onClick={() => {
+ setOpen(false);
+ onAllProjects();
+ }}
+ className="w-full text-left px-3 py-1.5 text-[13px] text-foreground/55 hover:text-foreground/85 hover:bg-surface-4 transition-colors"
+ >
+ {allProjectsLabel} — manage &amp; index →
+ </button>
+ </div>
</div>
- </div>
+ </>
)}
</div>
);