peppa/apps/web/components/ProgressOverview.tsx
peppa-bot 0097cb07f7 PEP-182: не больше 9 агентов на подписку — ёмкость, очередь задач, «Делается · В очереди»
Ёмкость подписки (core/capacity.ts, по умолчанию 9, суперадмин меняет на набор 1–20);
pickSubscription, ротация и ручной перевод агентов уважают ёмкость; без места задача
ждёт в очереди и запускается сама по порядку доски (capacityQueueTick); команда растёт
только в пределах ёмкости; экраны «Подписки», Главная, доска, страница задачи; ru/kk/en;
тест subscription-capacity.test.ts; OpenSpec change archived.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 02:55:40 +05:00

136 lines
6.7 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.

import Link from "next/link";
import type { ProgressOverview as Overview, ProjectProgress } from "@peppa/core";
import { AgentBadge } from "@/components/AgentBadge";
import { Empty, Key } from "@/components/common";
import { WorkLine } from "@/components/WorkLine";
import { cn } from "@/lib/utils";
import { getT } from "@/lib/i18n";
import { m, type Translator } from "@peppa/shared/i18n";
import { words } from "@/lib/auth";
import type { Words } from "@peppa/shared/wording";
const PARTS = [
{ k: "done", label: m("готово"), bar: "bg-ok" },
{ k: "review", label: m("ревью"), bar: "bg-primary" },
{ k: "inProgress", label: m("в работе"), bar: "bg-info" },
{ k: "backlog", label: m("бэклог"), bar: "bg-muted-foreground/40" },
] as const;
type Counts = Pick<ProjectProgress, "done" | "review" | "inProgress" | "backlog" | "total">;
/** One bar split by board column: done · review · in work · backlog. */
function StackedBar({ c, className, t, w }: { c: Counts; className?: string; t: Translator; w: Words }) {
const label = PARTS.map((p) => `${t(p.label)} ${c[p.k]}`).join(", ");
return (
<span role="img" aria-label={t("{Tasks}: {list}", { Tasks: w.Task("pl"), list: label })} title={label} className={cn("flex h-2 w-full gap-0.5 overflow-hidden rounded-full bg-muted", className)}>
{c.total > 0 && PARTS.map((p) => (c[p.k] ? <span key={p.k} className={cn("h-full", p.bar)} style={{ flexGrow: c[p.k], flexBasis: 0 }} /> : null))}
</span>
);
}
const pct = (c: Counts) => (c.total ? Math.round((c.done / c.total) * 100) : 0);
function Legend({ c, t }: { c: Counts; t: Translator }) {
return (
<span className="flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground">
{PARTS.map((p) => (
<span key={p.k} className="inline-flex items-center gap-1">
<span aria-hidden className={cn("size-2 rounded-full", p.bar)} />
{t(p.label)} <b className="font-medium text-foreground">{c[p.k]}</b>
</span>
))}
</span>
);
}
function ProjectRow({ p, t, w }: { p: ProjectProgress; t: Translator; w: Words }) {
return (
<li className="flex flex-col gap-2 rounded-lg border bg-card px-4 py-3">
<div className="flex flex-wrap items-center gap-2 text-sm">
<Key href={`/p/${p.key}`}>{p.key}</Key>
<Link href={`/p/${p.key}`} className="min-w-0 truncate font-medium text-foreground hover:no-underline">{p.name}</Link>
{p.ownerLogin && <span className="rounded-full border px-2 text-[11px] text-muted-foreground">{p.ownerLogin}</span>}
{p.paused && (
<span className="rounded-full border border-warn/40 bg-warn/12 px-2 text-[11px] font-medium text-warn">{t("На паузе")}</span>
)}
{p.product ? (
<a href={p.product.url} target="_blank" rel="noreferrer" className="rounded-full border border-ok/60 bg-ok/15 px-3 py-0.5 text-xs font-semibold text-foreground hover:bg-ok/25 hover:no-underline" title={p.product.live ? t("Рабочая версия, открыта для всех") : t("Версия для проверки — пока её видите только вы")}>
{t("Открыть продукт")} ↗
</a>
) : p.productFix ? (
<Link href={`/t/${p.productFix}`} className="rounded-full border border-info/50 bg-info/10 px-2 text-[11px] font-medium text-foreground hover:no-underline">
{t("Готовим ссылку на продукт")}
</Link>
) : null}
<span className="ml-auto text-xs text-muted-foreground">
{p.total ? (
<>
{t("готово")} <b className="font-medium text-foreground">{p.done}</b> {t("из {total}", { total: p.total })} · {pct(p)}%
</>
) : (
t("{tasks} пока нет", { tasks: w.task("genPl") })
)}
</span>
</div>
<StackedBar c={p} t={t} w={w} />
<WorkLine line={p.work} className="text-xs" />
{p.working.length > 0 && (
<ul className="m-0 flex list-none flex-col gap-1 p-0 text-sm">
{p.working.map((s) => (
<li key={s.key} className="flex flex-wrap items-center gap-x-2 gap-y-0.5">
<Key href={`/t/${s.key}`}>{s.key}</Key>
<span className="min-w-0 flex-[1_1_10em] truncate">{s.title}</span>
{s.agent && <AgentBadge name={s.agent} className="text-muted-foreground" />}
{s.queued != null && <span className="text-xs text-muted-foreground">{t("В очереди: {n}-я, начнётся, когда освободится агент", { n: s.queued })}</span>}
{s.total ? (
<span className="text-xs text-muted-foreground" title={s.current ?? undefined}>
{s.done}/{s.total}
</span>
) : null}
</li>
))}
</ul>
)}
{p.reviewKeys.length > 0 && (
<p className="m-0 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
{t("Ждут «Принять»:")}
{p.reviewKeys.slice(0, 8).map((k) => (
<Key key={k} href={`/t/${k}`}>{k}</Key>
))}
{p.reviewKeys.length > 8 && <span>{t("и ещё {n}", { n: p.reviewKeys.length - 8 })}</span>}
</p>
)}
</li>
);
}
/** PEP-77: progress of the user's own projects on the Home page (other people's projects — on «Проекты», for a superadmin). */
export async function ProgressOverview({ data }: { data: Overview }) {
const t = await getT();
const w = await words();
if (!data.mine.length) return <Empty>{t("Проектов пока нет — прогресс появится с первой {task}.", { task: w.task("ins") })}</Empty>;
const tot = data.totals;
return (
<div className="flex flex-col gap-3">
{data.mine.length > 0 && (
<div className="flex flex-col gap-2 rounded-lg border bg-card px-4 py-3">
<div className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
<span className="text-2xl font-semibold tabular-nums">{pct(tot)}%</span>
<span className="text-sm text-muted-foreground">
{t.n(data.mine.length, "готово {done} из {total} {tasks} в {n} проекте", "готово {done} из {total} {tasks} в {n} проектах", "готово {done} из {total} {tasks} в {n} проектах", { done: tot.done, total: tot.total, tasks: w.task("genPl") })}
</span>
</div>
<StackedBar c={tot} className="h-3" t={t} w={w} />
<Legend c={tot} t={t} />
<WorkLine line={data.work} />
</div>
)}
<ul className="m-0 flex list-none flex-col gap-2 p-0">
{data.mine.map((p) => (
<ProjectRow key={p.key} p={p} t={t} w={w} />
))}
</ul>
</div>
);
}