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

565 lines
25 KiB
TypeScript

// WF-P8 S07 "Boards-Übersicht" — rebuilt against Davids Subframe export of
// 2026-07-28 (page 5190e285-e92f-4ad2-9f3d-2a2f511fe695), including the create
// dialog variants S07-D (50219cd7-…) and S07a (a0139eb6-…).
//
// The screen used to be a stack of accordion cards that configured every board
// inline. David split that: this page lists the boards and each row links to
// S04 (BoardSettingsPage) for the configuration. Pure/presentational — renders
// the server-built PipelineAdminData and turns create/duplicate/archive into a
// typed onSubmit(intent, fields) the route POSTs. No useLoaderData/useFetcher.
//
// Deliberate deltas against the export:
// * The "Zugriff" column reports the shape of the restriction, not a team
// name. PipelineAccess stores a role/group/user id, and resolving those to
// display names is a lookup this table does not do.
// * The export's header "Board-Einstellungen" button names no board. Settings
// are per board, so it opens the default one (the board the footer line
// names) and hides itself when the tenant has no board at all.
// * S07-D and S07a are the same dialog in two states, so they are one
// component here: the error state is what it renders once a create attempt
// came back with field errors.
import { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { AppLink } from "~/components/app/AppLink";
import type { PipelineAdminData, PipelineAdminItem, PipelineTypHint } from "@hivegrid/view-models";
import {
FeatherActivity,
FeatherChevronRight,
FeatherFilter,
FeatherColumns,
FeatherCopy,
FeatherFolderKanban,
FeatherGlobe,
FeatherKanbanSquare,
FeatherLayers,
FeatherLock,
FeatherMoreHorizontal,
FeatherPlus,
FeatherSettings,
FeatherShield,
FeatherTag,
FeatherThumbsDown,
FeatherTrash,
FeatherUsers,
FeatherX,
} from "@subframe/core";
import * as SubframeCore from "@subframe/core";
import { FacetFilterBar } from "../shared/FacetFilterBar";
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
import { BOARD_TYP_ICON, BOARD_TYP_TONE } from "./boardTypeVisuals";
import { Alert } from "~/ui/components/Alert";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { Dialog } from "~/ui/components/Dialog";
import { DropdownMenu } from "~/ui/components/DropdownMenu";
import { EmptyState } from "~/ui/components/EmptyState";
import { IconButton } from "~/ui/components/IconButton";
import { IconWithBackground } from "~/ui/components/IconWithBackground";
import { Select } from "~/ui/components/Select";
import { Table } from "~/ui/components/Table";
import { Tag_Label } from "~/ui/components/Tag_Label";
import { TextInput } from "~/ui/components/TextInput";
import { useLocaleFormatters } from "~/locale/format";
export type PipelineAdminSubmit = (intent: string, fields: Record<string, string>) => void;
export type PipelineAdminPageProps = {
data: PipelineAdminData;
submitting: boolean;
errorKey?: string | null;
lostReasonsHref: string;
/** S04 board settings of one board. */
settingsHref: (pipelineId: string) => string;
actions: { onSubmit: PipelineAdminSubmit };
};
const DEFAULT_STAGES = JSON.stringify([
{ name: "Neu", stageKind: "offen" },
{ name: "Gewonnen", stageKind: "gewonnen" },
{ name: "Verloren", stageKind: "verloren" },
]);
const TYP_OPTIONS = ["sales", "auftrag", "custom"] as const;
export type BoardTypFilter = PipelineTypHint;
export type BoardStatusFilter = "active" | "draft";
export type BoardAccessFilter = "everyone" | "restricted";
export type BoardRulesFilter = "withRules" | "withoutRules";
export type BoardFilters = {
readonly search: string;
/** Empty set = facet not filtered. Several values in one facet are OR-ed. */
readonly typ: ReadonlySet<string>;
readonly status: ReadonlySet<string>;
readonly access: ReadonlySet<string>;
readonly rules: ReadonlySet<string>;
};
const STATUS_OPTIONS: readonly BoardStatusFilter[] = ["active", "draft"];
const ACCESS_OPTIONS: readonly BoardAccessFilter[] = ["everyone", "restricted"];
const RULES_OPTIONS: readonly BoardRulesFilter[] = ["withRules", "withoutRules"];
const EMPTY_SELECTION: ReadonlySet<string> = new Set();
/** Adds or removes one value of a facet. */
function toggleValue(current: ReadonlySet<string>, value: string): ReadonlySet<string> {
const next = new Set(current);
if (!next.delete(value)) next.add(value);
return next;
}
/**
* Client-side board filter, exported so the rule can be tested without driving
* the Radix menus. The list is a handful of rows, so filtering here rather
* than round-tripping to the server is the cheaper answer.
*/
export function filterBoards(boards: readonly PipelineAdminItem[], filters: BoardFilters): readonly PipelineAdminItem[] {
const query = filters.search.trim().toLowerCase();
return boards.filter((board) => {
if (filters.typ.size > 0 && !filters.typ.has(board.typHint)) return false;
if (filters.status.size > 0 && !filters.status.has(board.statusKey)) return false;
if (filters.access.size > 0 && !filters.access.has(board.access.scope)) return false;
// "Regeln" is not the same question as "Zugriff": the access scope counts
// denying rules only, so a board configured purely with granting rules
// reads as "everyone" while still carrying rules.
if (filters.rules.size > 0 && !filters.rules.has(board.accessRules.length > 0 ? "withRules" : "withoutRules")) return false;
if (query && !board.name.toLowerCase().includes(query)) return false;
return true;
});
}
/** Field errors of the create dialog hold i18n keys so the render stays dumb. */
type NewBoardErrors = { nameKey?: string; typKey?: string };
export function PipelineAdminPage(props: PipelineAdminPageProps) {
const { t } = useTranslation();
const submit = props.actions.onSubmit;
const boards = props.data.pipelines;
const [filters, setFilters] = useState<BoardFilters>({
search: "",
typ: EMPTY_SELECTION,
status: EMPTY_SELECTION,
access: EMPTY_SELECTION,
rules: EMPTY_SELECTION,
});
const visible = useMemo(() => filterBoards(boards, filters), [boards, filters]);
const defaultBoard = boards.find((board) => board.isDefault) ?? null;
const headerSettingsBoard = defaultBoard ?? boards[0] ?? null;
const [newBoard, setNewBoard] = useState({ name: "", typHint: "" });
const [dialogOpen, setDialogOpen] = useState(false);
const [createErrors, setCreateErrors] = useState<NewBoardErrors>({});
const [createFailed, setCreateFailed] = useState(false);
// "waiting" = submit fired, POST not started yet; "inflight" = POST running.
const [createPhase, setCreatePhase] = useState<"idle" | "waiting" | "inflight">("idle");
function resetDialog() {
setNewBoard({ name: "", typHint: "" });
setCreateErrors({});
setCreateFailed(false);
setCreatePhase("idle");
}
// S07a error state: keep the dialog open until the create round-trip
// succeeded. A server error re-shows the alert and maps the duplicate-name
// key onto the name field; success closes and resets the dialog.
useEffect(() => {
if (createPhase === "waiting" && props.submitting) {
setCreatePhase("inflight");
return;
}
if (createPhase === "inflight" && !props.submitting) {
setCreatePhase("idle");
if (props.errorKey) {
setCreateFailed(true);
if (props.errorKey === "projects.error.pipelineNameDuplicate") {
setCreateErrors({ nameKey: "projects.admin.createDialog.nameDuplicate" });
}
} else {
setDialogOpen(false);
resetDialog();
}
}
}, [createPhase, props.submitting, props.errorKey]);
function handleCreate() {
const name = newBoard.name.trim();
const nextErrors: NewBoardErrors = {};
if (boards.some((board) => board.name.trim().toLowerCase() === name.toLowerCase())) {
nextErrors.nameKey = "projects.admin.createDialog.nameDuplicate";
}
if (!newBoard.typHint) {
nextErrors.typKey = "projects.admin.createDialog.typRequired";
}
if (nextErrors.nameKey || nextErrors.typKey) {
setCreateErrors(nextErrors);
setCreateFailed(true);
return;
}
setCreateErrors({});
setCreateFailed(false);
setCreatePhase("waiting");
submit("createPipeline", { name, typHint: newBoard.typHint, stages: DEFAULT_STAGES });
}
return (
<PageShell uiId="ui.projects.admin" className="bg-surface-neutral-primary">
<PageHeader
icon={<FeatherColumns className={PAGE_HEADER_ICON_CLASS} />}
title={t("projects.admin.title")}
subtitle={t("projects.admin.subtitle")}
actions={
<>
<AppLink href={props.lostReasonsHref} className="no-underline">
<Button variant="tertiary" size="small" icon={<FeatherThumbsDown />}>
{t("projects.lostReasonsAdmin.title")}
</Button>
</AppLink>
{/* The export draws this button without saying which board it
configures. It opens the default board — the one the footer line
names — and falls back to the first board when none is marked.
With no boards at all there is nothing to configure. */}
{headerSettingsBoard ? (
<AppLink href={props.settingsHref(headerSettingsBoard.id)} className="no-underline" data-ui-id="ui.projects.admin.headerSettings">
<Button variant="tertiary" size="small" icon={<FeatherSettings />}>
{t("projects.board.contextMenu.settings")}
</Button>
</AppLink>
) : null}
<Button size="small" icon={<FeatherPlus />} onClick={() => setDialogOpen(true)} data-ui-id="ui.projects.admin.newPipeline.open">
{t("projects.admin.newPipeline")}
</Button>
</>
}
/>
<FacetFilterBar
uiId="ui.projects.admin.filter"
facets={[
{
key: "typ",
label: t("projects.admin.filter.typ"),
icon: <FeatherFilter />,
selected: filters.typ,
options: TYP_OPTIONS.map((typ) => ({ value: typ, label: t(`projects.typHint.${typ}`), tone: BOARD_TYP_TONE[typ] })),
},
{
key: "status",
label: t("projects.admin.filter.status"),
icon: <FeatherActivity />,
tone: "sky-subtle",
selected: filters.status,
options: STATUS_OPTIONS.map((status) => ({ value: status, label: t(`projects.boardSettings.status.${status}`) })),
},
{
key: "access",
label: t("projects.admin.filter.access"),
icon: <FeatherLock />,
tone: "blue-subtle",
selected: filters.access,
options: ACCESS_OPTIONS.map((scope) => ({ value: scope, label: t(`projects.admin.accessScope.${scope}`) })),
},
{
key: "rules",
label: t("projects.admin.filter.rules"),
icon: <FeatherShield />,
tone: "sand-subtle",
selected: filters.rules,
options: RULES_OPTIONS.map((rules) => ({ value: rules, label: t(`projects.admin.rulesScope.${rules}`) })),
},
]}
onToggle={(facetKey, value) =>
setFilters((current) => ({
...current,
[facetKey]: toggleValue(current[facetKey as "typ" | "status" | "access" | "rules"], value),
}))
}
search={filters.search}
onSearchChange={(value) => setFilters((current) => ({ ...current, search: value }))}
searchPlaceholder={t("projects.fields.search")}
onReset={() =>
setFilters({ search: "", typ: EMPTY_SELECTION, status: EMPTY_SELECTION, access: EMPTY_SELECTION, rules: EMPTY_SELECTION })
}
labels={{ reset: t("projects.board.filter.reset"), removeChip: t("projects.board.filter.removeChip") }}
trailing={
<span
className="whitespace-nowrap text-body-extra-small-medium-0 font-body-extra-small-medium-0 text-text-neutral-tertiary"
data-ui-id="ui.projects.admin.count"
>
{t("projects.admin.boardCount", { count: visible.length })}
</span>
}
/>
<PageBody>
{props.errorKey ? (
<Alert variant="error" notDismissible title={t(props.errorKey)} data-ui-id="ui.projects.admin.error" />
) : null}
{visible.length === 0 ? (
<EmptyState title={t("projects.admin.empty")} data-ui-id="ui.projects.admin.empty" />
) : (
<>
<div className="flex w-full flex-col items-start overflow-hidden rounded-lg border border-solid border-border-default shadow-sm overflow-x-auto">
<Table
className="border-none min-w-[880px]"
data-ui-id="ui.projects.admin.list"
header={
<Table.HeaderRow className="bg-surface-neutral-tertiary">
<Table.HeaderCell icon={<FeatherColumns />}>{t("projects.admin.columns.board")}</Table.HeaderCell>
<Table.HeaderCell icon={<FeatherTag />}>{t("projects.admin.columns.typ")}</Table.HeaderCell>
<Table.HeaderCell icon={<FeatherLayers />}>{t("projects.admin.columns.stages")}</Table.HeaderCell>
<Table.HeaderCell icon={<FeatherFolderKanban />}>{t("projects.admin.columns.projects")}</Table.HeaderCell>
<Table.HeaderCell icon={<FeatherUsers />}>{t("projects.admin.columns.access")}</Table.HeaderCell>
<Table.HeaderCell icon={<FeatherActivity />}>{t("projects.admin.columns.status")}</Table.HeaderCell>
{/* "Aktionen" carries no icon in the export. */}
<Table.HeaderCell>{t("projects.admin.columns.actions")}</Table.HeaderCell>
</Table.HeaderRow>
}
emptyText={t("projects.admin.empty")}
>
{visible.map((board) => (
<BoardRow key={board.id} board={board} settingsHref={props.settingsHref(board.id)} submit={submit} />
))}
</Table>
</div>
<span
className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary"
data-ui-id="ui.projects.admin.footer"
>
{defaultBoard
? t("projects.admin.footerLine", { shown: visible.length, total: boards.length, name: defaultBoard.name })
: t("projects.admin.footerLineNoDefault", { shown: visible.length, total: boards.length })}
</span>
</>
)}
</PageBody>
<Dialog
open={dialogOpen}
onOpenChange={(open) => {
setDialogOpen(open);
if (!open) resetDialog();
}}
>
{/* One flat card, as in the export: no tinted header or footer band —
the dialog is short enough that the tints only cut it into stripes. */}
<Dialog.Content className="w-[448px] max-w-[92vw] p-0" data-ui-id="ui.projects.admin.newPipeline">
<div className="flex w-full flex-col gap-5 px-4 py-4">
<div className="flex w-full items-start justify-between gap-3">
<div className="flex items-start gap-3">
<IconWithBackground variant="information" size="large" round icon={<FeatherKanbanSquare />} />
<div className="flex min-w-0 flex-col items-start gap-1">
{/* The trigger says "Neues Board", the dialog names the act. */}
<span className="text-heading- font-heading- text-text-neutral-primary">{t("projects.admin.createDialog.title")}</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
{t("projects.admin.createDialog.subtitle")}
</span>
</div>
</div>
<IconButton
type="button"
variant="ghost"
size="small"
icon={<FeatherX />}
aria-label={t("projects.actions.cancel")}
onClick={() => {
setDialogOpen(false);
resetDialog();
}}
/>
</div>
<div className="flex w-full flex-col gap-4">
{createFailed ? (
<Alert
variant="error"
notDismissible
title={t("projects.admin.createDialog.createError")}
data-ui-id="ui.projects.admin.newPipeline.error"
/>
) : null}
<TextInput
className="h-auto w-full flex-none"
fillContainer
label={t("projects.admin.createDialog.nameLabel")}
showLabel
error={Boolean(createErrors.nameKey)}
message={createErrors.nameKey ? t(createErrors.nameKey) : undefined}
>
<TextInput.Input
autoFocus
value={newBoard.name}
placeholder={t("projects.admin.createDialog.namePlaceholder")}
onChange={(e) => {
setNewBoard((s) => ({ ...s, name: e.target.value }));
setCreateErrors((s) => ({ ...s, nameKey: undefined }));
}}
data-ui-id="ui.projects.admin.newPipeline.name"
/>
</TextInput>
<Select
className="h-auto w-full flex-none"
variant="outline"
icon={<FeatherLayers />}
label={t("projects.admin.createDialog.typLabel")}
showLabel
placeholder={t("projects.admin.createDialog.typPlaceholder")}
error={Boolean(createErrors.typKey)}
errorText={createErrors.typKey ? t(createErrors.typKey) : undefined}
value={newBoard.typHint}
onValueChange={(v) => {
setNewBoard((s) => ({ ...s, typHint: v }));
setCreateErrors((s) => ({ ...s, typKey: undefined }));
}}
data-ui-id="ui.projects.admin.newPipeline.typ"
>
{TYP_OPTIONS.map((typ) => (
<Select.Item key={typ} value={typ}>{t(`projects.typHint.${typ}`)}</Select.Item>
))}
</Select>
<Alert
variant="information"
notDismissible
title={t("projects.admin.createDialog.infoTitle")}
description={t("projects.admin.createDialog.infoBody")}
data-ui-id="ui.projects.admin.newPipeline.info"
/>
</div>
<div className="flex w-full items-center justify-end gap-2 mobile:flex-col-reverse mobile:items-stretch">
<Button
type="button"
className="mobile:w-full"
variant="tertiary"
icon={<FeatherX />}
onClick={() => {
setDialogOpen(false);
resetDialog();
}}
>
{t("projects.actions.cancel")}
</Button>
<Button
className="mobile:w-full"
icon={<FeatherPlus />}
disabled={!newBoard.name.trim()}
loading={props.submitting}
onClick={handleCreate}
data-ui-id="ui.projects.admin.newPipeline.create"
>
{t("projects.actions.createPipeline")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
</PageShell>
);
}
function BoardRow({ board, settingsHref, submit }: { board: PipelineAdminItem; settingsHref: string; submit: PipelineAdminSubmit }) {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
const idBase = `ui.projects.admin.row.${board.id}`;
return (
<Table.Row data-row-id={board.id} data-ui-id={idBase}>
<Table.Cell>
<div className="flex items-center gap-3">
<div className="flex h-8 w-8 flex-none items-center justify-center rounded-md border border-solid border-border-default bg-surface-neutral-tertiary text-icon-neutral-tertiary">
{BOARD_TYP_ICON[board.typHint]}
</div>
{/* The board name is the one link in the row, so it is drawn as one.
No badge next to it — which board is the default is what the footer
line under the table says. */}
<AppLink href={settingsHref} className="flex items-center gap-1 no-underline hover:underline" data-ui-id={`${idBase}.open`}>
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">{board.name}</span>
<FeatherChevronRight aria-hidden className="text-body-small-regular-0 text-text-feedback-link-default" />
</AppLink>
</div>
</Table.Cell>
<Table.Cell>
<Tag_Label tone={BOARD_TYP_TONE[board.typHint]} noAction size="small">
{t(board.typHintLabelKey)}
</Tag_Label>
</Table.Cell>
<Table.Cell>
<span className="whitespace-nowrap text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
{t("projects.boards.stagesValue", { formatted: formatters.number(board.stageCount) })}
</span>
</Table.Cell>
<Table.Cell>
<span
className={`whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 ${
board.projectCount === 0 ? "text-text-neutral-tertiary" : "text-text-neutral-primary"
}`}
data-ui-id={`${idBase}.projects`}
>
{board.projectCount}
</span>
</Table.Cell>
<Table.Cell>
<div className="flex items-center gap-1.5">
{board.access.scope === "everyone" ? (
<FeatherGlobe aria-hidden className="text-body-small-regular-0 text-icon-neutral-tertiary" />
) : (
<FeatherLock aria-hidden className="text-body-small-regular-0 text-icon-neutral-subtle" />
)}
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
{t(board.access.labelKey)}
</span>
</div>
</Table.Cell>
<Table.Cell>
<BadgeFeedback farbe={board.statusKey === "active" ? "subtle-positive" : "subtle-neutral"} size="small">
{t(`projects.boardSettings.status.${board.statusKey}`)}
</BadgeFeedback>
</Table.Cell>
{/* Export pins the action column to the right edge. */}
<Table.Cell variant="align-right">
<div className="flex w-full items-center justify-end gap-1">
<AppLink href={settingsHref} className="no-underline" data-ui-id={`${idBase}.settings`}>
<Button variant="tertiary" size="small" icon={<FeatherSettings />}>
{t("projects.admin.openSettings")}
</Button>
</AppLink>
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<IconButton
variant="ghost"
size="small"
square
icon={<FeatherMoreHorizontal />}
aria-label={t("projects.fields.actions")}
data-ui-id={`${idBase}.menu`}
/>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content align="end" sideOffset={4} asChild>
<DropdownMenu>
<DropdownMenu.DropdownItem
icon={<FeatherCopy />}
onSelect={() => submit("duplicatePipeline", { pipelineId: board.id, name: t("projects.admin.copyName", { name: board.name }) })}
data-ui-id={`${idBase}.duplicate`}
>
{t("projects.actions.duplicatePipeline")}
</DropdownMenu.DropdownItem>
<DropdownMenu.DropdownDivider />
<DropdownMenu.DropdownItem
icon={<FeatherTrash />}
onSelect={() => submit("archivePipeline", { pipelineId: board.id })}
data-ui-id={`${idBase}.archive`}
>
{t("projects.actions.archivePipeline")}
</DropdownMenu.DropdownItem>
</DropdownMenu>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
</div>
</Table.Cell>
</Table.Row>
);
}
export default PipelineAdminPage;