peppa/apps/web/components/Sidebar.tsx
Асель 14916079bc PEP-5/43/47/48: usage and limits, story budgets, factory metrics, audit journal
- PEP-5: statusLine hook (cost, context, 5h/7d limit windows), transcript tokens,
  sessions.usage, usage strip over every page, runner usage, bot /status, MCP get_usage
- PEP-43: project/story budgets in settings, watchdog pause (Escape, question to the PM:
  extend x2 / remove limit / stop), start/resume guard, budget on the story card
- PEP-47: project metrics tab (cycle time, first pass, review returns, questions, runner
  hours, PM wait, limits, spend by week/agent/epic), MCP get_metrics
- PEP-48: event authors (actor columns, AsyncLocalStorage context), question_answered,
  /journal for superadmins, project journal tab, authors in the story feed
- Migration 0007_usage_audit; OpenSpec changes archived

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 06:52:13 +05:00

95 lines
5.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Bot, FolderKanban, House, KeyRound, ScrollText, LifeBuoy, LogOut, Search, Settings, Users, type LucideIcon } from "lucide-react";
import { Brand } from "@/components/Brand";
import { ThemeToggle } from "@/components/ThemeToggle";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
interface Item {
href: string;
label: string;
icon: LucideIcon;
match: (p: string) => boolean;
count?: "questions" | "waitingRunners";
/** Superadmin only (PEP-68, PEP-67; others get 404 on the URL too); desktop panel only — on phones it is linked from Settings. */
admin?: boolean;
}
const ITEMS: Item[] = [
{ href: "/", label: "Главная", icon: House, match: (p) => p === "/", count: "questions" },
{ href: "/projects", label: "Проекты", icon: FolderKanban, match: (p) => p.startsWith("/projects") || p.startsWith("/p/") || p.startsWith("/t/") },
{ href: "/runners", label: "Раннеры", icon: Bot, match: (p) => p.startsWith("/runners"), count: "waitingRunners" },
{ href: "/help", label: "Помощь", icon: LifeBuoy, match: (p) => p.startsWith("/help") },
{ href: "/subscriptions", label: "Подписки", icon: KeyRound, match: (p) => p.startsWith("/subscriptions"), admin: true },
{ href: "/journal", label: "Журнал", icon: ScrollText, match: (p) => p.startsWith("/journal"), admin: true },
{ href: "/users", label: "Пользователи", icon: Users, match: (p) => p.startsWith("/users"), admin: true },
{ href: "/settings", label: "Настройки", icon: Settings, match: (p) => p.startsWith("/settings") },
];
const COUNT_TITLE = { questions: "вопросов ждут тебя", waitingRunners: "раннеров ждут тебя" };
/** Left panel on desktop; on phones a top bar plus a bottom tab bar (PEP-38): sections with «ждут тебя» counters, theme, user. */
export function Sidebar({ login, avatarUrl, counts, superadmin = false }: { login: string; avatarUrl: string | null; counts: Record<"questions" | "waitingRunners", number>; superadmin?: boolean }) {
const path = usePathname();
return (
<header className="sticky top-0 z-30 flex h-14 items-center gap-2 border-b bg-sidebar px-3 md:h-dvh md:flex-col md:items-stretch md:gap-1 md:border-r md:border-b-0 md:px-3 md:py-4">
<Link href="/" className="flex shrink-0 items-center gap-2 rounded-md px-1 text-foreground hover:no-underline md:mb-4 md:px-2">
<Brand />
<span className="hidden font-mono text-[11px] text-muted-foreground md:inline">фабрика</span>
</Link>
{/* PEP-52: the palette listens for clicks on [data-open-palette]. */}
<button
type="button"
data-open-palette
title="Поиск и команды (⌘K)"
className="ml-auto flex items-center gap-2 rounded-md border bg-background/60 px-2 py-1.5 text-sm text-muted-foreground transition-colors hover:text-foreground md:mb-2 md:ml-0"
>
<Search className="size-4" />
<span className="hidden md:inline">Поиск</span>
<kbd className="ml-auto hidden rounded border bg-muted px-1 font-mono text-[10px] md:inline">⌘K</kbd>
</button>
<nav
aria-label="Разделы"
className="fixed inset-x-0 bottom-0 z-30 grid grid-cols-5 border-t bg-sidebar/95 pb-[env(safe-area-inset-bottom)] backdrop-blur md:static md:flex md:flex-col md:gap-0.5 md:border-0 md:bg-transparent md:pb-0 md:backdrop-blur-none"
>
{ITEMS.filter((i) => !i.admin || superadmin).map((i) => {
const active = i.match(path);
const n = i.count ? counts[i.count] : 0;
return (
<Link
key={i.href}
href={i.href}
aria-current={active ? "page" : undefined}
className={cn(
i.admin && "max-md:hidden",
"relative flex flex-col items-center gap-0.5 px-1 pt-2 pb-1.5 text-[10px] text-muted-foreground transition-colors hover:text-foreground hover:no-underline md:flex-row md:gap-2 md:rounded-md md:px-2.5 md:py-1.5 md:text-sm md:hover:bg-accent",
active && "font-medium text-foreground md:bg-accent md:before:absolute md:before:inset-y-1.5 md:before:-left-3 md:before:w-0.5 md:before:rounded-full md:before:bg-primary",
)}
>
<i.icon className={cn("size-5 md:size-4", active && "text-primary")} />
<span>{i.label}</span>
{n > 0 && (
<span title={`${n} ${COUNT_TITLE[i.count!]}`} className="absolute top-1 left-[calc(50%+6px)] min-w-4 rounded-full bg-primary px-1 text-center font-mono text-[10px] font-semibold leading-4 text-primary-foreground tabular-nums md:static md:ml-auto md:min-w-5 md:px-1.5 md:text-[11px] md:leading-5">
{n}
</span>
)}
</Link>
);
})}
</nav>
<div className="flex shrink-0 items-center gap-1 md:mt-auto md:ml-0 md:border-t md:pt-3">
{avatarUrl && <img src={avatarUrl} alt="" width={24} height={24} className="hidden size-6 rounded-full md:block" />}
<span className="hidden min-w-0 flex-1 truncate text-sm md:block" title={login}>{login}</span>
<ThemeToggle />
<form action="/logout" method="post">
<Button variant="ghost" size="icon-sm" aria-label="Выйти" title="Выйти">
<LogOut />
</Button>
</form>
</div>
</header>
);
}