ostra / frontend /src /components /layout /WorkbenchShell.tsx
sumandas's picture
Fix 40% 2D map split, collapsible sidebar, info hover tooltips, and layout alignment
0cf2f43 verified
Raw History Blame Contribute Delete
21.1 kB
import { lazy, Suspense, useState } from "react";
import {
Activity,
ChevronLeft,
Compass,
Database,
FlaskConical,
GitCompare,
LayoutDashboard,
ListChecks,
Loader2,
Maximize2,
PanelRightClose,
PanelRightOpen,
Sliders,
Stethoscope,
X,
} from "lucide-react";
import { useShallow } from "zustand/react/shallow";
import {
useOstraStore,
type Page,
type XRayTab,
} from "../../store/useOstraStore";
import type { DiagnosticLens } from "../../types/ostra";
import { DocInspectorDrawer } from "../atlas/DocInspectorDrawer";
import { HelpInfo } from "../common/HelpInfo";
import { OverviewPage } from "../overview/OverviewPage";
import { DiagnosisAndResultsView } from "../xray/DiagnosisAndResultsView";
import { QueryBarAnatomy } from "../xray/QueryBarAnatomy";
import { CorpusHealthBar } from "./CorpusHealthBar";
// Code-split heavy views (especially Deck.gl WebGL Atlas, Labs, Compare, and Modals)
// so initial HTML + Query Bar + results paint immediately without blocking the main thread.
const AtlasPage = lazy(() =>
import("../atlas/AtlasPage").then((m) => ({ default: m.AtlasPage }))
);
const EmbeddingAtlasCanvas = lazy(() =>
import("../atlas/EmbeddingAtlasCanvas").then((m) => ({
default: m.EmbeddingAtlasCanvas,
}))
);
const CompareRunsPage = lazy(() =>
import("../compare/CompareRunsPage").then((m) => ({
default: m.CompareRunsPage,
}))
);
const LabsPage = lazy(() =>
import("../suite/LabsPage").then((m) => ({ default: m.LabsPage }))
);
const SampleSuitePanel = lazy(() =>
import("../suite/SampleSuitePanel").then((m) => ({
default: m.SampleSuitePanel,
}))
);
const ForensicDiffPanel = lazy(() =>
import("../xray/ForensicDiffPanel").then((m) => ({
default: m.ForensicDiffPanel,
}))
);
const QuadrantAndCliffView = lazy(() =>
import("../xray/QuadrantAndCliffView").then((m) => ({
default: m.QuadrantAndCliffView,
}))
);
const HybridMixingBoard = lazy(() =>
import("../tuners/HybridMixingBoard").then((m) => ({
default: m.HybridMixingBoard,
}))
);
const DatasetWizardModal = lazy(() =>
import("../ingest/DatasetWizardModal").then((m) => ({
default: m.DatasetWizardModal,
}))
);
const ExportRecipeModal = lazy(() =>
import("../suite/ExportRecipeModal").then((m) => ({
default: m.ExportRecipeModal,
}))
);
function LazyViewFallback({ label = "Loading view…" }: { label?: string }) {
return (
<div className="flex-1 h-full paper-canvas flex items-center justify-center gap-2 text-[#334155] font-mono text-xs">
<Loader2 className="w-4 h-4 animate-spin text-sky-600" />
<span>{label}</span>
</div>
);
}
const XRAY_TABS: { id: XRayTab; label: string; icon: React.ReactNode }[] = [
{
id: "diagnosis",
label: "Diagnosis & Results",
icon: <Stethoscope className="w-3.5 h-3.5" />,
},
{
id: "forensic",
label: "Forensic Diff (A vs B)",
icon: <GitCompare className="w-3.5 h-3.5" />,
},
{
id: "cliff",
label: "Confidence & Abstention",
icon: <Activity className="w-3.5 h-3.5" />,
},
];
const SPLIT_MAP_LENSES: { id: DiagnosticLens; label: string }[] = [
{ id: "clusters", label: "Clusters" },
{ id: "hubness", label: "Hubs" },
{ id: "antihubs", label: "Hidden" },
{ id: "truncation", label: "Cut-Off" },
{ id: "purity", label: "Purity" },
];
const NAV_ITEMS: {
id: Page;
label: string;
subtitle: string;
icon: React.ReactNode;
}[] = [
{
id: "debug",
label: "Debug & Map",
subtitle: "Live X-ray + 2D Atlas",
icon: <Stethoscope className="w-4 h-4 shrink-0" />,
},
{
id: "overview",
label: "Overview",
subtitle: "Health & next step",
icon: <LayoutDashboard className="w-4 h-4 shrink-0" />,
},
{
id: "suite",
label: "Eval Suite",
subtitle: "Questions, triage & gate",
icon: <ListChecks className="w-4 h-4 shrink-0" />,
},
{
id: "optimize",
label: "Optimize",
subtitle: "Verified fix labs",
icon: <FlaskConical className="w-4 h-4 shrink-0" />,
},
{
id: "atlas",
label: "Full Atlas",
subtitle: "2D map & facets",
icon: <Compass className="w-4 h-4 shrink-0" />,
},
{
id: "compare",
label: "Compare",
subtitle: "Model & run bakeoff",
icon: <GitCompare className="w-4 h-4 shrink-0" />,
},
];
export function WorkbenchShell() {
const {
activeRun,
runs,
loadingRun,
page,
lab,
xrayTab,
sidebarCollapsed,
setSidebarCollapsed,
mixingDrawerOpen,
setMixingDrawerOpen,
openOverview,
setXRayTab,
openSuite,
openLab,
openAtlas,
openCompare,
setWizardOpen,
wizardOpen,
exportModalOpen,
activeLens,
setActiveLens,
atlasBinary,
loadingAtlas,
suiteItems,
baselineCheck,
facets,
} = useOstraStore(
useShallow((s) => ({
activeRun: s.activeRun,
runs: s.runs,
loadingRun: s.loadingRun,
page: s.page,
lab: s.lab,
xrayTab: s.xrayTab,
sidebarCollapsed: s.sidebarCollapsed,
setSidebarCollapsed: s.setSidebarCollapsed,
mixingDrawerOpen: s.mixingDrawerOpen,
setMixingDrawerOpen: s.setMixingDrawerOpen,
openOverview: s.openOverview,
setXRayTab: s.setXRayTab,
openSuite: s.openSuite,
openLab: s.openLab,
openAtlas: s.openAtlas,
openCompare: s.openCompare,
setWizardOpen: s.setWizardOpen,
wizardOpen: s.wizardOpen,
exportModalOpen: s.exportModalOpen,
activeLens: s.activeLens,
setActiveLens: s.setActiveLens,
atlasBinary: s.atlasBinary,
loadingAtlas: s.loadingAtlas,
suiteItems: s.suiteItems,
baselineCheck: s.baselineCheck,
facets: s.facets,
}))
);
const [splitMapVisible, setSplitMapVisible] = useState(true);
const navigate = (target: Page) => {
if (target === "overview") openOverview();
else if (target === "debug") setXRayTab(xrayTab);
else if (target === "suite") openSuite();
else if (target === "optimize") openLab(lab);
else if (target === "atlas") openAtlas();
else openCompare();
};
return (
<div className="h-screen w-screen flex flex-col bg-[#f7f8fa] text-[#0f172a] overflow-hidden">
<CorpusHealthBar />
{loadingRun ? (
<div className="flex-1 paper-canvas flex items-center justify-center gap-2 text-[#334155] font-mono text-xs">
<Loader2 className="w-4 h-4 animate-spin text-sky-600" />
<span>Loading binary Atlas &amp; sparse BM25 index…</span>
</div>
) : !activeRun ? (
<div className="flex-1 paper-canvas flex flex-col items-center justify-center p-8">
<div className="paper-card max-w-md w-full p-6 text-center space-y-4">
<span className="paper-legend">Ostra Workbench</span>
<div className="mx-auto w-12 h-12 bg-[#f1f4f8] border-[1.5px] border-[#0f172a] flex items-center justify-center relative">
<Database className="w-6 h-6 text-sky-700" />
<span className="absolute -top-1 -right-1 w-2.5 h-2.5 bg-emerald-500 border border-[#0f172a]" />
</div>
<div className="space-y-1.5">
<h1 className="text-base font-mono font-bold text-[#0f172a] tracking-tight">
Visual Debugger for Embedding &amp; Hybrid Search
</h1>
<p className="text-xs text-[#475569] leading-relaxed">
Select any public Hugging Face text dataset &amp; embedding model,
diagnose why vector or hybrid search fails, optimize fusion and
reranking against an eval suite, and export verified configs.
</p>
</div>
<button
type="button"
onClick={() => setWizardOpen(true)}
className="paper-btn-ink px-4 py-2 text-xs font-semibold cursor-pointer inline-flex items-center gap-1.5"
>
<span>Select Hugging Face Dataset →</span>
</button>
</div>
</div>
) : (
<div className="flex-1 flex min-h-0 overflow-hidden">
{/* Primary Collapsible Left Navigation Sidebar (fully collapses to reclaim 100% width) */}
{!sidebarCollapsed && (
<nav className="w-[184px] shrink-0 border-r-[1.5px] border-[#0f172a] bg-[#f1f4f8] flex flex-col justify-between select-none">
<div className="p-2 flex flex-col gap-1 overflow-y-auto">
{NAV_ITEMS.map((item) => {
const active = page === item.id;
const badge =
item.id === "suite" && suiteItems.length > 0
? {
text: String(suiteItems.length),
tone:
baselineCheck?.verdict === "FAIL_REGRESSION"
? "bg-red-600 text-white"
: "bg-[#0f172a] text-white",
}
: item.id === "atlas" && facets?.selection_active
? {
text: String(facets.filtered_count),
tone: "bg-sky-600 text-white",
}
: item.id === "compare" && runs.length >= 2
? {
text: String(runs.length),
tone: "bg-[#e8edf3] text-[#0f172a] border border-[#0f172a]",
}
: null;
return (
<button
key={item.id}
type="button"
title={item.subtitle}
onClick={() => navigate(item.id)}
className={`relative flex items-center justify-between px-2.5 py-2 border-[1.5px] cursor-pointer transition-colors text-left ${
active
? "bg-white border-[#0f172a] text-[#0f172a] shadow-[2px_2px_0_rgba(15,23,42,0.18)]"
: "border-transparent text-[#475569] hover:bg-white/80 hover:border-[#94a3b8] hover:text-[#0f172a]"
}`}
>
<div className="flex items-center gap-2 min-w-0">
<span
className={active ? "text-[#0f172a]" : "text-[#64748b]"}
>
{item.icon}
</span>
<div className="min-w-0">
<div className="font-mono text-[11px] font-bold leading-tight truncate">
{item.label}
</div>
<div className="text-[10px] text-[#64748b] leading-tight truncate">
{item.subtitle}
</div>
</div>
</div>
{badge && (
<span
className={`px-1.5 py-0.5 font-mono text-[9px] font-bold tabular-nums shrink-0 ${badge.tone}`}
>
{badge.text}
</span>
)}
</button>
);
})}
</div>
<div className="p-2 border-t border-[#cbd5e1] flex items-center justify-end">
<button
type="button"
onClick={() => setSidebarCollapsed(true)}
title="Collapse navigation sidebar"
className="w-full py-1 px-2 bg-white hover:bg-[#e8edf3] border border-[#94a3b8] hover:border-[#0f172a] text-[#475569] hover:text-[#0f172a] font-mono text-[10px] inline-flex items-center justify-center gap-1 cursor-pointer"
>
<ChevronLeft className="w-3.5 h-3.5" />
<span>Collapse Sidebar</span>
</button>
</div>
</nav>
)}
{/* Main Full-Width Page Canvas */}
<main className="flex-1 min-w-0 relative paper-canvas overflow-hidden flex flex-col">
{page === "overview" && <OverviewPage />}
{page === "debug" && (
<div className="flex-1 flex flex-col min-h-0 bg-[#f7f8fa]">
<QueryBarAnatomy />
{/* X-Ray View Tabs (Clean 3-tab Folder Strip) */}
<div className="h-9 shrink-0 border-b-[1.5px] border-[#0f172a] bg-[#f1f4f8] px-3 flex items-end justify-between gap-2 overflow-x-auto">
<div className="flex items-end gap-1 shrink-0">
{XRAY_TABS.map((t) => (
<button
key={t.id}
type="button"
onClick={() => setXRayTab(t.id)}
className={`inline-flex items-center gap-1.5 px-2.5 py-1.5 font-mono text-[11px] whitespace-nowrap shrink-0 transition-colors cursor-pointer border-[1.5px] -mb-[1.5px] ${
xrayTab === t.id
? "bg-[#f7f8fa] text-[#0f172a] border-[#0f172a] border-b-[#f7f8fa] font-semibold"
: "bg-[#e8edf3] text-[#475569] border-[#94a3b8] border-b-[#0f172a] hover:text-[#0f172a] hover:bg-white/70"
}`}
>
{t.icon}
<span>{t.label}</span>
</button>
))}
</div>
<div className="self-center flex items-center gap-1.5 shrink-0">
<button
type="button"
onClick={() => setSplitMapVisible((v) => !v)}
className={`h-6 px-2 text-[10px] font-mono font-semibold whitespace-nowrap inline-flex items-center gap-1 border cursor-pointer transition-colors ${
splitMapVisible
? "bg-[#0f172a] text-white border-[#0f172a]"
: "bg-white text-[#0f172a] border-[#0f172a] hover:bg-sky-50"
}`}
title={
splitMapVisible
? "Hide live 2D Map split pane"
: "Show live 2D Map alongside Debug results"
}
>
{splitMapVisible ? (
<>
<PanelRightClose className="w-3 h-3 text-sky-400" />
<span>Hide 2D Map</span>
</>
) : (
<>
<PanelRightOpen className="w-3 h-3 text-sky-700" />
<span>Show 2D Map</span>
</>
)}
</button>
<button
type="button"
onClick={() => openAtlas(activeLens)}
className="paper-btn h-6 px-2 text-[10px] font-semibold whitespace-nowrap inline-flex items-center gap-1 cursor-pointer"
title="Expand 2D Corpus Atlas with full Facets & Cross-Filter sidebar"
>
<Maximize2 className="w-3 h-3 text-sky-700" />
<span>Full Map &amp; Facets</span>
</button>
</div>
</div>
{/* Immersive Split Home Workspace: Debug X-Ray (Left 60%) + Live 2D Corpus Map (Right 40% of screen) */}
<div className="flex-1 min-h-0 flex overflow-hidden paper-canvas">
<div className="flex-1 min-w-0 min-h-0 overflow-hidden @container">
{xrayTab === "diagnosis" && <DiagnosisAndResultsView />}
{xrayTab === "forensic" && (
<Suspense fallback={<LazyViewFallback label="Loading Forensic Diff…" />}>
<ForensicDiffPanel />
</Suspense>
)}
{xrayTab === "cliff" && (
<Suspense fallback={<LazyViewFallback label="Loading Confidence & Cliff…" />}>
<QuadrantAndCliffView />
</Suspense>
)}
</div>
{splitMapVisible && (
<section className="hidden md:flex w-[40vw] min-w-[340px] max-w-[55%] shrink-0 border-l-[1.5px] border-[#0f172a] bg-[#f7f8fa] flex-col min-h-0 overflow-hidden">
<div className="h-9 shrink-0 border-b border-[#cbd5e1] bg-[#f1f4f8] px-2.5 flex items-center justify-between gap-2 overflow-x-auto">
<div className="inline-flex items-center gap-1.5 font-mono text-[10px] font-bold text-[#0f172a] shrink-0">
<Compass className="w-3.5 h-3.5 text-sky-600" />
<span>2D Map</span>
<HelpInfo topic="atlasLens" />
</div>
<div className="flex items-center gap-1 shrink-0">
{SPLIT_MAP_LENSES.map((l) => (
<button
key={l.id}
type="button"
onClick={() => setActiveLens(l.id)}
className={`px-1.5 py-0.5 font-mono text-[10px] whitespace-nowrap border cursor-pointer transition-colors ${
activeLens === l.id
? "bg-[#0f172a] text-white border-[#0f172a] font-semibold"
: "bg-white text-[#475569] border-[#cbd5e1] hover:border-[#0f172a] hover:text-[#0f172a]"
}`}
>
{l.label}
</button>
))}
</div>
</div>
<div className="flex-1 relative min-h-0">
{loadingAtlas && !atlasBinary ? (
<LazyViewFallback label="Loading 2D Map coordinates…" />
) : (
<Suspense fallback={<LazyViewFallback label="Initializing 2D Map…" />}>
<EmbeddingAtlasCanvas showLensBar={false} compact />
</Suspense>
)}
</div>
</section>
)}
</div>
</div>
)}
{page === "suite" && (
<Suspense fallback={<LazyViewFallback label="Loading Eval Suite…" />}>
<SampleSuitePanel />
</Suspense>
)}
{page === "optimize" && (
<Suspense fallback={<LazyViewFallback label="Loading Optimization Labs…" />}>
<LabsPage />
</Suspense>
)}
{page === "atlas" && (
<Suspense fallback={<LazyViewFallback label="Loading 2D Corpus Atlas…" />}>
<AtlasPage />
</Suspense>
)}
{page === "compare" && (
<Suspense fallback={<LazyViewFallback label="Loading Run Bakeoff…" />}>
<CompareRunsPage />
</Suspense>
)}
<DocInspectorDrawer />
</main>
{/* Optional On-Demand Right Drawer: Live Engine Controls (collapsed by default!) */}
{mixingDrawerOpen && (
<aside className="w-[332px] shrink-0 border-l-[1.5px] border-[#0f172a] bg-[#f7f8fa] flex flex-col overflow-hidden">
<div className="h-10 shrink-0 border-b-[1.5px] border-[#0f172a] bg-[#f1f4f8] px-3 flex items-center justify-between gap-2">
<div className="inline-flex items-center gap-1.5 font-mono text-[11px] font-bold text-[#0f172a]">
<Sliders className="w-3.5 h-3.5 text-emerald-700" />
<span>Engine Controls</span>
</div>
<button
type="button"
onClick={() => setMixingDrawerOpen(false)}
title="Close Engine Controls drawer"
className="p-1 bg-white hover:bg-[#e8edf3] border border-[#0f172a] text-[#0f172a] cursor-pointer"
>
<X className="w-3.5 h-3.5" />
</button>
</div>
<Suspense fallback={<LazyViewFallback label="Loading controls…" />}>
<HybridMixingBoard />
</Suspense>
</aside>
)}
</div>
)}
{/* Modals (mounted strictly on demand) */}
{wizardOpen && (
<Suspense fallback={null}>
<DatasetWizardModal />
</Suspense>
)}
{exportModalOpen && (
<Suspense fallback={null}>
<ExportRecipeModal />
</Suspense>
)}
</div>
);
}