From 3b86c00768d00dab56debf0cd175421da38c679c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=81=D0=B5=D0=BB=D1=8C?= Date: Sat, 14 Nov 2026 05:54:05 +0500 Subject: [PATCH] =?UTF-8?q?PEP-34/42:=20web=20=E2=80=94=20board=20drag=20o?= =?UTF-8?q?rder,=20collapsed=20Done,=20epic=20progress,=20archive,=20depen?= =?UTF-8?q?dencies,=20plan=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- apps/web/app/(app)/board-actions.ts | 122 +++++++++++ apps/web/app/(app)/p/[key]/page.tsx | 24 ++- .../app/(app)/p/[key]/plan/[epic]/page.tsx | 102 +++++++++ apps/web/app/(app)/p/[key]/tabs.tsx | 29 ++- apps/web/app/(app)/t/[key]/page.tsx | 55 ++++- apps/web/components/Board.tsx | 201 +++++++++++++----- apps/web/components/PendingButton.tsx | 14 ++ apps/web/lib/queries.ts | 3 +- 8 files changed, 478 insertions(+), 72 deletions(-) create mode 100644 apps/web/app/(app)/board-actions.ts create mode 100644 apps/web/app/(app)/p/[key]/plan/[epic]/page.tsx create mode 100644 apps/web/components/PendingButton.tsx diff --git a/apps/web/app/(app)/board-actions.ts b/apps/web/app/(app)/board-actions.ts new file mode 100644 index 00000000..7556b808 --- /dev/null +++ b/apps/web/app/(app)/board-actions.ts @@ -0,0 +1,122 @@ +"use server"; +// Board order and archive (PEP-34), story dependencies and the epic planner (PEP-42). +// Thin wrappers over core/runner with the owner/member check, like actions.ts. + +import { getEpic, PeppaError, projectForUser, resolveTask, setDependencies, type TaskRef } from "@peppa/core"; +import { applyPlan, archiveTask, discardPlanDraft, parseDepsInput, planEpic, reorderBoardTask, type PlanDep, type PlannedStory } from "@peppa/runner"; +import { revalidatePath } from "next/cache"; +import { redirect } from "next/navigation"; +import { requireUser } from "@/lib/auth"; +import { db } from "@/lib/db"; + +const str = (f: FormData, k: string) => String(f.get(k) ?? "").trim(); + +async function attempt(f: FormData, fn: () => Promise): Promise { + let target = str(f, "back") || "/"; + try { + target = (await fn()) || target; + } catch (e) { + const msg = e instanceof PeppaError ? e.message : `Ошибка: ${(e as Error).message}`; + const [path, query] = target.split("?"); + const params = new URLSearchParams(query); + params.set("error", msg.slice(0, 300)); + target = `${path}?${params}`; + } + revalidatePath("/", "layout"); + redirect(target); +} + +async function ownedTask(userId: number, key: string): Promise { + const ref = await resolveTask(db, key); + await projectForUser(db, userId, ref.project.id); + return ref; +} + +/** Drag within a column (before/after another card) or the card menu (top/bottom). */ +export async function reorderTaskCard(f: FormData) { + const user = await requireUser(); + await attempt(f, async () => { + const ref = await ownedTask(user.id, str(f, "taskKey")); + const to = str(f, "to"); + if (to === "top" || to === "bottom") await reorderBoardTask(db, ref, { to }); + else if (to === "before" || to === "after") await reorderBoardTask(db, ref, { to, other: await ownedTask(user.id, str(f, "other")) }); + else throw new PeppaError("Неизвестное место"); + }); +} + +/** Called from the board without a page reload (drag and drop); errors are returned. */ +export async function reorderTaskInline(taskKey: string, to: "top" | "bottom" | "before" | "after", other?: string): Promise { + const user = await requireUser(); + try { + const ref = await ownedTask(user.id, taskKey); + if (to === "before" || to === "after") await reorderBoardTask(db, ref, { to, other: await ownedTask(user.id, other ?? "") }); + else await reorderBoardTask(db, ref, { to }); + revalidatePath("/", "layout"); + return null; + } catch (e) { + return e instanceof PeppaError ? e.message : (e as Error).message; + } +} + +export async function archiveTaskAction(f: FormData) { + const user = await requireUser(); + await attempt(f, async () => { + const ref = await ownedTask(user.id, str(f, "taskKey")); + await archiveTask(db, ref, str(f, "archived") !== "0"); + }); +} + +export async function setDependenciesAction(f: FormData) { + const user = await requireUser(); + await attempt(f, async () => { + const ref = await ownedTask(user.id, str(f, "taskKey")); + const keys = str(f, "blockedBy").split(/[\s,;]+/).filter(Boolean); + // "remove" drops one key from the current list; otherwise the field adds to it. + const current = (f.getAll("current") as string[]).map(String); + const remove = str(f, "remove"); + await setDependencies(db, ref, remove ? current.filter((k) => k !== remove) : [...current, ...keys]); + }); +} + +export async function planEpicAction(f: FormData) { + const user = await requireUser(); + await attempt(f, async () => { + const p = await projectForUser(db, user.id, Number(str(f, "projectId"))); + const epic = await getEpic(db, p.id, Number(str(f, "epicId"))); + const r = await planEpic(db, p, epic.id, { wishes: str(f, "wishes") || null, by: user.login }); + if (!r.ok) throw new PeppaError(`Планировщик: ${r.error}`); + }); +} + +export async function applyPlanAction(f: FormData) { + const user = await requireUser(); + await attempt(f, async () => { + const p = await projectForUser(db, user.id, Number(str(f, "projectId"))); + const epicId = Number(str(f, "epicId")); + const n = Number(str(f, "count")); + // Plan numbers in the form refer to the full draft; renumber them for the kept stories. + const kept: number[] = []; + for (let i = 1; i <= n; i++) if (f.get(`keep_${i}`)) kept.push(i); + if (!kept.length) throw new PeppaError("Не выбрано ни одной стори"); + const renum = new Map(kept.map((orig, i) => [orig, i + 1])); + const stories: PlannedStory[] = kept.map((i) => { + const deps = parseDepsInput(str(f, `deps_${i}`)).map((d): PlanDep => { + if (typeof d !== "number") return d; + if (!renum.has(d)) throw new PeppaError(`Стори ${i} зависит от №${d}, которую вы сняли — уберите зависимость или оставьте стори`); + return renum.get(d)!; + }); + return { title: str(f, `title_${i}`), description: str(f, `description_${i}`), dependsOn: deps }; + }); + await applyPlan(db, p, epicId, stories); + return `/p/${p.key}?epic=${epicId}`; + }); +} + +export async function discardPlanAction(f: FormData) { + const user = await requireUser(); + await attempt(f, async () => { + const p = await projectForUser(db, user.id, Number(str(f, "projectId"))); + const epic = await getEpic(db, p.id, Number(str(f, "epicId"))); + await discardPlanDraft(db, epic.id); + }); +} diff --git a/apps/web/app/(app)/p/[key]/page.tsx b/apps/web/app/(app)/p/[key]/page.tsx index c2ac9c13..c9acaee2 100644 --- a/apps/web/app/(app)/p/[key]/page.tsx +++ b/apps/web/app/(app)/p/[key]/page.tsx @@ -1,7 +1,7 @@ import { notFound } from "next/navigation"; import { ExternalLink, Plus, Rocket } from "lucide-react"; import { columnOf, currentReleases, describeRepo, isPlatform, listReleases, bugsinkWebhookBase, openPulls, platformReleaseCandidate, platformReleaseOffers, repoOverview, type Release } from "@peppa/runner"; -import { taskProgress, getAutonomy, getIncidentSettings, getReviewSettings, isSuperadmin, listEpics, listErrorSources, listIncidents, listMembers, listPools, listSpecs, projectPool, repoAudience, repoVisibilityLabel } from "@peppa/core"; +import { blockedLabel, blockersMap, epicProgress, progressLabel, taskProgress, getAutonomy, getIncidentSettings, getReviewSettings, isSuperadmin, listEpics, listErrorSources, listIncidents, listMembers, listPools, listSpecs, projectPool, repoAudience, repoVisibilityLabel } from "@peppa/core"; import { LiveRefresh } from "@/components/LiveRefresh"; import { PanelSection } from "@/components/ActivityAside"; import { Board, type Card } from "@/components/Board"; @@ -19,7 +19,7 @@ import { cn } from "@/lib/utils"; import { db } from "@/lib/db"; import { board, projectForUserByKey, projectSessions } from "@/lib/queries"; import { addProjectMember, addTask, deployProdAction, grantRepoAccessToMembers, removeProjectMember, saveReviewSettingsAction, setProjectVisibilityAction } from "../../actions"; -import { CodeTab, EpicsPanel, PullsTab, SpecsTab } from "./tabs"; +import { CodeTab, EpicsPanel, ProgressBar, PullsTab, SpecsTab } from "./tabs"; import { setProjectPoolAction } from "../../subscriptions/actions"; const RELEASE_STATUS: Record = { @@ -67,7 +67,7 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr const tab = TABS.find((t) => t.id === tabParam)?.id ?? "board"; const p = await projectForUserByKey(user.id, key).catch(() => null); if (!p) notFound(); - const [{ tasks }, epics, sessions, team, repo, incidentSettings, sources, incidents, releases, current, reviewer] = await Promise.all([ + const [{ tasks }, epics, sessions, team, repo, incidentSettings, sources, incidents, releases, current, reviewer, progress, deps] = await Promise.all([ board(p.id), listEpics(db, p.id), projectSessions(p.id), @@ -79,6 +79,8 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr listReleases(db, p.id, 15), currentReleases(db, p.id), getReviewSettings(db, p.id), + epicProgress(db, p.id), + blockersMap(db, p.id), ]); // Peppa itself has no staging: its prod candidate is the newest green main (PEP-18). const prodCandidate = isPlatform(p) ? ((await platformReleaseOffers(db)) ? await platformReleaseCandidate(db, p) : null) : (current.staging?.sha ?? null); @@ -108,6 +110,7 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr epic: t.goalId ? (epicTitle.get(t.goalId) ?? null) : null, // PEP-33: tasks.md progress of stories in work. progress: pr && { done: pr.done, total: pr.total, current: pr.current }, + blocked: t.status === "backlog" ? blockedLabel(deps.get(t.id)) : null, }; }); // Gitea and the working copy are read only for the open tab. @@ -159,7 +162,7 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr - + @@ -347,12 +350,23 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr key={e.id} href={boardHref(e.id || undefined)} aria-current={active ? "page" : undefined} - className={cn("rounded-full border px-2.5 py-0.5 text-xs hover:no-underline", active ? "border-primary bg-primary/12 text-primary" : "text-muted-foreground hover:text-foreground")} + className={cn("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs hover:no-underline", active ? "border-primary bg-primary/12 text-primary" : "text-muted-foreground hover:text-foreground")} > {e.title} + {e.id > 0 && ( + + + {progressLabel(progress.get(e.id))} + + )} ); })} + {epicFilter && ( + + Спланировать стори эпика → + + )} )} diff --git a/apps/web/app/(app)/p/[key]/plan/[epic]/page.tsx b/apps/web/app/(app)/p/[key]/plan/[epic]/page.tsx new file mode 100644 index 00000000..9a85053a --- /dev/null +++ b/apps/web/app/(app)/p/[key]/plan/[epic]/page.tsx @@ -0,0 +1,102 @@ +// PEP-42: plan an epic — the planner proposes stories with dependencies; the PM edits and approves. +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { Sparkles } from "lucide-react"; +import { getEpic, listTasks } from "@peppa/core"; +import { getPlanDraft } from "@peppa/runner"; +import { Hidden } from "@/components/cards"; +import { Empty, Flash, PageHeader, Section } from "@/components/common"; +import { PendingButton } from "@/components/PendingButton"; +import { Button } from "@/components/ui/button"; +import { Input, Textarea } from "@/components/ui/input"; +import { Workspace } from "@/components/Workspace"; +import { requireUser } from "@/lib/auth"; +import { db } from "@/lib/db"; +import { projectForUserByKey } from "@/lib/queries"; +import { applyPlanAction, discardPlanAction, planEpicAction } from "../../../../board-actions"; + +export default async function PlanEpicPage({ params, searchParams }: { params: Promise<{ key: string; epic: string }>; searchParams: Promise<{ error?: string }> }) { + const user = await requireUser(); + const { key, epic: epicParam } = await params; + const { error } = await searchParams; + const p = await projectForUserByKey(user.id, key).catch(() => null); + if (!p) notFound(); + const epic = await getEpic(db, p.id, Number(epicParam)).catch(() => null); + if (!epic) notFound(); + const [draft, existing] = await Promise.all([getPlanDraft(db, epic.id), listTasks(db, { projectId: p.id, goalId: epic.id })]); + const back = `/p/${p.key}/plan/${epic.id}`; + + return ( + + + + {p.name} + / + эпик «{epic.title}» + + } + title={<>Спланировать эпик «{epic.title}»} + > + Планировщик (короткая сессия Claude на подписке пула проекта) предложит стори с критериями готовности и зависимостями. Ничего не создаётся, пока вы не утвердите план. + + +
+
{epic.description || Без описания — опишите эпик в «⋯ Настройки проекта → Эпики», так план будет точнее.}
+ {existing.length > 0 && ( +

+ Уже есть стори: {existing.map((t) => t.key).join(", ")} — планировщик их не повторит и может от них зависеть. +

+ )} +
+ +