// R-P8b (P8 configurable Kanban) Interim-UI (AD-28) — pipeline board screen // (D-KANBAN), composed from ~/ui (ProjectCard + Dialog) on top of the shared // SortableKanbanBoard (dnd-kit). Pure/presentational: renders the server-built // KanbanBoardData and turns each action into a typed callback the route POSTs. // Primary stage change = drag&drop (mouse + keyboard via the board's drag // handle). A drop into a "gewonnen" stage opens a confirm dialog; "verloren" // opens a mandatory lost-reason dialog — so DnD still routes through requestMove // and never submits won/lost blindly. Live SSE stays a tracked design-nachzug // (sseHref kept on the root as a hint). No useLoaderData/useFetcher, no server // imports. import { useMemo, useState, type ReactNode } from "react"; import { useTranslation } from "react-i18next"; import { FeatherAlertCircle, FeatherArchive, FeatherArrowLeftRight, FeatherArrowRight, FeatherCheck, FeatherChevronDown, FeatherChevronsLeft, FeatherColumns, FeatherCommand, FeatherCopy, FeatherExternalLink, FeatherKanbanSquare, FeatherList, FeatherMoreVertical, FeatherPlus, FeatherRotateCcw, FeatherRedo2, FeatherSearchX, FeatherSettings2, FeatherTrendingDown, FeatherTrendingUp, FeatherUndo2, FeatherX, } from "@subframe/core"; import * as SubframeCore from "@subframe/core"; import type { BoardFacet, BoardFacetChip, BoardFacetsVM, KanbanBoardData, PipelineHandoverKind, PipelineHandoverVM } from "@hivegrid/view-models"; import { BoardFilterBar } from "./BoardFilterBar"; import { PipelineHandoverDialog } from "./dialogs/PipelineHandoverDialog"; import { PAGE_HEADER_ICON_CLASS, PageHeader, PageShell } from "../shared/PageShell"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Checkbox } from "~/ui/components/Checkbox"; import { BadgeShortcut } from "~/ui/components/BadgeShortcut"; import { ContextMenu } from "~/ui/components/ContextMenu"; import { Alert } from "~/ui/components/Alert"; import { Dialog } from "~/ui/components/Dialog"; import { IconWithBackground } from "~/ui/components/IconWithBackground"; import { TextArea } from "~/ui/components/TextArea"; import { DropdownMenu } from "~/ui/components/DropdownMenu"; import { DropdownMenuMultiSelect } from "~/ui/components/DropdownMenuMultiSelect"; import { FilterBar } from "~/ui/components/FilterBar"; import { IconButton } from "~/ui/components/IconButton"; import { Avatar } from "~/ui/components/Avatar"; import { ProjectCard } from "~/ui/components/ProjectCard"; import { Tag_Label } from "~/ui/components/Tag_Label"; import { Select } from "~/ui/components/Select"; import { TextInput } from "~/ui/components/TextInput"; import { ToggleGroup } from "~/ui/components/ToggleGroup"; import { useLocaleFormatters } from "~/locale/format"; import { SortableKanbanBoard, type SortableKanbanColumn } from "~/components/ui/kanban/SortableKanbanBoard"; import { useRecommendedSidebarCollapse } from "~/components/app/AppShellSidebarContext"; import { AppLink } from "~/components/app/AppLink"; import { tagTone } from "./tagTone"; /** Day+month only, matching the export's "14.07." on the card date range. */ const SHORT_DATE: Intl.DateTimeFormatOptions = { day: "2-digit", month: "2-digit" }; /** Project priority → ProjectCard colour variant. */ const PRIORITY_VARIANT: Record = { niedrig: "low", normal: "none", hoch: "high", dringend: "critical", }; /** Up to two initials for the assignee avatar (the card has no photo source). */ function initialsOf(label: string): string { return label .split(/\s+/u) .filter(Boolean) .slice(0, 2) .map((part) => part[0]!.toUpperCase()) .join(""); } export type PipelineKanbanActions = { onShowList: () => void; onOpenProject: (detailHref: string) => void; /** Board settings — reachable from the card context menu, not from the header. */ onManageBoard: () => void; onSwitchPipeline: (pipelineId: string) => void; onToggleOnlyMine: (checked: boolean) => void; onSearch: (q: string) => void; /** S01 facet option toggled on/off (assignee, customer type, period, value). */ onToggleFacet: (facet: BoardFacet["key"], value: string) => void; /** One active-filter chip removed. */ onRemoveChip: (chip: BoardFacetChip) => void; /** Clear search, only-mine and every facet in a single navigation. */ onResetFilters: () => void; /** Bounds of the custom period option (ISO yyyy-mm-dd, "" = unset). */ onPeriodRangeChange: (from: string, to: string) => void; onToggleDemo: (show: boolean) => void; onMove: (projectId: string, targetStageId: string, lostReasonId?: string, notiz?: string) => void; onBulkMove: (projectIds: string[], targetStageId: string) => void; onCreateProject: (fields: { projektname: string; potenziellerAuftragswert: string }) => void; /** Optional: context-menu duplicate. Item only renders when callback + write permission exist. */ onDuplicate?: (projectId: string) => void; /** Optional: M03 "Rückgängig" — undo the last won/lost move inside its window. */ onUndoStage?: (projectId: string) => void; /** Optional: M03 "Wiederholen" — re-apply the move an undo reverted. */ onRedoStage?: (projectId: string) => void; /** Optional: M03 "Board wechseln" — move the project into another board. */ onMoveToPipeline?: (projectId: string, targetPipelineId: string) => void; /** Optional: context-menu archive (behind a confirm dialog). Item only renders when callback + delete permission exist. */ onArchive?: (projectId: string) => void; /** M04 confirmed — commit the handover with the picked companion records. */ onHandover?: (projectId: string, fromPipelineId: string, selection: readonly { kind: PipelineHandoverKind; sourceId: string }[]) => void; }; export type PipelineKanbanPageProps = { data: KanbanBoardData; onlyMine: boolean; q: string; /** S01 filter bar: facet dropdowns + active-filter chips. */ facets: BoardFacetsVM; /** Bounds of the custom period option (ISO yyyy-mm-dd, "" = unset). */ periodFrom: string; periodTo: string; includeDemoData: boolean; /** Demo-data toggle is a staging/dev-only affordance (env-gated by the loader). */ showDemoToggle: boolean; submitting: boolean; errorKey?: string | null; /** * M04, handed back by the last stage move: non-null exactly when the card * landed in a stage that offers a handover. D-P8 makes the move the trigger, * so the board opens the dialog itself instead of waiting for someone to * open the project. */ handover?: PipelineHandoverVM | null; language?: string; actions: PipelineKanbanActions; }; type PendingMove = { projectId: string; stageId: string; kind: "gewonnen" | "verloren" }; type BoardCard = KanbanBoardData["columns"][number]["cards"][number]; // Pseudo-card injected into empty columns so each of them renders a dashed, // stage-aware placeholder (S01a). Placeholders never get a drag handle and are // filtered out of every move path. type ColumnPlaceholder = { readonly id: string; readonly kind: "column-placeholder"; readonly stageId: string; readonly stageName: string }; type BoardEntry = BoardCard | ColumnPlaceholder; const PLACEHOLDER_PREFIX = "column-placeholder:"; function isPlaceholder(entry: BoardEntry): entry is ColumnPlaceholder { return "kind" in entry && entry.kind === "column-placeholder"; } const mutedText = "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary"; export function PipelineKanbanPage(props: PipelineKanbanPageProps) { const { t } = useTranslation(); const formatters = useLocaleFormatters(); const { data } = props; useRecommendedSidebarCollapse(`projects:${data.pipelineId}`); const [selected, setSelected] = useState>(new Set()); const [bulkStage, setBulkStage] = useState(data.openStages[0]?.id ?? ""); const [pendingMove, setPendingMove] = useState(null); // M01 starts with no preselected reason: the dialog demands a deliberate // choice, and preselecting the first one would let a blind confirm record a // reason the user never picked. const [lostReasonId, setLostReasonId] = useState(""); const [lostNote, setLostNote] = useState(""); const [lostReasonMissing, setLostReasonMissing] = useState(false); const [createOpen, setCreateOpen] = useState(false); // Archive goes through an explicit confirm dialog — never a one-click destroy. const [pendingArchive, setPendingArchive] = useState(null); const [draft, setDraft] = useState({ projektname: "", potenziellerAuftragswert: "" }); // Bumped whenever an optimistic DnD drop must be reverted (won/lost dialog // cancelled) so SortableKanbanBoard snaps the card back to the server order. const [resetToken, setResetToken] = useState(0); // Which columns this person wants on screen. Only the deliberate deviations // are stored, so the default below keeps applying to every other stage — and // to the stages of another board after a switch. const [columnVisibility, setColumnVisibility] = useState>>({}); // Which handover the user closed without deciding. Keyed by project so the // next move that offers one opens the dialog again rather than staying shut. const [handoverDismissed, setHandoverDismissed] = useState(null); // The board shows the board: every configured stage is on screen until this // person hides one. Hiding is theirs to choose, not ours to preselect. function isColumnVisible(column: KanbanBoardData["columns"][number]): boolean { return columnVisibility[column.stageId] ?? true; } const visibleColumns = data.columns.filter(isColumnVisible); // Shown on the picker button, so a missing column is never a silent one. const hiddenColumnCount = data.columns.length - visibleColumns.length; const stageKindById = useMemo(() => new Map(data.columns.map((column) => [column.stageId, column.stageKind])), [data.columns]); // Owning stage per card — used by the context menu to offer only the OTHER // stages as move targets. const stageIdByCardId = useMemo(() => { const map = new Map(); for (const column of data.columns) for (const card of column.cards) map.set(card.id, column.stageId); return map; }, [data.columns]); // Every stage change (drag-end OR keyboard-DnD) funnels through here so a move // into a "gewonnen"/"verloren" column opens the confirm / lost-reason dialog // instead of submitting blindly. function requestMove(projectId: string, stageId: string) { if (projectId.startsWith(PLACEHOLDER_PREFIX)) return; // placeholder cards never move const kind = stageKindById.get(stageId); if (kind === "gewonnen" || kind === "verloren") { setLostReasonId(""); setLostNote(""); setLostReasonMissing(false); setPendingMove({ projectId, stageId, kind }); return; } props.actions.onMove(projectId, stageId); } function cancelPending() { setPendingMove(null); setResetToken((token) => token + 1); // revert the optimistic drop } function confirmPending() { if (!pendingMove) return; if (pendingMove.kind === "verloren") { // Silently returning would leave the user pressing a button that appears // to do nothing; the dialog says what is missing instead. if (!lostReasonId) { setLostReasonMissing(true); return; } props.actions.onMove(pendingMove.projectId, pendingMove.stageId, lostReasonId, lostNote.trim() || undefined); } else { props.actions.onMove(pendingMove.projectId, pendingMove.stageId); } setPendingMove(null); } function toggleSelect(id: string, checked: boolean) { setSelected((prev) => { const next = new Set(prev); if (checked) next.add(id); else next.delete(id); return next; }); } const someSelected = selected.size > 0; // "Empty" is what the person actually looks at: a card parked in a hidden // column is not something they can see or work on here. const boardIsEmpty = visibleColumns.every((column) => column.cards.length === 0); const filterActive = props.facets.hasActiveFilters; // One navigation clears everything — search, only-mine and every facet. The // route drops the parameters in a single history entry, so the board does not // flicker through half-reset states. function resetFilters() { props.actions.onResetFilters(); } // Card body slot for SortableKanbanBoard. The board supplies the DnD handle; // the card places its invisible target in the tag-row whitespace so the title // link and bulk-select checkbox stay independent. Stage change is drag&drop; // right-click opens a context menu (open / move to stage / board settings). function renderProjectCard(entry: BoardEntry, dragHandle?: ReactNode): ReactNode { if (isPlaceholder(entry)) { // Dashed stage-aware placeholder for an empty column (S01a). return (
{t("projects.board.columnEmpty.title", { stage: entry.stageName })} {t("projects.board.columnEmpty.body")}
); } const card = entry; const currentStageId = stageIdByCardId.get(card.id); // Every stage, including a hidden one: "Verloren" is off the board by // default, and losing a project must not depend on showing that column. const moveTargets = data.canChangeStage ? data.columns.filter((column) => column.stageId !== currentStageId) : []; // No dead buttons: items render only with both the permission AND a wired callback. const onDuplicate = data.canWrite ? props.actions.onDuplicate : undefined; const onArchive = data.canDelete ? props.actions.onArchive : undefined; // The undo entry only appears while the service still accepts it: the VM // carries the window end and the service clears it once it has passed. const onUndo = data.canChangeStage && card.undoUntilIso ? props.actions.onUndoStage : undefined; // Redo is offered only right after an undo — the VM turns the service's // redo pointer into canRedo, and the next forward move clears it. const onRedo = data.canChangeStage && card.canRedo ? props.actions.onRedoStage : undefined; const onMoveToPipeline = data.canChangeStage ? props.actions.onMoveToPipeline : undefined; const boardTargets = data.pipelines.filter((pipeline) => pipeline.id !== data.pipelineId); return ( {card.projektname}} subtitle={card.subtitle ?? undefined} tags={
{card.projekttyp ? ( {card.projekttyp} ) : null} {/* Tags from the tenant catalogue, in their own colour. */} {card.tags.map((tag) => ( {tag.name} ))} {/* No staleness chip on the card: Davids S01 card carries the tag catalogue and the project type, nothing else. The VM still computes `stuckDays` for other readers. */} {card.isStuck ? {t("projects.board.stuck")} : null}
{/* Drag handle and bulk-select live on their own row: Davids ProjectCard has no slot for them, and squeezing them into the tag row pushes the tags out of the clamped height. */}
{dragHandle} {data.canChangeStage ? ( toggleSelect(card.id, c)} hideLabel label={card.projektname} data-ui-id={`ui.projects.board.select.${card.id}`} /> ) : null}
} price={ card.valueVisible ? ( card.value ?? "\u2014" ) : ( {t("projects.board.valueLocked")} ) } priorityLabel={t(card.prioritaetLabelKey)} variant={PRIORITY_VARIANT[card.prioritaet]} avatar={ card.ownerLabel ? ( {initialsOf(card.ownerLabel)} ) : undefined } hideAvatar={!card.ownerLabel} startDate={card.startIso ? formatters.date(card.startIso, SHORT_DATE) : undefined} endDate={card.deadlineIso ? formatters.date(card.deadlineIso, SHORT_DATE) : undefined} // The range needs at least one end to say anything; without both // the row would be two icons around an empty line. hideDateRange={!card.startIso && !card.deadlineIso} appointmentLabel={ card.appointmentIso ? t("projects.board.nextAppointment", { title: card.appointmentTitle ?? "", date: formatters.date(card.appointmentIso, SHORT_DATE), }) : undefined } hideAppointment={!card.appointmentIso} className="h-auto w-full flex-none" data-row-id={card.id} data-ui-id={`ui.projects.board.card.${card.id}`} />
{/* M03 order: open/settings, then the undo block, then the move block, then the destructive action. Local kit drift: the export names the shortcut icon prop `iconLeft1`, the synced BadgeShortcut has `icon`. */} } onSelect={() => props.actions.onOpenProject(card.detailHref)} data-ui-id={`ui.projects.board.contextMenu.${card.id}.open`} > {t("projects.board.contextMenu.open")} {data.canAdmin ? ( } onSelect={props.actions.onManageBoard} data-ui-id={`ui.projects.board.contextMenu.${card.id}.settings`} > {t("projects.board.contextMenu.settings")} ) : null} {onUndo || onRedo ? : null} {onUndo ? ( } rightSlot={}>Z} onSelect={() => onUndo(card.id)} data-ui-id={`ui.projects.board.contextMenu.${card.id}.undo`} > {t("projects.board.contextMenu.undo")} ) : null} {onRedo ? ( } rightSlot={}>⇧Z} onSelect={() => onRedo(card.id)} data-ui-id={`ui.projects.board.contextMenu.${card.id}.redo`} > {t("projects.board.contextMenu.redo")} ) : null} {moveTargets.length > 0 ? : null} {moveTargets.map((column) => ( } onSelect={() => requestMove(card.id, column.stageId)} data-ui-id={`ui.projects.board.contextMenu.${card.id}.moveTo.${column.stageId}`} > {t("projects.board.contextMenu.moveTo", { stage: column.stageName })} ))} {/* M03 "Board wechseln". Rendered flat, one entry per other board: the kit's ContextMenu has no submenu, and the number of boards is the same handful the switcher chip lists. */} {onMoveToPipeline && boardTargets.length > 0 ? : null} {onMoveToPipeline ? boardTargets.map((pipeline) => ( } onSelect={() => onMoveToPipeline(card.id, pipeline.id)} data-ui-id={`ui.projects.board.contextMenu.${card.id}.moveToBoard.${pipeline.id}`} > {t("projects.board.contextMenu.moveToBoard", { board: pipeline.name })} )) : null} {onDuplicate ? ( } rightSlot={}>D} onSelect={() => onDuplicate(card.id)} data-ui-id={`ui.projects.board.contextMenu.${card.id}.duplicate`} > {t("projects.board.contextMenu.duplicate")} ) : null} {onArchive ? ( <> {/* Davids entry says "Löschen". HiveGrid archives instead: a project carries stage history, files and appointments, and there is no hard delete behind it. */} } rightSlot={⌦} onSelect={() => setPendingArchive(card.id)} data-ui-id={`ui.projects.board.contextMenu.${card.id}.archive`} > {t("projects.board.contextMenu.archive")} ) : null}
); } const boardColumns: SortableKanbanColumn[] = visibleColumns.map((column) => ({ id: column.stageId, label: column.stageName, name: column.stageName, price: column.aggregateVisible ? (column.aggregateValue ?? "—") : "—", badge: {String(column.projectCount)}, sumMode: column.aggregateVisible ? "visible" : "locked", lockedSumSlot: t("projects.board.sumLocked"), // No stage tint: Davids S01 draws every column on the same neutral surface, // and the card already carries the only colour that means something here // (priority). The stage colour stays the detail view's stage bar. // A stage column always stays a single card column, however many cards it // holds — the board scrolls instead of widening a column into a grid. cards: column.cards.length > 0 ? column.cards : [{ id: `${PLACEHOLDER_PREFIX}${column.stageId}`, kind: "column-placeholder", stageId: column.stageId, stageName: column.stageName } satisfies ColumnPlaceholder], })); return ( } // The module names the page; which board is being shown is the switcher's // job, right next to it behind a vertical rule (Davids S01). title={t("projects.board.headline")} titleTrailing={ <> {/* S01 board switcher as a header chip — the control that decides which board the page shows. */} {data.pipelines.map((pipeline) => ( : null} onClick={() => props.actions.onSwitchPipeline(pipeline.id)} data-ui-id={`ui.projects.board.switcher.${pipeline.id}`} > {pipeline.name} ))} } actions={ <> value === "list" && props.actions.onShowList()} data-ui-id="ui.projects.board.viewToggle" > } value="board" aria-label={t("projects.viewMode.board")} data-ui-id="ui.projects.board.viewToggle.board"> {t("projects.viewMode.board")} } value="list" aria-label={t("projects.viewMode.list")} data-ui-id="ui.projects.board.viewToggle.list"> {t("projects.viewMode.list")} {data.canAdmin ? ( ) : null} {data.canWrite ? ( ) : null} } /> {/* --- Filter bar (S01): free text + facets + active-filter chips --- The board switcher moved into the header chip above; search lives in the bar itself, so the old PageToolbar row is gone. */} } label={t("projects.board.columnPicker.label")} showCount={hiddenColumnCount > 0} count={hiddenColumnCount > 0 ? String(hiddenColumnCount) : ""} data-ui-id="ui.projects.board.columnPicker" dropdown={ {data.columns.map((column) => ( setColumnVisibility((current) => ({ ...current, [column.stageId]: !isColumnVisible(column) })) } data-ui-id={`ui.projects.board.columnPicker.${column.stageId}`} > {column.stageName} ))} } /> } trailing={ props.showDemoToggle ? ( ) : null } /> {props.errorKey ?
{t(props.errorKey)}
: null} {/* --- Bulk bar --- */} {data.canChangeStage && someSelected && data.openStages.length > 0 ? (
) : null} {/* --- Empty state (S01a). One block for both cases: an empty board is an empty board, and a different icon per reason only makes the two look like different failures. It is a notice above the board, not a replacement for it — the columns stay, so the board a project would land in is still visible while the message explains why none is. --- */} {boardIsEmpty ? (
{/* Same headline either way — the reason belongs in the line below it, not in two different verdicts about the same empty board. */} {t("projects.board.emptyFiltered.title")} {t(filterActive ? "projects.board.emptyFiltered.body" : "projects.board.emptyHint")}
{/* Reset only where there is something to reset. */} {filterActive ? ( ) : null} {data.canWrite ? ( ) : null}
) : null} {/* --- Columns (drag&drop board). They render whether or not the board holds cards: each column keeps its dashed placeholder, so an empty board still shows its stages. --- */}
columns={boardColumns} renderCard={renderProjectCard} renderColumnMenu={(column, api) => ( } onClick={api.toggleCollapse} data-ui-id={`ui.projects.board.column.${column.id}.collapse`} > {api.collapsed ? t("projects.board.column.expand") : t("projects.board.column.collapse")} {data.canAdmin ? ( } onClick={props.actions.onManageBoard} data-ui-id={`ui.projects.board.column.${column.id}.settings`} > {t("projects.board.contextMenu.settings")} ) : null} )} getCardLabel={(entry) => (isPlaceholder(entry) ? entry.stageName : entry.projektname)} // An empty column's placeholder is scenery, not a project. isCardDraggable={(entry) => !isPlaceholder(entry)} onCardMove={(cardId, toColumnId) => requestMove(cardId, toColumnId)} disabled={!data.canChangeStage} dragHandlePlacement="inline" errorKey={props.errorKey} resetToken={resetToken} data-ui-id="ui.projects.board.columns" />
{/* --- M01 Verloren-Dialog / Gewonnen-Bestätigung --- */} (open ? null : cancelPending())}> {/* w-112 like the export, and `items-stretch` (not `items-start`): with items-start the Select shrank to its content while the TextArea filled the row, so the two fields ended up different widths. */}
: } />
{t(pendingMove?.kind === "verloren" ? "projects.lostDialog.title" : "projects.wonDialog.title")} {t(pendingMove?.kind === "verloren" ? "projects.lostDialog.subtitle" : "projects.wonDialog.body")}
} onClick={cancelPending} data-ui-id="ui.projects.board.moveDialog.close" />
{pendingMove?.kind === "verloren" ? ( <> {/* Local kit drift: the cloud export names the error text prop `message`; the synced Select only has `errorText`. */} ) : null}
{/* --- Archive confirm dialog (same Dialog pattern as the won/lost confirm) --- */} (open ? null : setPendingArchive(null))}>
{t("projects.archiveDialog.title")} {t("projects.archiveDialog.body")}
{/* --- Quick-create dialog (interim-UI shell mirroring TaskNewDialog) --- */}
{t("projects.actions.newProject")} {t("projects.createDialog.subtitle")}
} aria-label={t("projects.actions.cancel")} onClick={() => setCreateOpen(false)} />
setDraft((d) => ({ ...d, projektname: e.target.value }))} data-ui-id="ui.projects.board.createDialog.name" />
{/* --- M04 pipeline handover. Status-driven: the move hands the payload back, there is no button that opens this. --- */} {props.handover && props.actions.onHandover ? ( setHandoverDismissed(open ? null : props.handover!.projectId)} onConfirm={(selection) => { props.actions.onHandover?.(props.handover!.projectId, props.handover!.fromPipelineId, selection); setHandoverDismissed(props.handover!.projectId); }} /> ) : null}
); } export default PipelineKanbanPage;