peppa/apps/web/app/(app)/p/[key]/tabs.tsx
Асель 328900e254 PEP-66: epics (goals as story labels), tabs Код/Спеки/PR, bug settings in ⋯
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 03:28:34 +05:00

200 lines
9.4 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.

// Project page tabs «Код», «Спеки», «PR» and the epics block of «⋯ Настройки проекта» (PEP-66).
import { Archive, ExternalLink, GitBranch, GitPullRequest } from "lucide-react";
import type { Epic, SpecSummary } from "@peppa/core";
import type { OpenPull, RepoOverview } from "@peppa/runner";
import { addEpic, editEpic } from "../../actions";
import { Hidden } from "@/components/cards";
import { Disclosure, Empty, Key, Section, StatusBadge } from "@/components/common";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Input, Textarea } from "@/components/ui/input";
const when = (iso: string | null) => (iso ? new Date(iso).toLocaleString("ru-RU", { dateStyle: "short", timeStyle: "short" }) : "—");
function plural(n: number, one: string, few: string, many: string) {
const m10 = n % 10;
const m100 = n % 100;
return m10 === 1 && m100 !== 11 ? one : m10 >= 2 && m10 <= 4 && (m100 < 12 || m100 > 14) ? few : many;
}
export function CodeTab({ code }: { code: RepoOverview }) {
const gitea = (
<Button asChild size="sm">
<a href={code.url}>
Открыть в Gitea <ExternalLink />
</a>
</Button>
);
if (code.error) {
return (
<Section title="Код" actions={gitea}>
<Empty>{code.error}. Репозиторий: <a href={code.url} className="text-primary">{code.url}</a></Empty>
</Section>
);
}
return (
<div className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_320px]">
<Section title={<>README {code.readme && <span className="ml-1 font-mono text-xs font-normal text-muted-foreground">{code.readme.path}</span>}</>} actions={gitea}>
{code.readme ? (
<pre className="m-0 max-h-[40em] overflow-auto rounded-lg border bg-card p-4 font-mono text-xs leading-relaxed whitespace-pre-wrap">{code.readme.text}</pre>
) : (
<Empty>{code.defaultBranch ? `В ветке ${code.defaultBranch} нет README.` : "Репозиторий пуст."}</Empty>
)}
</Section>
<div className="flex flex-col gap-6">
<Section title="Ветки" count={code.branches.length}>
{code.branches.length === 0 ? (
<Empty>Веток нет.</Empty>
) : (
<ul className="m-0 flex list-none flex-col gap-1 p-0 text-sm">
{code.branches.map((b) => (
<li key={b.name} className="flex min-w-0 items-center gap-2 rounded-md px-2 py-1">
<GitBranch className="size-3.5 shrink-0 text-muted-foreground" />
<a href={`${code.url}/src/branch/${b.name.split("/").map(encodeURIComponent).join("/")}`} className="truncate font-mono text-xs text-primary">
{b.name}
</a>
{b.name === code.defaultBranch && <Badge variant="muted">по умолчанию</Badge>}
<span className="ml-auto shrink-0 font-mono text-[11px] text-muted-foreground">{b.sha.slice(0, 7)}</span>
</li>
))}
</ul>
)}
</Section>
<Section title={`Коммиты ${code.defaultBranch ?? ""}`}>
{code.commits.length === 0 ? (
<Empty>Коммитов нет.</Empty>
) : (
<ul className="m-0 flex list-none flex-col gap-2 p-0 text-sm">
{code.commits.map((c) => (
<li key={c.sha} className="flex flex-col gap-0.5 rounded-md border bg-card px-3 py-2">
<span className="[overflow-wrap:anywhere]">{c.message}</span>
<span className="flex flex-wrap gap-x-2 text-xs text-muted-foreground">
<a href={c.url} className="font-mono text-primary">{c.sha.slice(0, 7)}</a>
{c.author} · {when(c.date)}
</span>
</li>
))}
</ul>
)}
</Section>
</div>
</div>
);
}
export function SpecsTab({ specs }: { specs: SpecSummary[] }) {
return (
<Section title="Спеки" count={specs.length}>
<p className="m-0 text-sm text-muted-foreground">Что система умеет сейчас: требования OpenSpec из рабочей копии (openspec/specs). Обновляются, когда стори архивирует свой change.</p>
{specs.length === 0 ? (
<Empty>Спек ещё нет — они появляются после archive первого change.</Empty>
) : (
specs.map((s) => (
<Disclosure
key={s.name}
summary={
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
<span className="flex items-center gap-2">
<span className="font-mono">{s.name}</span>
<Badge variant="muted">
{s.requirements} {plural(s.requirements, "требование", "требования", "требований")}
</Badge>
</span>
{s.purpose && <span className="text-xs font-normal text-muted-foreground">{s.purpose.split("\n")[0]}</span>}
</span>
}
>
<pre className="m-0 max-h-[40em] overflow-auto font-mono text-xs leading-relaxed whitespace-pre-wrap">{s.text}</pre>
</Disclosure>
))
)}
</Section>
);
}
const CI_TONE = { success: "ok", failure: "danger", pending: "info", none: "muted", not_configured: "muted" } as const;
export function PullsTab({ pulls, error, repoUrl }: { pulls: OpenPull[]; error: string | null; repoUrl: string }) {
return (
<Section
title="Открытые PR"
count={pulls.length}
actions={
<Button asChild size="sm">
<a href={`${repoUrl}/pulls`}>
Все PR в Gitea <ExternalLink />
</a>
</Button>
}
>
{error ? (
<Empty>{error}.</Empty>
) : pulls.length === 0 ? (
<Empty>Открытых PR нет.</Empty>
) : (
pulls.map((p) => (
<article key={p.number} className="flex flex-col gap-1.5 rounded-lg border bg-card p-3.5 text-sm">
<div className="flex items-start gap-2">
<GitPullRequest className="mt-0.5 size-4 shrink-0 text-ok" />
<a href={p.url} className="min-w-0 flex-1 text-foreground [overflow-wrap:anywhere]">
<span className="font-mono text-xs text-muted-foreground">#{p.number}</span> {p.title}
</a>
</div>
<div className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">
<span className="font-mono">{p.branch}</span>
{p.task ? (
<>
· <Key href={`/t/${p.task.key}`}>{p.task.key}</Key>
<StatusBadge status={p.task.status} />
<Badge variant={CI_TONE[p.task.ci.state]}>{p.task.ci.label}</Badge>
</>
) : (
<span>· не стори Пеппы</span>
)}
</div>
</article>
))
)}
</Section>
);
}
/** «⋯ Настройки проекта» → Эпики: labels that group stories (stored as goals). */
export function EpicsPanel({ projectId, epics, back }: { projectId: number; epics: Epic[]; back: string }) {
return (
<div className="flex flex-col gap-2 text-sm">
{epics.length === 0 && <p className="m-0 text-muted-foreground">Эпиков нет. Эпик — метка, которая группирует стори; его описание агент получает вместе со стори.</p>}
{epics.map((e) => (
<details key={e.id} className="group rounded-md border bg-card">
<summary className="flex cursor-pointer list-none items-center gap-2 px-3 py-2 select-none [&::-webkit-details-marker]:hidden">
<span className="text-muted-foreground transition-transform group-open:rotate-90">›</span>
<span className="min-w-0 flex-1 truncate">{e.title}</span>
<span className="font-mono text-[11px] text-muted-foreground">#{e.id}</span>
</summary>
<div className="flex flex-col gap-2 border-t px-3 py-2.5">
<form action={editEpic} className="flex flex-col gap-2">
<Hidden fields={{ projectId, epicId: e.id, back }} />
<Input name="title" required minLength={2} defaultValue={e.title} aria-label="Название эпика" className="h-8" />
<Textarea name="description" rows={3} defaultValue={e.description ?? ""} placeholder="Описание для агента: зачем этот эпик" aria-label="Описание эпика" />
<Button size="xs" className="self-start">Сохранить</Button>
</form>
<form action={editEpic}>
<Hidden fields={{ projectId, epicId: e.id, back, archive: "1" }} />
<Button size="xs" variant="ghost">
<Archive />В архив
</Button>
</form>
</div>
</details>
))}
<form action={addEpic} className="flex flex-col gap-2">
<Hidden fields={{ projectId, back }} />
<div className="flex gap-2">
<Input name="title" required minLength={2} placeholder="Новый эпик" aria-label="Название нового эпика" className="h-8" />
<Button size="sm">Добавить</Button>
</div>
</form>
</div>
);
}