Merge pull request 'UI: вкладки проекта, «+ Стори» в заголовке, цели — в настройках' (#32) from ui/project-tabs into main
This commit is contained in:
commit
e76fc92150
@ -1,19 +1,20 @@
|
|||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { ExternalLink, Plus, Rocket, Target } from "lucide-react";
|
import { ExternalLink, Plus, Rocket } from "lucide-react";
|
||||||
import { columnOf, currentReleases, describeRepo, isPlatform, listReleases, bugsinkWebhookBase, platformReleaseCandidate, type Release } from "@peppa/runner";
|
import { columnOf, currentReleases, describeRepo, isPlatform, listReleases, bugsinkWebhookBase, platformReleaseCandidate, type Release } from "@peppa/runner";
|
||||||
import { getIncidentSettings, listErrorSources, listIncidents, listMembers, repoAudience, repoVisibilityLabel } from "@peppa/core";
|
import { getIncidentSettings, listErrorSources, listIncidents, listMembers, repoAudience, repoVisibilityLabel } from "@peppa/core";
|
||||||
import { AutoRefresh } from "@/components/AutoRefresh";
|
import { AutoRefresh } from "@/components/AutoRefresh";
|
||||||
import { PanelSection } from "@/components/ActivityAside";
|
import { PanelSection } from "@/components/ActivityAside";
|
||||||
import { Board, type Card } from "@/components/Board";
|
import { Board, type Card } from "@/components/Board";
|
||||||
import { Hidden, SessionCard } from "@/components/cards";
|
import { Hidden, SessionCard } from "@/components/cards";
|
||||||
import { Disclosure, Empty, Flash, Key, Notice, PageHeader, Section } from "@/components/common";
|
import { Empty, Flash, Key, Notice, PageHeader, Section } from "@/components/common";
|
||||||
import { IncidentsSection } from "@/components/Incidents";
|
import { IncidentsSection } from "@/components/Incidents";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input, Textarea } from "@/components/ui/input";
|
import { Input, NativeSelect, Textarea } from "@/components/ui/input";
|
||||||
import { SettingsDialog } from "@/components/SettingsDialog";
|
import { SettingsDialog } from "@/components/SettingsDialog";
|
||||||
import { Workspace } from "@/components/Workspace";
|
import { Workspace } from "@/components/Workspace";
|
||||||
import { requireUser } from "@/lib/auth";
|
import { requireUser } from "@/lib/auth";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { board, projectForUserByKey, projectSessions } from "@/lib/queries";
|
import { board, projectForUserByKey, projectSessions } from "@/lib/queries";
|
||||||
import { addGoal, addProjectMember, addTask, deployProdAction, grantRepoAccessToMembers, removeProjectMember } from "../../actions";
|
import { addGoal, addProjectMember, addTask, deployProdAction, grantRepoAccessToMembers, removeProjectMember } from "../../actions";
|
||||||
@ -26,6 +27,13 @@ const RELEASE_STATUS: Record<Release["status"], { label: string; tone: "info" |
|
|||||||
removed: { label: "удалён", tone: "muted" },
|
removed: { label: "удалён", tone: "muted" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TABS = [
|
||||||
|
{ id: "board", label: "Доска" },
|
||||||
|
{ id: "releases", label: "Релизы" },
|
||||||
|
{ id: "bugs", label: "Баги" },
|
||||||
|
{ id: "sessions", label: "Сессии" },
|
||||||
|
] as const;
|
||||||
|
|
||||||
function EnvLine({ name, r }: { name: string; r: Release | null | undefined }) {
|
function EnvLine({ name, r }: { name: string; r: Release | null | undefined }) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-w-0 flex-1 flex-col gap-0.5 rounded-md border bg-background/40 px-3 py-2">
|
<div className="flex min-w-0 flex-1 flex-col gap-0.5 rounded-md border bg-background/40 px-3 py-2">
|
||||||
@ -46,10 +54,11 @@ function EnvLine({ name, r }: { name: string; r: Release | null | undefined }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function ProjectPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string; created?: string }> }) {
|
export default async function ProjectPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string; created?: string; tab?: string }> }) {
|
||||||
const user = await requireUser();
|
const user = await requireUser();
|
||||||
const { key } = await params;
|
const { key } = await params;
|
||||||
const { error, created } = await searchParams;
|
const { error, created, tab: tabParam } = await searchParams;
|
||||||
|
const tab = TABS.find((t) => t.id === tabParam)?.id ?? "board";
|
||||||
const p = await projectForUserByKey(user.id, key).catch(() => null);
|
const p = await projectForUserByKey(user.id, key).catch(() => null);
|
||||||
if (!p) notFound();
|
if (!p) notFound();
|
||||||
const [{ goals, tasks }, sessions, team, repo, incidentSettings, sources, incidents, releases, current] = await Promise.all([
|
const [{ goals, tasks }, sessions, team, repo, incidentSettings, sources, incidents, releases, current] = await Promise.all([
|
||||||
@ -71,8 +80,7 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr
|
|||||||
repo.collaborators !== null && login.toLowerCase() !== p.giteaOwner.toLowerCase() && !collaborators.has(login.toLowerCase());
|
repo.collaborators !== null && login.toLowerCase() !== p.giteaOwner.toLowerCase() && !collaborators.has(login.toLowerCase());
|
||||||
const missingAccess = team.members.some((m) => noRepoAccess(m.login));
|
const missingAccess = team.members.some((m) => noRepoAccess(m.login));
|
||||||
const isOwner = p.ownerId === user.id;
|
const isOwner = p.ownerId === user.id;
|
||||||
const back = `/p/${p.key}`;
|
const back = tab === "board" ? `/p/${p.key}` : `/p/${p.key}?tab=${tab}`;
|
||||||
const groups = [...goals.map((g) => ({ goal: g })), { goal: null }];
|
|
||||||
const goalTitle = new Map(goals.map((g) => [g.id, g.title]));
|
const goalTitle = new Map(goals.map((g) => [g.id, g.title]));
|
||||||
const cards: Card[] = tasks.map((t) => ({
|
const cards: Card[] = tasks.map((t) => ({
|
||||||
key: `${p.key}-${t.number}`,
|
key: `${p.key}-${t.number}`,
|
||||||
@ -159,9 +167,39 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr
|
|||||||
)}
|
)}
|
||||||
{isOwner && <p className="m-0 text-xs text-muted-foreground">Участник видит доску и входящие, двигает карточки и отвечает агентам; получает доступ на запись к репозиторию.</p>}
|
{isOwner && <p className="m-0 text-xs text-muted-foreground">Участник видит доску и входящие, двигает карточки и отвечает агентам; получает доступ на запись к репозиторию.</p>}
|
||||||
</PanelSection>
|
</PanelSection>
|
||||||
|
|
||||||
|
<PanelSection title="Цели" count={goals.length}>
|
||||||
|
<ul className="m-0 flex list-none flex-col gap-1 p-0 text-sm">
|
||||||
|
{goals.map((g) => (
|
||||||
|
<li key={g.id} className="px-2">◎ {g.title}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<form action={addGoal} className="flex flex-col gap-2">
|
||||||
|
<Hidden fields={{ projectId: p.id, back }} />
|
||||||
|
<Input name="title" required placeholder="Новая цель" aria-label="Название цели" className="h-8" />
|
||||||
|
<Textarea name="description" rows={2} placeholder="Зачем и какой результат" aria-label="Описание цели" />
|
||||||
|
<Button size="sm" className="self-start">Создать цель</Button>
|
||||||
|
</form>
|
||||||
|
</PanelSection>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const newTask = (
|
||||||
|
<form action={addTask} className="flex flex-col gap-2">
|
||||||
|
<Hidden fields={{ projectId: p.id, back }} />
|
||||||
|
<Input name="title" required placeholder="Что сделать" aria-label="Название стори" />
|
||||||
|
<Textarea name="description" rows={5} placeholder="Описание: кому и зачем, критерии готовности" aria-label="Описание стори" />
|
||||||
|
<NativeSelect name="goalId" aria-label="Цель" defaultValue="">
|
||||||
|
<option value="">Без цели</option>
|
||||||
|
{goals.map((g) => (
|
||||||
|
<option key={g.id} value={g.id}>◎ {g.title}</option>
|
||||||
|
))}
|
||||||
|
</NativeSelect>
|
||||||
|
<Button variant="default" size="sm" className="self-start">Создать стори</Button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
const tabCount: Partial<Record<(typeof TABS)[number]["id"], number>> = { board: tasks.length, bugs: incidents.length, sessions: sessions.length };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Workspace aside={null} wide>
|
<Workspace aside={null} wide>
|
||||||
<AutoRefresh />
|
<AutoRefresh />
|
||||||
@ -175,7 +213,14 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr
|
|||||||
</Notice>
|
</Notice>
|
||||||
)}
|
)}
|
||||||
<PageHeader
|
<PageHeader
|
||||||
actions={<SettingsDialog title="Настройки проекта">{aside}</SettingsDialog>}
|
actions={
|
||||||
|
<>
|
||||||
|
<SettingsDialog title="Новая стори" trigger={<><Plus />Стори</>}>
|
||||||
|
{newTask}
|
||||||
|
</SettingsDialog>
|
||||||
|
<SettingsDialog title="Настройки проекта">{aside}</SettingsDialog>
|
||||||
|
</>
|
||||||
|
}
|
||||||
crumbs={<a href="/projects" className="text-muted-foreground hover:text-foreground">Проекты</a>}
|
crumbs={<a href="/projects" className="text-muted-foreground hover:text-foreground">Проекты</a>}
|
||||||
title={
|
title={
|
||||||
<>
|
<>
|
||||||
@ -186,109 +231,95 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr
|
|||||||
<a href={repo.url} className="text-primary">{repo.fullName}</a> · {repoVisibilityLabel(repo.private)}
|
<a href={repo.url} className="text-primary">{repo.fullName}</a> · {repoVisibilityLabel(repo.private)}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
|
||||||
<Board cards={cards} back={back} />
|
<nav aria-label="Разделы проекта" className="-mt-2 mb-4 flex gap-1 overflow-x-auto border-b">
|
||||||
|
{TABS.map((t) => (
|
||||||
<div className="mt-3 grid gap-2 md:grid-cols-2">
|
<a
|
||||||
{groups.map(({ goal }) => (
|
key={t.id}
|
||||||
<Disclosure
|
href={t.id === "board" ? `/p/${p.key}` : `/p/${p.key}?tab=${t.id}`}
|
||||||
key={goal?.id ?? "none"}
|
aria-current={tab === t.id ? "page" : undefined}
|
||||||
summary={
|
className={cn(
|
||||||
<span className="flex min-w-0 items-center gap-1.5">
|
"-mb-px flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm whitespace-nowrap text-muted-foreground hover:text-foreground hover:no-underline",
|
||||||
<Plus className="size-3.5 text-primary" />
|
tab === t.id ? "border-primary text-foreground" : "border-transparent",
|
||||||
Задача
|
)}
|
||||||
<span className="truncate text-muted-foreground">{goal ? `· ◎ ${goal.title}` : "без цели"}</span>
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<form action={addTask} className="flex flex-col gap-2">
|
{t.label}
|
||||||
<Hidden fields={{ projectId: p.id, back, goalId: goal?.id }} />
|
{!!tabCount[t.id] && <span className="rounded-full bg-muted px-1.5 font-mono text-[11px] tabular-nums">{tabCount[t.id]}</span>}
|
||||||
<Input name="title" required placeholder="Что сделать" aria-label="Название задачи" />
|
</a>
|
||||||
<Textarea name="description" rows={3} placeholder="Описание: контекст, критерии готовности" aria-label="Описание задачи" />
|
|
||||||
<Button variant="default" size="sm" className="self-start">Создать задачу</Button>
|
|
||||||
</form>
|
|
||||||
</Disclosure>
|
|
||||||
))}
|
))}
|
||||||
<Disclosure
|
</nav>
|
||||||
summary={
|
|
||||||
<span className="flex items-center gap-1.5">
|
|
||||||
<Target className="size-3.5 text-primary" />
|
|
||||||
Цель
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<form action={addGoal} className="flex flex-col gap-2">
|
|
||||||
<Hidden fields={{ projectId: p.id, back }} />
|
|
||||||
<Input name="title" required placeholder="Верхнеуровневая цель" aria-label="Название цели" />
|
|
||||||
<Textarea name="description" rows={3} placeholder="Зачем и какой результат" aria-label="Описание цели" />
|
|
||||||
<Button variant="default" size="sm" className="self-start">Создать цель</Button>
|
|
||||||
</form>
|
|
||||||
</Disclosure>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Section title="Релизы">
|
{tab === "board" && <Board cards={cards} back={back} />}
|
||||||
<div className="flex flex-col gap-2 sm:flex-row">
|
|
||||||
<EnvLine name="staging" r={current.staging} />
|
{tab === "releases" && (
|
||||||
<EnvLine name="прод" r={current.prod} />
|
<Section title="Релизы">
|
||||||
</div>
|
<div className="flex flex-col gap-2 sm:flex-row">
|
||||||
{prodCandidate && prodCandidate !== current.prod?.sha && (
|
<EnvLine name="staging" r={current.staging} />
|
||||||
<form action={deployProdAction}>
|
<EnvLine name="прод" r={current.prod} />
|
||||||
<Hidden fields={{ projectKey: p.key, back }} />
|
|
||||||
<Button variant="default" size="sm">
|
|
||||||
<Rocket />
|
|
||||||
Выкатить в прод {prodCandidate.slice(0, 7)}
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
)}
|
|
||||||
{releases.length === 0 ? (
|
|
||||||
<Empty>
|
|
||||||
Деплоев ещё не было. Настройка — <span className="font-mono">deploy</span> в .peppa/project.json (см. «Помощь → CI/CD»).
|
|
||||||
</Empty>
|
|
||||||
) : (
|
|
||||||
<div className="overflow-x-auto rounded-lg border">
|
|
||||||
<table className="w-full border-collapse text-sm">
|
|
||||||
<tbody>
|
|
||||||
{releases.map((r) => (
|
|
||||||
<tr key={r.id} className="border-b last:border-0">
|
|
||||||
<td className="px-3 py-2 whitespace-nowrap">
|
|
||||||
{r.env}
|
|
||||||
{r.prNumber ? ` #${r.prNumber}` : ""}
|
|
||||||
</td>
|
|
||||||
<td className="px-3 py-2 font-mono">{r.sha.slice(0, 7)}</td>
|
|
||||||
<td className="px-3 py-2">
|
|
||||||
<Badge variant={RELEASE_STATUS[r.status].tone}>{RELEASE_STATUS[r.status].label}</Badge>
|
|
||||||
{r.reason && <span className="ml-1.5 text-muted-foreground">{r.reason}</span>}
|
|
||||||
</td>
|
|
||||||
<td className="px-3 py-2">
|
|
||||||
{r.tasks.map((t) => (
|
|
||||||
<Key key={t} href={`/t/${t}`} className="mr-1.5">{t}</Key>
|
|
||||||
))}
|
|
||||||
</td>
|
|
||||||
<td className="px-3 py-2 text-right whitespace-nowrap text-muted-foreground">
|
|
||||||
{r.deployedBy} · {r.createdAt.toLocaleString("ru-RU", { dateStyle: "short", timeStyle: "short" })}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
{prodCandidate && prodCandidate !== current.prod?.sha && (
|
||||||
</Section>
|
<form action={deployProdAction}>
|
||||||
|
<Hidden fields={{ projectKey: p.key, back }} />
|
||||||
|
<Button variant="default" size="sm">
|
||||||
|
<Rocket />
|
||||||
|
Выкатить в прод {prodCandidate.slice(0, 7)}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
{releases.length === 0 ? (
|
||||||
|
<Empty>
|
||||||
|
Деплоев ещё не было. Настройка — <span className="font-mono">deploy</span> в .peppa/project.json (см. «Помощь → CI/CD»).
|
||||||
|
</Empty>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto rounded-lg border">
|
||||||
|
<table className="w-full border-collapse text-sm">
|
||||||
|
<tbody>
|
||||||
|
{releases.map((r) => (
|
||||||
|
<tr key={r.id} className="border-b last:border-0">
|
||||||
|
<td className="px-3 py-2 whitespace-nowrap">
|
||||||
|
{r.env}
|
||||||
|
{r.prNumber ? ` #${r.prNumber}` : ""}
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-2 font-mono">{r.sha.slice(0, 7)}</td>
|
||||||
|
<td className="px-3 py-2">
|
||||||
|
<Badge variant={RELEASE_STATUS[r.status].tone}>{RELEASE_STATUS[r.status].label}</Badge>
|
||||||
|
{r.reason && <span className="ml-1.5 text-muted-foreground">{r.reason}</span>}
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-2">
|
||||||
|
{r.tasks.map((t) => (
|
||||||
|
<Key key={t} href={`/t/${t}`} className="mr-1.5">{t}</Key>
|
||||||
|
))}
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-2 text-right whitespace-nowrap text-muted-foreground">
|
||||||
|
{r.deployedBy} · {r.createdAt.toLocaleString("ru-RU", { dateStyle: "short", timeStyle: "short" })}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Section>
|
||||||
|
)}
|
||||||
|
|
||||||
<IncidentsSection
|
{tab === "bugs" && (
|
||||||
projectId={p.id}
|
<IncidentsSection
|
||||||
projectKey={p.key}
|
projectId={p.id}
|
||||||
back={back}
|
projectKey={p.key}
|
||||||
isOwner={isOwner}
|
back={back}
|
||||||
settings={incidentSettings}
|
isOwner={isOwner}
|
||||||
sources={sources}
|
settings={incidentSettings}
|
||||||
incidents={incidents}
|
sources={sources}
|
||||||
taskKeys={new Map(tasks.map((t) => [t.id, `${p.key}-${t.number}`]))}
|
incidents={incidents}
|
||||||
webhookUrl={incidentSettings ? `${bugsinkWebhookBase()}/api/hooks/bugsink/${incidentSettings.hookSecret}` : null}
|
taskKeys={new Map(tasks.map((t) => [t.id, `${p.key}-${t.number}`]))}
|
||||||
/>
|
webhookUrl={incidentSettings ? `${bugsinkWebhookBase()}/api/hooks/bugsink/${incidentSettings.hookSecret}` : null}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<Section title="Сессии">
|
{tab === "sessions" && (
|
||||||
{sessions.length === 0 ? <Empty>Сессий ещё не было.</Empty> : sessions.map((s) => <SessionCard key={s.id} s={s} back={back} showTitle />)}
|
<Section title="Сессии">
|
||||||
</Section>
|
{sessions.length === 0 ? <Empty>Сессий ещё не было.</Empty> : sessions.map((s) => <SessionCard key={s.id} s={s} back={back} showTitle />)}
|
||||||
|
</Section>
|
||||||
|
)}
|
||||||
</Workspace>
|
</Workspace>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,14 +4,24 @@ import { useRef, type ReactNode } from "react";
|
|||||||
import { Ellipsis, X } from "lucide-react";
|
import { Ellipsis, X } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
/** "⋯" button that opens a side dialog (native <dialog>) with page settings rendered on the server. */
|
/**
|
||||||
export function SettingsDialog({ title, children }: { title: string; children: ReactNode }) {
|
* Button that opens a side dialog (native <dialog>) with content rendered on the server.
|
||||||
|
* Default trigger is "⋯" (page settings); pass `trigger` for a labelled button such as "+ Задача".
|
||||||
|
*/
|
||||||
|
export function SettingsDialog({ title, trigger, children }: { title: string; trigger?: ReactNode; children: ReactNode }) {
|
||||||
const ref = useRef<HTMLDialogElement>(null);
|
const ref = useRef<HTMLDialogElement>(null);
|
||||||
|
const open = () => ref.current?.showModal();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button variant="ghost" size="icon" aria-label={title} title={title} onClick={() => ref.current?.showModal()}>
|
{trigger ? (
|
||||||
<Ellipsis />
|
<Button size="sm" onClick={open}>
|
||||||
</Button>
|
{trigger}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button variant="ghost" size="icon" aria-label={title} title={title} onClick={open}>
|
||||||
|
<Ellipsis />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<dialog
|
<dialog
|
||||||
ref={ref}
|
ref={ref}
|
||||||
aria-label={title}
|
aria-label={title}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user