Spaces:
Sleeping
Sleeping
File size: 10,103 Bytes
9932e86 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 9932e86 15d8afd 9932e86 0b6365f 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 9932e86 30cd0c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | import { BarChart3, BookOpen, ChevronLeft, ChevronRight, Home, LogOut, Moon, Plus, Sun, Trash2 } from "lucide-react";
import { useTheme } from "next-themes";
import type { Analysis } from "@/services/orchestrationApi";
import { cx, formatDateTime } from "./utils";
export type AppMenuKey = "home" | "knowledge" | "analysis-agent";
interface AppNavigationProps {
active: AppMenuKey;
userName?: string;
collapsed?: boolean;
analyses?: Analysis[];
activeAnalysisId?: string;
loadingAnalyses?: boolean;
onChange: (menu: AppMenuKey) => void;
onLogout: () => void;
onToggleCollapsed?: () => void;
onNewAnalysis?: () => void;
onSelectAnalysis?: (analysis: Analysis) => void;
onDeleteAnalysis?: (analysis: Analysis) => void;
}
const navItems: Array<{
key: AppMenuKey;
label: string;
description: string;
icon: typeof Home;
badge?: string;
}> = [
{
key: "home",
label: "Home",
description: "Overview cara pakai Data Eyond dari knowledge sampai report.",
icon: Home,
},
{
key: "knowledge",
label: "Knowledge",
description: "Langkah pertama: upload dokumen, proses knowledge, atau connect database.",
icon: BookOpen,
badge: "Start here",
},
{
key: "analysis-agent",
label: "Analysis Agent",
description: "Buat analysis, chat dengan AI agent, gunakan Help, dan generate report.",
icon: BarChart3,
},
];
export function AppNavigation({
active,
userName,
collapsed = false,
analyses = [],
activeAnalysisId,
loadingAnalyses = false,
onChange,
onLogout,
onToggleCollapsed,
onNewAnalysis,
onSelectAnalysis,
onDeleteAnalysis,
}: AppNavigationProps) {
const { resolvedTheme, setTheme } = useTheme();
const isDark = resolvedTheme === "dark";
const showAnalysisList = active === "analysis-agent" && !collapsed;
return (
<aside
className={cx(
"flex h-full min-h-0 w-full flex-col border-r border-slate-200 bg-white py-4 text-slate-900 transition-[padding]",
collapsed ? "px-2" : "px-3"
)}
>
<div className={cx("flex items-center pb-5", collapsed ? "flex-col justify-center gap-2 px-0" : "gap-3 px-2")}>
<div className="brand-logo-surface flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-md border p-2 shadow-sm" style={{ backgroundColor: "#ffffff", borderColor: "#e2e8f0" }}>
<img src="/logo.png" alt="Data Eyond" className="h-full w-full object-contain" />
</div>
{!collapsed && (
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold leading-none">Data Eyond</p>
<p className="mt-1 truncate text-xs text-slate-500">Analysis workspace</p>
</div>
)}
{onToggleCollapsed && (
<button
type="button"
title={collapsed ? "Expand sidebar" : "Collapse sidebar"}
aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"}
onClick={onToggleCollapsed}
className="hidden h-8 w-8 items-center justify-center rounded-md text-slate-500 hover:bg-slate-100 hover:text-slate-950 lg:flex"
>
{collapsed ? <ChevronRight className="h-4 w-4" /> : <ChevronLeft className="h-4 w-4" />}
</button>
)}
</div>
<nav className="min-h-0 flex-1 space-y-1 overflow-y-auto" aria-label="Primary workspace navigation">
{navItems.map((item) => {
const Icon = item.icon;
const selected = active === item.key;
return (
<div key={item.key}>
<button
type="button"
title={item.description}
aria-label={`${item.label}: ${item.description}`}
onClick={() => onChange(item.key)}
className={cx(
"group flex w-full items-center rounded-lg py-2.5 text-left text-sm transition",
collapsed ? "justify-center px-2" : "gap-3 px-3",
selected
? "bg-slate-950 text-white shadow-sm"
: "text-slate-600 hover:bg-slate-100 hover:text-slate-950"
)}
>
<Icon className="h-4 w-4 flex-shrink-0" />
{!collapsed && <span className="min-w-0 flex-1 truncate font-medium">{item.label}</span>}
{!collapsed && item.badge && (
<span
className={cx(
"hidden rounded-md px-1.5 py-0.5 text-[10px] font-semibold lg:inline-flex",
selected ? "bg-white/15 text-white" : "bg-emerald-50 text-emerald-700"
)}
>
{item.badge}
</span>
)}
</button>
{item.key === "analysis-agent" && showAnalysisList && (
<div className="mt-2 space-y-2 border-l border-slate-200 pl-3 pr-1">
<button
type="button"
title="Create new analysis"
aria-label="Create new analysis"
onClick={onNewAnalysis}
className="flex w-full items-center gap-2 rounded-md border border-slate-200 bg-white px-2.5 py-2 text-left text-xs font-medium text-slate-600 transition hover:border-emerald-200 hover:bg-emerald-50 hover:text-emerald-700 disabled:cursor-not-allowed disabled:opacity-60"
disabled={!onNewAnalysis}
>
<Plus className="h-3.5 w-3.5" />
<span className="truncate">New analysis</span>
</button>
<div className="space-y-2 pb-2">
<p className="px-1 text-[11px] font-semibold uppercase text-slate-400">Saved analyses</p>
{loadingAnalyses ? (
<div className="rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-xs text-slate-500">Loading analyses</div>
) : analyses.length === 0 ? (
<div className="rounded-md border border-dashed border-slate-200 bg-slate-50 px-3 py-3 text-xs leading-5 text-slate-500">
No analyses yet. Create one after knowledge is ready.
</div>
) : (
analyses.map((analysis) => {
const selectedAnalysis = activeAnalysisId === analysis.id;
return (
<div
key={analysis.id}
className={cx(
"group flex items-start gap-1 rounded-md border transition",
selectedAnalysis ? "border-emerald-200 bg-emerald-50" : "border-slate-200 bg-white hover:bg-slate-50"
)}
>
<button
type="button"
title={analysis.analysis_title}
onClick={() => onSelectAnalysis?.(analysis)}
className="min-w-0 flex-1 rounded-md p-2.5 text-left"
>
<span className="block truncate text-sm font-medium text-slate-900">{analysis.analysis_title}</span>
<span className="mt-1 line-clamp-2 text-xs leading-5 text-slate-500">{analysis.objective}</span>
<span className="mt-2 block text-[11px] text-slate-400">{formatDateTime(analysis.updated_at || analysis.created_at)}</span>
</button>
{onDeleteAnalysis && (
<button
type="button"
title={`Delete ${analysis.analysis_title}`}
aria-label={`Delete ${analysis.analysis_title}`}
onClick={() => onDeleteAnalysis(analysis)}
className="mr-1 mt-2 rounded p-1 text-slate-400 opacity-0 hover:bg-red-50 hover:text-red-600 group-hover:opacity-100 focus:opacity-100"
>
<Trash2 className="h-3.5 w-3.5" />
</button>
)}
</div>
);
})
)}
</div>
</div>
)}
</div>
);
})}
</nav>
<div className="mt-3 border-t border-slate-100 pt-3">
{!collapsed && (
<div className="mb-2 px-2 text-xs text-slate-500">
<p className="truncate font-medium text-slate-700">{userName ?? "Signed in"}</p>
<p>Secure session</p>
</div>
)}
<button
type="button"
title={isDark ? "Switch to light mode" : "Switch to dark mode"}
aria-label={isDark ? "Switch to light mode" : "Switch to dark mode"}
onClick={() => setTheme(isDark ? "light" : "dark")}
className={cx(
"mb-1 flex w-full items-center rounded-lg py-2.5 text-sm font-medium text-slate-600 hover:bg-slate-100 hover:text-slate-950",
collapsed ? "justify-center px-2" : "gap-3 px-3"
)}
>
{isDark ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
{!collapsed && (isDark ? "Light mode" : "Dark mode")}
</button>
<button
type="button"
title="Logout dari workspace"
aria-label="Logout from Data Eyond workspace"
onClick={onLogout}
className={cx(
"flex w-full items-center rounded-lg py-2.5 text-sm font-medium text-slate-600 hover:bg-slate-100 hover:text-slate-950",
collapsed ? "justify-center px-2" : "gap-3 px-3"
)}
>
<LogOut className="h-4 w-4" />
{!collapsed && "Logout"}
</button>
</div>
</aside>
);
}
|