123 lines
5.1 KiB
TypeScript
123 lines
5.1 KiB
TypeScript
import Link from "next/link";
|
||
import type { ProgressOverview as Overview, ProjectProgress } from "@peppa/core";
|
||
import { AgentBadge } from "@/components/AgentBadge";
|
||
import { Disclosure, Empty, Key } from "@/components/common";
|
||
import { cn } from "@/lib/utils";
|
||
|
||
const PARTS = [
|
||
{ k: "done", label: "готово", bar: "bg-ok" },
|
||
{ k: "review", label: "ревью", bar: "bg-primary" },
|
||
{ k: "inProgress", label: "в работе", bar: "bg-info" },
|
||
{ k: "backlog", label: "бэклог", 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 }: { c: Counts; className?: string }) {
|
||
const label = PARTS.map((p) => `${p.label} ${c[p.k]}`).join(", ");
|
||
return (
|
||
<span role="img" aria-label={`Стори: ${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 }: { c: Counts }) {
|
||
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)} />
|
||
{p.label} <b className="font-medium text-foreground">{c[p.k]}</b>
|
||
</span>
|
||
))}
|
||
</span>
|
||
);
|
||
}
|
||
|
||
function ProjectRow({ p }: { p: ProjectProgress }) {
|
||
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>}
|
||
<span className="ml-auto text-xs text-muted-foreground">
|
||
{p.total ? (
|
||
<>
|
||
готово <b className="font-medium text-foreground">{p.done}</b> из {p.total} · {pct(p)}%
|
||
</>
|
||
) : (
|
||
"стори пока нет"
|
||
)}
|
||
</span>
|
||
</div>
|
||
<StackedBar c={p} />
|
||
{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">
|
||
Ждут «Принять»:
|
||
{p.reviewKeys.slice(0, 8).map((k) => (
|
||
<Key key={k} href={`/t/${k}`}>{k}</Key>
|
||
))}
|
||
{p.reviewKeys.length > 8 && <span>и ещё {p.reviewKeys.length - 8}</span>}
|
||
</p>
|
||
)}
|
||
</li>
|
||
);
|
||
}
|
||
|
||
/** PEP-77: progress of all stories and projects on the Home page. */
|
||
export function ProgressOverview({ data }: { data: Overview }) {
|
||
if (!data.mine.length && !data.others.length) return <Empty>Проектов пока нет — прогресс появится с первой стори.</Empty>;
|
||
const t = 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(t)}%</span>
|
||
<span className="text-sm text-muted-foreground">
|
||
готово {t.done} из {t.total} стори в {data.mine.length} {data.mine.length === 1 ? "проекте" : "проектах"}
|
||
</span>
|
||
</div>
|
||
<StackedBar c={t} className="h-3" />
|
||
<Legend c={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} />
|
||
))}
|
||
</ul>
|
||
{data.others.length > 0 && (
|
||
<Disclosure summary={`Проекты других — ${data.others.length}`}>
|
||
<ul className="m-0 mt-2 flex list-none flex-col gap-2 p-0">
|
||
{data.others.map((p) => (
|
||
<ProjectRow key={p.key} p={p} />
|
||
))}
|
||
</ul>
|
||
</Disclosure>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|