// R-P8b (P8 configurable Kanban) Interim-UI (AD-28) — pipeline-scoped board // `/projects/pipelines/:id`. Same KanbanBoardVM + screen as `/projects`, but the // pipeline is fixed by the URL and the switcher navigates between pipeline // routes. Final Subframe optics = tracked design-nachzug. import { CatalogError, foundationErrors } from "@hivegrid/foundation"; import { redirect, useActionData, useLoaderData, useNavigate, useNavigation, useSubmit, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router"; import { useTranslation } from "react-i18next"; import type { PipelineHandoverVM } from "@hivegrid/view-models"; import { EmptyState } from "~/ui/components/EmptyState"; import { getTranslations } from "~/locale/i18next.server"; import { loadProjectContext, PROJECT_READ_PERMISSIONS, projectActionErrorResponse, requireProjectPermission, requireProjectView } from "~/utils/integrations/projects/projectAccess.server"; import { PROJECTS_MODULE_KEY, projectBoardSettingsPath, projectDetailPath, projectPipelinePath } from "~/utils/integrations/projects/projectRoutePaths"; import { handleKanbanIntent, kanbanIntentPermission, loadKanbanData, parseBoardFacetParams, type KanbanLoaderData } from "~/utils/integrations/projects/projectBoardRoute.server"; import { PipelineKanbanPage } from "~/components/screens/projects/PipelineKanbanPage"; import { useBoardLiveUpdates } from "~/utils/stream/useBoardLiveUpdates"; import { useBoardFacetParams } from "~/hooks/use-board-facet-params"; export async function loader({ request, params }: LoaderFunctionArgs) { const ctx = await requireProjectView({ request, params }, PROJECT_READ_PERMISSIONS); const { locale } = await getTranslations(request); if (!params.pipelineId) throw new CatalogError(foundationErrors.notFound); const url = new URL(request.url); const data = await loadKanbanData({ tenantSlug: params.tenant!, tenantId: ctx.tenantId, ctx, pipelineId: params.pipelineId, onlyMine: url.searchParams.get("onlyMine") === "1", includeDemoData: url.searchParams.get("demo") === "show", q: url.searchParams.get("q"), facets: parseBoardFacetParams(url.searchParams), locale, }); return Response.json(data satisfies KanbanLoaderData); } export async function action({ request, params }: ActionFunctionArgs) { const ctx = await loadProjectContext({ request, params, requireModule: true }); const form = await request.formData(); const intent = form.get("_action")?.toString() ?? null; try { requireProjectPermission(ctx, kanbanIntentPermission(intent)); const { createdProjectId, handover } = await handleKanbanIntent({ intent, form, tenantId: ctx.tenantId, ctx }); if (createdProjectId) { return redirect(`${projectDetailPath(params.tenant!, createdProjectId)}?toast=${encodeURIComponent("projects.toast.projectCreated")}`); } // `handover` is non-null only when the move just put a card into a stage // that offers M04 — the screen opens the dialog on it. return Response.json({ ok: true, handover: handover ?? null }); } catch (error) { return projectActionErrorResponse(error); } } export default function ProjectPipelineRoute() { const { t } = useTranslation(); const data = useLoaderData(); const navigate = useNavigate(); const { setParam, toggleFacet, removeChip, setPeriodRange, resetFilters } = useBoardFacetParams(); const submit = useSubmit(); const navigation = useNavigation(); const actionData = useActionData<{ error?: string; handover?: PipelineHandoverVM | null }>(); const vmData = data.vm.status === "ready" ? data.vm.data : null; // Live board: subscribe to the pipeline SSE stream and revalidate on real // change-events (route owns data/revalidation; the screen stays pure). useBoardLiveUpdates(vmData?.sseHref, { paused: navigation.state !== "idle" }); function post(intent: string, fields: Record) { const fd = new FormData(); fd.set("_action", intent); for (const [key, value] of Object.entries(fields)) fd.set(key, value); submit(fd, { method: "post" }); } if (!vmData) { return (
); } return (
navigate(detailHref), onHandover: (projectId, fromPipelineId, selection) => post("handoverProject", { projectId, fromPipelineId, selection: JSON.stringify(selection) }), onShowList: () => navigate(data.listHref), // Board settings of THIS board (S04), not the board table — the page // already knows which board it shows. onManageBoard: () => navigate(projectBoardSettingsPath(data.tenantSlug, vmData.pipelineId)), onSwitchPipeline: (pipelineId) => navigate(projectPipelinePath(data.tenantSlug, pipelineId)), onToggleOnlyMine: (checked) => setParam("onlyMine", checked ? "1" : ""), onSearch: (q) => setParam("q", q), onToggleFacet: toggleFacet, onRemoveChip: removeChip, onResetFilters: resetFilters, onPeriodRangeChange: setPeriodRange, onToggleDemo: (show) => setParam("demo", show ? "show" : ""), onMove: (projectId, targetStageId, lostReasonId, notiz) => post("moveStage", { projectId, targetStageId, ...(lostReasonId ? { lostReasonId } : {}), ...(notiz ? { notiz } : {}) }), onBulkMove: (projectIds, targetStageId) => post("bulkMoveStage", { projectIds: projectIds.join(","), targetStageId }), onCreateProject: (fields) => post("createProject", fields), onDuplicate: (projectId) => post("duplicateProject", { projectId }), onArchive: (projectId) => post("archiveProject", { projectId }), onUndoStage: (projectId) => post("undoStage", { projectId }), onRedoStage: (projectId) => post("redoStage", { projectId }), onMoveToPipeline: (projectId, targetPipelineId) => post("moveToPipeline", { projectId, targetPipelineId }), }} />
); } export const handle = { moduleKey: PROJECTS_MODULE_KEY };