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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
feat(graph-ui): sync active tab and project to the URL
Zadak0c7883eb2f04
diff --git a/graph-ui/src/App.tsx b/graph-ui/src/App.tsxindex 732a9d18a..18392667c 100644--- a/graph-ui/src/App.tsx+++ b/graph-ui/src/App.tsx@@ -1,14 +1,62 @@-import { useState } from "react";+import { useCallback, useEffect, useState } from "react";import { GraphTab } from "./components/GraphTab";import { StatsTab } from "./components/StatsTab";import { ControlTab } from "./components/ControlTab";import type { TabId } from "./lib/types";import { useUiMessages } from "./lib/i18n";+const TAB_IDS: TabId[] = ["graph", "stats", "control"];++interface RouteState {+ tab: TabId;+ project: string | null;+}++/* Read the active tab + selected project from the URL query string so the+ * current view survives refreshes and can be bookmarked or shared. */+function readRoute(): RouteState {+ const params = new URLSearchParams(window.location.search);+ const rawTab = params.get("tab");+ const tab = TAB_IDS.includes(rawTab as TabId) ? (rawTab as TabId) : "stats";+ const project = params.get("project");+ return { tab, project: project ? project : null };+}++/* Build the canonical URL for a route, preserving the path and hash. */+function routeUrl(tab: TabId, project: string | null): string {+ const params = new URLSearchParams();+ params.set("tab", tab);+ if (project) params.set("project", project);+ return `${window.location.pathname}?${params.toString()}${window.location.hash}`;+}+export function App() {const t = useUiMessages();- const [activeTab, setActiveTab] = useState<TabId>("stats");- const [selectedProject, setSelectedProject] = useState<string | null>(null);+ const [route, setRoute] = useState<RouteState>(readRoute);+ const { tab: activeTab, project: selectedProject } = route;++ /* Normalize the URL on first load so it always carries the current route. */+ useEffect(() => {+ const initial = readRoute();+ window.history.replaceState(null, "", routeUrl(initial.tab, initial.project));+ }, []);++ /* Sync state when the user navigates with the browser back/forward buttons. */+ useEffect(() => {+ const onPopState = () => setRoute(readRoute());+ window.addEventListener("popstate", onPopState);+ return () => window.removeEventListener("popstate", onPopState);+ }, []);++ /* Change the route and push a history entry (skips no-op navigations). */+ const navigate = useCallback((tab: TabId, project: string | null) => {+ const url = routeUrl(tab, project);+ const current = `${window.location.pathname}${window.location.search}${window.location.hash}`;+ if (url === current) return;+ window.history.pushState(null, "", url);+ setRoute({ tab, project });+ }, []);+const tabs: { id: TabId; label: string }[] = [{ id: "graph", label: t.tabs.graph },{ id: "stats", label: t.tabs.projects },@@ -29,19 +77,26 @@ export function App() {{/* Tabs inline in header */}<nav className="flex items-center gap-0.5">- {tabs.map((tab) => (- <button- key={tab.id}- onClick={() => setActiveTab(tab.id)}- className={`px-3 py-1 rounded-md text-[12px] font-medium transition-all ${- activeTab === tab.id- ? "bg-primary/15 text-primary"- : "text-muted-foreground hover:text-foreground hover:bg-white/[0.04]"- }`}- >- {tab.label}- </button>- ))}+ {tabs.map((tab) => {+ const disabled = tab.id === "graph" && !selectedProject;+ return (+ <button+ key={tab.id}+ onClick={() => navigate(tab.id, tab.id === "stats" ? null : selectedProject)}+ disabled={disabled}+ title={disabled ? "Select a project first" : undefined}+ className={`px-3 py-1 rounded-md text-[12px] font-medium transition-all ${+ disabled+ ? "text-muted-foreground/30 cursor-not-allowed"+ : activeTab === tab.id+ ? "bg-primary/15 text-primary"+ : "text-muted-foreground hover:text-foreground hover:bg-white/[0.04]"+ }`}+ >+ {tab.label}+ </button>+ );+ })}</nav></div>@@ -54,7 +109,7 @@ export function App() {{selectedProject}</span><button- onClick={() => { setSelectedProject(null); setActiveTab("stats"); }}+ onClick={() => navigate("stats", null)}className="text-foreground/20 hover:text-foreground/50 text-[12px] ml-1 transition-colors">×@@ -71,10 +126,7 @@ export function App() {<ControlTab />) : (<StatsTab- onSelectProject={(p) => {- setSelectedProject(p);- setActiveTab("graph");- }}+ onSelectProject={(p) => navigate("graph", p)}/>)}</main>