Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/projects/PipelineKanbanPage.tsx
T

946 lines
47 KiB
TypeScript

// 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<string, "none" | "low" | "medium" | "high" | "critical"> = {
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<ReadonlySet<string>>(new Set());
const [bulkStage, setBulkStage] = useState(data.openStages[0]?.id ?? "");
const [pendingMove, setPendingMove] = useState<PendingMove | null>(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<string | null>(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<Readonly<Record<string, boolean>>>({});
// 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<string | null>(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<string, string>();
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 (
<div
className="flex min-h-[144px] w-full flex-col items-center justify-center gap-2 rounded-md border border-dashed border-border-default bg-surface-neutral-secondary px-4 py-6"
data-ui-id={`ui.projects.board.column.empty.${entry.stageId}`}
>
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-secondary">
{t("projects.board.columnEmpty.title", { stage: entry.stageName })}
</span>
<span className="text-center text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
{t("projects.board.columnEmpty.body")}
</span>
</div>
);
}
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 (
<SubframeCore.ContextMenu.Root>
<SubframeCore.ContextMenu.Trigger asChild>
<ProjectCard
title={<AppLink href={card.detailHref} className="text-text-feedback-link-default">{card.projektname}</AppLink>}
subtitle={card.subtitle ?? undefined}
tags={
<div className="flex w-full flex-col gap-1">
<div className="flex flex-wrap items-center gap-1">
{card.projekttyp ? (
<Tag_Label tone="blue-subtle" noAction size="small" data-ui-id={`ui.projects.board.typ.${card.id}`}>
{card.projekttyp}
</Tag_Label>
) : null}
{/* Tags from the tenant catalogue, in their own colour. */}
{card.tags.map((tag) => (
<Tag_Label key={tag.id} tone={tagTone(tag.farbe)} noAction size="small" data-ui-id={`ui.projects.board.tag.${card.id}.${tag.id}`}>
{tag.name}
</Tag_Label>
))}
{/* 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 ? <BadgeFeedback farbe="subtle-warning" size="small">{t("projects.board.stuck")}</BadgeFeedback> : null}
</div>
{/* 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. */}
<div className="flex w-full items-center justify-between gap-2">
{dragHandle}
{data.canChangeStage ? (
<Checkbox
checked={selected.has(card.id)}
onCheckedChange={(c) => toggleSelect(card.id, c)}
hideLabel
label={card.projektname}
data-ui-id={`ui.projects.board.select.${card.id}`}
/>
) : null}
</div>
</div>
}
price={
card.valueVisible ? (
card.value ?? "\u2014"
) : (
<span className={mutedText}>{t("projects.board.valueLocked")}</span>
)
}
priorityLabel={t(card.prioritaetLabelKey)}
variant={PRIORITY_VARIANT[card.prioritaet]}
avatar={
card.ownerLabel ? (
<Avatar size="extra-small" data-ui-id={`ui.projects.board.owner.${card.id}`}>{initialsOf(card.ownerLabel)}</Avatar>
) : 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}`}
/>
</SubframeCore.ContextMenu.Trigger>
<SubframeCore.ContextMenu.Portal>
<SubframeCore.ContextMenu.Content asChild>
{/* 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`. */}
<ContextMenu data-ui-id={`ui.projects.board.contextMenu.${card.id}`}>
<ContextMenu.ContextItem
icon={<FeatherExternalLink />}
onSelect={() => props.actions.onOpenProject(card.detailHref)}
data-ui-id={`ui.projects.board.contextMenu.${card.id}.open`}
>
{t("projects.board.contextMenu.open")}
</ContextMenu.ContextItem>
{data.canAdmin ? (
<ContextMenu.ContextItem
icon={<FeatherSettings2 />}
onSelect={props.actions.onManageBoard}
data-ui-id={`ui.projects.board.contextMenu.${card.id}.settings`}
>
{t("projects.board.contextMenu.settings")}
</ContextMenu.ContextItem>
) : null}
{onUndo || onRedo ? <ContextMenu.ContextDivider /> : null}
{onUndo ? (
<ContextMenu.ContextItem
icon={<FeatherUndo2 />}
rightSlot={<BadgeShortcut icon={<FeatherCommand />}>Z</BadgeShortcut>}
onSelect={() => onUndo(card.id)}
data-ui-id={`ui.projects.board.contextMenu.${card.id}.undo`}
>
{t("projects.board.contextMenu.undo")}
</ContextMenu.ContextItem>
) : null}
{onRedo ? (
<ContextMenu.ContextItem
icon={<FeatherRedo2 />}
rightSlot={<BadgeShortcut icon={<FeatherCommand />}>⇧Z</BadgeShortcut>}
onSelect={() => onRedo(card.id)}
data-ui-id={`ui.projects.board.contextMenu.${card.id}.redo`}
>
{t("projects.board.contextMenu.redo")}
</ContextMenu.ContextItem>
) : null}
{moveTargets.length > 0 ? <ContextMenu.ContextDivider /> : null}
{moveTargets.map((column) => (
<ContextMenu.ContextItem
key={column.stageId}
icon={<FeatherArrowRight />}
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 })}
</ContextMenu.ContextItem>
))}
{/* 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 ? <ContextMenu.ContextDivider /> : null}
{onMoveToPipeline
? boardTargets.map((pipeline) => (
<ContextMenu.ContextItem
key={pipeline.id}
icon={<FeatherArrowLeftRight />}
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 })}
</ContextMenu.ContextItem>
))
: null}
{onDuplicate ? (
<ContextMenu.ContextItem
icon={<FeatherCopy />}
rightSlot={<BadgeShortcut icon={<FeatherCommand />}>D</BadgeShortcut>}
onSelect={() => onDuplicate(card.id)}
data-ui-id={`ui.projects.board.contextMenu.${card.id}.duplicate`}
>
{t("projects.board.contextMenu.duplicate")}
</ContextMenu.ContextItem>
) : null}
{onArchive ? (
<>
<ContextMenu.ContextDivider />
{/* Davids entry says "Löschen". HiveGrid archives instead:
a project carries stage history, files and appointments,
and there is no hard delete behind it. */}
<ContextMenu.ContextItem
className="text-text-feedback-negative hover:bg-surface-feedback-subtle-negative"
icon={<FeatherArchive />}
rightSlot={<BadgeShortcut icon={null}>&#8998;</BadgeShortcut>}
onSelect={() => setPendingArchive(card.id)}
data-ui-id={`ui.projects.board.contextMenu.${card.id}.archive`}
>
{t("projects.board.contextMenu.archive")}
</ContextMenu.ContextItem>
</>
) : null}
</ContextMenu>
</SubframeCore.ContextMenu.Content>
</SubframeCore.ContextMenu.Portal>
</SubframeCore.ContextMenu.Root>
);
}
const boardColumns: SortableKanbanColumn<BoardEntry>[] = visibleColumns.map((column) => ({
id: column.stageId,
label: column.stageName,
name: column.stageName,
price: column.aggregateVisible ? (column.aggregateValue ?? "—") : "—",
badge: <BadgeFeedback farbe="subtle-neutral" size="small">{String(column.projectCount)}</BadgeFeedback>,
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 (
<PageShell uiId="ui.projects.board" className="bg-surface-neutral-primary" sseHref={data.sseHref}>
<PageHeader
uiId="ui.projects.board.header"
dense
icon={<FeatherKanbanSquare className={PAGE_HEADER_ICON_CLASS} />}
// 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. */}
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<button
type="button"
className="flex items-center gap-2 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-3 py-1.5 hover:bg-surface-neutral-tertiary"
data-ui-id="ui.projects.board.switcher"
aria-label={t("projects.fields.pipeline")}
>
<FeatherTrendingUp className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
<span className="break-words text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">
{data.pipelineName}
</span>
<FeatherChevronDown className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
</button>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
<DropdownMenu>
{data.pipelines.map((pipeline) => (
<DropdownMenu.DropdownItem
key={pipeline.id}
icon={pipeline.id === data.pipelineId ? <FeatherCheck /> : null}
onClick={() => props.actions.onSwitchPipeline(pipeline.id)}
data-ui-id={`ui.projects.board.switcher.${pipeline.id}`}
>
{pipeline.name}
</DropdownMenu.DropdownItem>
))}
</DropdownMenu>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
</>
}
actions={
<>
<ToggleGroup
value="board"
onValueChange={(value: string) => value === "list" && props.actions.onShowList()}
data-ui-id="ui.projects.board.viewToggle"
>
<ToggleGroup.Item icon={<FeatherColumns />} value="board" aria-label={t("projects.viewMode.board")} data-ui-id="ui.projects.board.viewToggle.board">
{t("projects.viewMode.board")}
</ToggleGroup.Item>
<ToggleGroup.Item icon={<FeatherList />} value="list" aria-label={t("projects.viewMode.list")} data-ui-id="ui.projects.board.viewToggle.list">
{t("projects.viewMode.list")}
</ToggleGroup.Item>
</ToggleGroup>
{data.canAdmin ? (
<Button
variant="tertiary"
icon={<FeatherSettings2 />}
onClick={props.actions.onManageBoard}
data-ui-id="ui.projects.board.settings"
>
{t("projects.board.contextMenu.settings")}
</Button>
) : null}
{data.canWrite ? (
<Button icon={<FeatherPlus />} onClick={() => setCreateOpen(true)} data-ui-id="ui.projects.board.new">
{t("projects.actions.newProject")}
</Button>
) : 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. */}
<BoardFilterBar
facets={props.facets}
search={props.q}
onSearch={props.actions.onSearch}
onlyMine={props.onlyMine}
onToggleOnlyMine={props.actions.onToggleOnlyMine}
onToggleFacet={props.actions.onToggleFacet}
onRemoveChip={props.actions.onRemoveChip}
onReset={resetFilters}
periodFrom={props.periodFrom}
periodTo={props.periodTo}
onPeriodRangeChange={props.actions.onPeriodRangeChange}
// Which stages are on screen. It sits behind the rule because it is not
// a filter — it changes nothing about which projects the board holds, so
// it needs no permission and is not persisted. Multi-select, so hiding
// two columns does not mean opening the menu twice.
afterDivider={
<FilterBar.StatusFilterButton
icon={<FeatherColumns />}
label={t("projects.board.columnPicker.label")}
showCount={hiddenColumnCount > 0}
count={hiddenColumnCount > 0 ? String(hiddenColumnCount) : ""}
data-ui-id="ui.projects.board.columnPicker"
dropdown={
<DropdownMenuMultiSelect>
{data.columns.map((column) => (
<DropdownMenuMultiSelect.DropdownItem
key={column.stageId}
showCheckbox
selected={isColumnVisible(column)}
onClick={() =>
setColumnVisibility((current) => ({ ...current, [column.stageId]: !isColumnVisible(column) }))
}
data-ui-id={`ui.projects.board.columnPicker.${column.stageId}`}
>
{column.stageName}
</DropdownMenuMultiSelect.DropdownItem>
))}
</DropdownMenuMultiSelect>
}
/>
}
trailing={
props.showDemoToggle ? (
<Checkbox
checked={props.includeDemoData}
onCheckedChange={props.actions.onToggleDemo}
label={t("onboarding.demoData.showInLists")}
data-ui-id="ui.projects.board.demo"
/>
) : null
}
/>
{props.errorKey ? <div className="w-full px-6 pt-4 mobile:px-4"><BadgeFeedback farbe="subtle-negative">{t(props.errorKey)}</BadgeFeedback></div> : null}
{/* --- Bulk bar --- */}
{data.canChangeStage && someSelected && data.openStages.length > 0 ? (
<div className="flex w-full flex-wrap items-end gap-2 px-6 pt-4 mobile:px-4" data-ui-id="ui.projects.board.bulk">
<Select label={t("projects.board.moveTo")} showLabel value={bulkStage} onValueChange={setBulkStage}>
{data.openStages.map((stage) => (
<Select.Item key={stage.id} value={stage.id}>{stage.name}</Select.Item>
))}
</Select>
<Button
variant="neutral"
size="small"
loading={props.submitting}
onClick={() => {
props.actions.onBulkMove([...selected], bulkStage);
setSelected(new Set());
}}
data-ui-id="ui.projects.board.bulk.apply"
>
{t("projects.board.bulkApply")}
</Button>
</div>
) : 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 ? (
<div className="w-full px-6 pt-4 mobile:px-3">
<div
className="flex w-full items-center gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-4 mobile:flex-col mobile:items-start"
data-ui-id={filterActive ? "ui.projects.board.emptyFiltered" : "ui.projects.board.empty"}
>
<div className="flex h-10 w-10 flex-none items-center justify-center rounded-md bg-surface-neutral-tertiary">
<FeatherSearchX className="text-body-large font-body-large text-icon-neutral-tertiary" />
</div>
<div className="flex min-w-[0px] grow shrink-0 basis-0 flex-col items-start gap-1">
{/* Same headline either way — the reason belongs in the line below
it, not in two different verdicts about the same empty board. */}
<span className="text-body-default-medium-150 font-body-default-medium-150 text-text-neutral-primary">
{t("projects.board.emptyFiltered.title")}
</span>
<span className={mutedText}>{t(filterActive ? "projects.board.emptyFiltered.body" : "projects.board.emptyHint")}</span>
</div>
<div className="flex items-center gap-2 mobile:w-full mobile:flex-none mobile:flex-col">
{/* Reset only where there is something to reset. */}
{filterActive ? (
<Button
className="mobile:w-full"
variant="tertiary"
size="small"
icon={<FeatherRotateCcw />}
onClick={resetFilters}
data-ui-id="ui.projects.board.emptyFiltered.reset"
>
{t("projects.board.emptyFiltered.reset")}
</Button>
) : null}
{data.canWrite ? (
<Button
className="mobile:w-full"
size="small"
icon={<FeatherPlus />}
onClick={() => setCreateOpen(true)}
data-ui-id={filterActive ? "ui.projects.board.emptyFiltered.create" : "ui.projects.board.empty.create"}
>
{t("projects.board.emptyFiltered.create")}
</Button>
) : null}
</div>
</div>
</div>
) : 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. --- */}
<div className="w-full overflow-x-auto px-6 py-4 mobile:px-3">
<SortableKanbanBoard<BoardEntry>
columns={boardColumns}
renderCard={renderProjectCard}
renderColumnMenu={(column, api) => (
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<button type="button" aria-label={t("projects.board.column.menu")} data-ui-id={`ui.projects.board.column.${column.id}.menu`}>
<FeatherMoreVertical />
</button>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="end" sideOffset={4} asChild>
<DropdownMenu>
<DropdownMenu.DropdownItem
icon={<FeatherChevronsLeft />}
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")}
</DropdownMenu.DropdownItem>
{data.canAdmin ? (
<DropdownMenu.DropdownItem
icon={<FeatherSettings2 />}
onClick={props.actions.onManageBoard}
data-ui-id={`ui.projects.board.column.${column.id}.settings`}
>
{t("projects.board.contextMenu.settings")}
</DropdownMenu.DropdownItem>
) : null}
</DropdownMenu>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
)}
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"
/>
</div>
{/* --- M01 Verloren-Dialog / Gewonnen-Bestätigung --- */}
<Dialog open={pendingMove !== null} onOpenChange={(open) => (open ? null : cancelPending())}>
<Dialog.Content className="p-4" data-ui-id="ui.projects.board.moveDialog">
{/* 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. */}
<div className="flex w-full flex-col items-stretch gap-5" style={{ width: 448, maxWidth: "92vw" }}>
<div className="flex w-full items-start justify-between gap-3">
<div className="flex items-start gap-3">
<IconWithBackground
variant={pendingMove?.kind === "verloren" ? "destructive" : "success"}
size="large"
round
icon={pendingMove?.kind === "verloren" ? <FeatherTrendingDown /> : <FeatherTrendingUp />}
/>
<div className="flex flex-col items-start gap-1">
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">
{t(pendingMove?.kind === "verloren" ? "projects.lostDialog.title" : "projects.wonDialog.title")}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
{t(pendingMove?.kind === "verloren" ? "projects.lostDialog.subtitle" : "projects.wonDialog.body")}
</span>
</div>
</div>
<IconButton variant="tertiary" size="small" icon={<FeatherX />} onClick={cancelPending} data-ui-id="ui.projects.board.moveDialog.close" />
</div>
{pendingMove?.kind === "verloren" ? (
<>
{/* Local kit drift: the cloud export names the error text prop
`message`; the synced Select only has `errorText`. */}
<Select
// `max-w-none`: the kit caps a Select at 320px, which left it
// narrower than the note field right under it.
className="w-full max-w-none"
variant="outline"
showLabel
label={t("projects.lostDialog.reasonLabel")}
placeholder={t("projects.lostDialog.reasonPlaceholder")}
// The error only appears once the user tried to confirm
// without a reason — showing it on open would scold them for
// a form they have not touched yet.
error={lostReasonMissing}
icon={lostReasonMissing ? <FeatherAlertCircle /> : undefined}
errorText={lostReasonMissing ? t("projects.lostDialog.reasonRequired") : undefined}
value={lostReasonId || undefined}
onValueChange={(value) => {
setLostReasonId(value);
setLostReasonMissing(false);
}}
data-ui-id="ui.projects.board.moveDialog.reason"
>
{data.lostReasons.map((reason) => (
<Select.Item key={reason.id} value={reason.id}>{reason.name}</Select.Item>
))}
</Select>
<TextArea className="w-full max-w-none" showLabel label={t("projects.lostDialog.noteLabel")}>
<TextArea.Input
placeholder={t("projects.lostDialog.notePlaceholder")}
value={lostNote}
onChange={(event) => setLostNote(event.target.value)}
data-ui-id="ui.projects.board.moveDialog.note"
/>
</TextArea>
<Alert
className="w-full"
variant="information"
notDismissible
description={t("projects.lostDialog.undoHint")}
textSize="small"
/>
</>
) : null}
<div className="flex w-full items-center justify-end gap-2">
<Button variant="tertiary" onClick={cancelPending}>{t("projects.actions.cancel")}</Button>
<Button
variant={pendingMove?.kind === "verloren" ? "destructive" : undefined}
icon={pendingMove?.kind === "verloren" ? <FeatherX /> : undefined}
loading={props.submitting}
onClick={confirmPending}
data-ui-id="ui.projects.board.moveDialog.confirm"
>
{t(pendingMove?.kind === "verloren" ? "projects.actions.confirmLost" : "projects.actions.confirmWon")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
{/* --- Archive confirm dialog (same Dialog pattern as the won/lost confirm) --- */}
<Dialog open={pendingArchive !== null} onOpenChange={(open) => (open ? null : setPendingArchive(null))}>
<Dialog.Content className="p-6" data-ui-id="ui.projects.board.archiveDialog">
<div className="flex w-full flex-col gap-4" style={{ minWidth: 420 }}>
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{t("projects.archiveDialog.title")}
</span>
<span className={mutedText}>{t("projects.archiveDialog.body")}</span>
<div className="flex justify-end gap-2">
<Button variant="neutral" onClick={() => setPendingArchive(null)}>{t("projects.actions.cancel")}</Button>
<Button
variant="destructive"
loading={props.submitting}
onClick={() => {
if (pendingArchive) props.actions.onArchive?.(pendingArchive);
setPendingArchive(null);
}}
data-ui-id="ui.projects.board.archiveDialog.confirm"
>
{t("projects.actions.archive")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
{/* --- Quick-create dialog (interim-UI shell mirroring TaskNewDialog) --- */}
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
<Dialog.Content className="w-[440px] max-w-[92vw] p-0" data-ui-id="ui.projects.board.createDialog">
<div className="flex w-full flex-col">
<div className="flex w-full items-start justify-between gap-3 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-5 mobile:px-4">
<div className="flex flex-col items-start gap-1">
<span className="text-heading- font-heading- text-text-neutral-primary">{t("projects.actions.newProject")}</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("projects.createDialog.subtitle")}</span>
</div>
<IconButton type="button" variant="ghost" size="small" icon={<FeatherX />} aria-label={t("projects.actions.cancel")} onClick={() => setCreateOpen(false)} />
</div>
<div className="flex w-full flex-col gap-4 px-6 py-5 max-h-[65vh] overflow-y-auto mobile:px-4">
<TextInput label={t("projects.fields.name")} showLabel>
<TextInput.Input autoFocus value={draft.projektname} onChange={(e) => setDraft((d) => ({ ...d, projektname: e.target.value }))} data-ui-id="ui.projects.board.createDialog.name" />
</TextInput>
</div>
<div className="flex w-full items-center justify-end gap-2 border-t border-solid border-border-default bg-surface-neutral-secondary px-6 py-4 mobile:flex-col-reverse mobile:items-stretch mobile:px-4">
<Button type="button" className="mobile:w-full" variant="tertiary" onClick={() => setCreateOpen(false)}>{t("projects.actions.cancel")}</Button>
<Button
className="mobile:w-full"
icon={<FeatherPlus />}
disabled={!draft.projektname.trim()}
loading={props.submitting}
onClick={() => {
props.actions.onCreateProject({ projektname: draft.projektname.trim(), potenziellerAuftragswert: draft.potenziellerAuftragswert.trim() });
setCreateOpen(false);
setDraft({ projektname: "", potenziellerAuftragswert: "" });
}}
data-ui-id="ui.projects.board.createDialog.confirm"
>
{t("projects.actions.create")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
{/* --- M04 pipeline handover. Status-driven: the move hands the payload
back, there is no button that opens this. --- */}
{props.handover && props.actions.onHandover ? (
<PipelineHandoverDialog
key={props.handover.projectId}
open={handoverDismissed !== props.handover.projectId}
vm={props.handover}
submitting={props.submitting}
onOpenChange={(open) => setHandoverDismissed(open ? null : props.handover!.projectId)}
onConfirm={(selection) => {
props.actions.onHandover?.(props.handover!.projectId, props.handover!.fromPipelineId, selection);
setHandoverDismissed(props.handover!.projectId);
}}
/>
) : null}
</PageShell>
);
}
export default PipelineKanbanPage;