122 lines
5.7 KiB
TypeScript
122 lines
5.7 KiB
TypeScript
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 { cn } from "@/lib/utils";
|
||
import { getT } from "@/lib/i18n";
|
||
import { m, type Translator } from "@peppa/shared/i18n";
|
||
|
||
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 }: { c: Counts; className?: string; t: Translator }) {
|
||
const label = PARTS.map((p) => `${t(p.label)} ${c[p.k]}`).join(", ");
|
||
return (
|
||
<span role="img" aria-label={t("Стори: {list}", { 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 }: { p: ProjectProgress; t: Translator }) {
|
||
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.product && (
|
||
<a href={p.product.url} target="_blank" rel="noreferrer" className="rounded-full border border-ok/50 bg-ok/10 px-2 text-[11px] font-medium text-foreground hover:no-underline" title={p.product.live ? t("Рабочая версия, открыта для всех") : t("Версия для проверки")}>
|
||
{p.product.live ? t("Открыть продукт") : t("Версия для проверки")} ↗
|
||
</a>
|
||
)}
|
||
<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("стори пока нет")
|
||
)}
|
||
</span>
|
||
</div>
|
||
<StackedBar c={p} t={t} />
|
||
{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.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();
|
||
if (!data.mine.length) return <Empty>{t("Проектов пока нет — прогресс появится с первой стори.")}</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} стори в {n} проекте", "готово {done} из {total} стори в {n} проектах", "готово {done} из {total} стори в {n} проектах", { done: tot.done, total: tot.total })}
|
||
</span>
|
||
</div>
|
||
<StackedBar c={tot} className="h-3" t={t} />
|
||
<Legend c={tot} t={t} />
|
||
</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} />
|
||
))}
|
||
</ul>
|
||
</div>
|
||
);
|
||
}
|