import { useMemo } from "react"; import { Buildings, ChartLineUp, Cpu, CurrencyCircleDollar, Heartbeat, Lightning, Rocket, ShieldCheck, Target, TrendUp, Users, } from "@phosphor-icons/react"; import type { AgentRecord, RunRecord, SectionId, TaskRecord } from "@shared/types"; const DEPARTMENT_INFO: Record = { executive: { label: "Executive", icon: Buildings, color: "var(--accent)" }, engineering: { label: "Engineering", icon: Cpu, color: "#6366f1" }, product: { label: "Product", icon: Rocket, color: "#8b5cf6" }, design: { label: "Design", icon: Target, color: "#ec4899" }, marketing: { label: "Marketing", icon: TrendUp, color: "#0ea5e9" }, sales: { label: "Sales", icon: ChartLineUp, color: "#10b981" }, hr: { label: "People", icon: Users, color: "#06b6d4" }, finance: { label: "Finance", icon: CurrencyCircleDollar, color: "#14b8a6" }, legal: { label: "Legal", icon: ShieldCheck, color: "#64748b" }, operations: { label: "Operations", icon: Lightning, color: "#475569" }, customer_support: { label: "Support", icon: Heartbeat, color: "#3b82f6" }, research: { label: "Research", icon: Target, color: "#a855f7" }, }; export function DepartmentOverview({ agents, tasks, runs, onNavigate, }: { agents: AgentRecord[]; tasks: TaskRecord[]; runs: RunRecord[]; onNavigate: (section: SectionId) => void; }) { const departments = useMemo(() => { const depts = new Map(); for (const agent of agents) { if (agent.status === "terminated") continue; const dept = agent.department ?? "unassigned"; if (!depts.has(dept)) depts.set(dept, { agents: [], tasks: [], activeRuns: 0 }); depts.get(dept)!.agents.push(agent); } for (const task of tasks) { if (task.assigneeAgentId) { const agent = agents.find((a) => a.id === task.assigneeAgentId); if (agent?.department) { const dept = depts.get(agent.department); if (dept) dept.tasks.push(task); } } } for (const run of runs) { if (run.status === "running") { const agent = agents.find((a) => a.id === run.agentId); if (agent?.department) { const dept = depts.get(agent.department); if (dept) dept.activeRuns++; } } } return Array.from(depts.entries()) .filter(([key]) => key !== "unassigned") .sort((a, b) => b[1].agents.length - a[1].agents.length); }, [agents, tasks, runs]); if (departments.length <= 1) return null; return (
{departments.map(([deptId, data]) => { const info = DEPARTMENT_INFO[deptId] ?? { label: deptId, icon: Buildings, color: "var(--muted)" }; const Icon = info.icon; const activeTasks = data.tasks.filter((t) => t.status === "in_progress" || t.status === "in_review").length; const doneTasks = data.tasks.filter((t) => t.status === "done").length; const blockedTasks = data.tasks.filter((t) => t.status === "blocked").length; const runningAgents = data.agents.filter((a) => a.status === "running").length; return ( ); })}
); }