391 lines
18 KiB
TypeScript
391 lines
18 KiB
TypeScript
// WF-P8 S00 "Boards-Startseite" — rebuilt against Davids Subframe export of
|
|
// 2026-07-28 (page 1778cf5e-777b-439c-81b6-c51f85283cc4) plus the local
|
|
// wireframe doc, which is the authoritative copy for this nachzug.
|
|
//
|
|
// Pure/presentational: renders the server-built BoardsStartData; search and the
|
|
// three facet filters are client-side (the board list is small). Usable boards
|
|
// navigate via links; locked boards (deny-based PipelineAccess rule) stay
|
|
// visible per the design — greyed out, no links, with a "request access" action
|
|
// that the route wires to a POST. No useLoaderData/useFetcher, no server
|
|
// imports, plain document flow (the app shell's <main> scrolls).
|
|
//
|
|
// Deltas against the export that are deliberate, not oversights:
|
|
// * The Status facet offers Aktiv/Gesperrt only. "Entwurf"/"Archiviert" have
|
|
// no board state behind them (archived boards are not listed at all), and a
|
|
// filter option that can never match is worse than an absent one.
|
|
// * The Zugriff facet offers Freigegeben/Freigabe nötig. The export's third
|
|
// option "Nur ich" needs an owner concept that PipelineAccess does not have.
|
|
// * Board icons are derived from the board type. Pipeline carries no icon
|
|
// column, and inventing one per board would be data we do not have.
|
|
|
|
import { useMemo, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import {
|
|
FeatherActivity,
|
|
FeatherCheckCircle,
|
|
FeatherChevronRight,
|
|
FeatherFilter,
|
|
FeatherKanbanSquare,
|
|
FeatherLock,
|
|
FeatherPlus,
|
|
FeatherSettings,
|
|
FeatherUnlockKeyhole,
|
|
FeatherXCircle,
|
|
} from "@subframe/core";
|
|
import { BOARD_TYP_ICON, BOARD_TYP_TONE } from "./boardTypeVisuals";
|
|
import type { BoardsStartData, BoardsStartRowVM, BoardsStartTypHint } from "@hivegrid/view-models";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { AppLink } from "~/components/app/AppLink";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { IconButton } from "~/ui/components/IconButton";
|
|
import { Table } from "~/ui/components/Table";
|
|
import { Tag_Label } from "~/ui/components/Tag_Label";
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import { FacetFilterBar, type ClientFacet } from "../shared/FacetFilterBar";
|
|
import { PAGE_HEADER_ICON_CLASS, PageHeader, PageShell } from "../shared/PageShell";
|
|
|
|
export type BoardsStartPageProps = {
|
|
data: BoardsStartData;
|
|
/** Route-injected action callbacks (M014 shape) — the screen never posts itself. */
|
|
actions: {
|
|
onRequestAccess: (pipelineId: string) => void;
|
|
};
|
|
/** Disables the request-access buttons while a submission is in flight. */
|
|
submitting?: boolean;
|
|
};
|
|
|
|
export type BoardsStartTypFilter = BoardsStartTypHint;
|
|
export type BoardsStartAccessFilter = "granted" | "requestable";
|
|
export type BoardsStartStatusFilter = "active" | "locked";
|
|
|
|
const TYP_VALUES: readonly BoardsStartTypFilter[] = ["sales", "auftrag", "custom"];
|
|
const ACCESS_VALUES: readonly BoardsStartAccessFilter[] = ["granted", "requestable"];
|
|
const STATUS_VALUES: readonly BoardsStartStatusFilter[] = ["active", "locked"];
|
|
|
|
/** Muted styling for locked (greyed-out) board rows. */
|
|
const LOCKED_CELL_CLASS = "opacity-60";
|
|
|
|
// Board type → icon tile / tag tone. Shared with the S07 board table; Pipeline
|
|
// has no icon column, the type is what we know.
|
|
const TYP_ICON = BOARD_TYP_ICON;
|
|
const TYP_TONE = BOARD_TYP_TONE;
|
|
|
|
export type BoardsStartFilters = {
|
|
readonly search: string;
|
|
/** Empty set = facet not filtered. Several values in one facet are OR-ed. */
|
|
readonly typ: ReadonlySet<string>;
|
|
readonly access: ReadonlySet<string>;
|
|
readonly status: ReadonlySet<string>;
|
|
};
|
|
|
|
/**
|
|
* Client-side facet filter, exported so it can be tested as a plain function.
|
|
* The facet menus are Radix widgets that jsdom cannot drive, so asserting the
|
|
* behaviour through the rendered dropdown would test the widget, not the rule.
|
|
*/
|
|
export function filterBoardRows(
|
|
rows: readonly BoardsStartRowVM[],
|
|
filters: BoardsStartFilters
|
|
): readonly BoardsStartRowVM[] {
|
|
const q = filters.search.trim().toLowerCase();
|
|
return rows.filter((row) => {
|
|
if (filters.typ.size > 0 && !filters.typ.has(row.typHint)) return false;
|
|
if (filters.access.size > 0 && !filters.access.has(row.locked ? "requestable" : "granted")) return false;
|
|
if (filters.status.size > 0 && !filters.status.has(row.locked ? "locked" : "active")) return false;
|
|
if (q && !row.name.toLowerCase().includes(q)) return false;
|
|
return true;
|
|
});
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
export function BoardsStartPage(props: BoardsStartPageProps) {
|
|
const { t } = useTranslation();
|
|
const { number } = useLocaleFormatters();
|
|
const { data, actions, submitting = false } = props;
|
|
|
|
const [search, setSearch] = useState("");
|
|
const [typ, setTyp] = useState<ReadonlySet<string>>(EMPTY_SELECTION);
|
|
const [access, setAccess] = useState<ReadonlySet<string>>(EMPTY_SELECTION);
|
|
const [status, setStatus] = useState<ReadonlySet<string>>(EMPTY_SELECTION);
|
|
|
|
const rows = useMemo(
|
|
() => filterBoardRows(data.rows, { search, typ, access, status }),
|
|
[data.rows, search, typ, access, status]
|
|
);
|
|
|
|
const facets: ClientFacet[] = [
|
|
{
|
|
key: "typ",
|
|
label: t("projects.boards.columns.typ"),
|
|
icon: <FeatherFilter />,
|
|
selected: typ,
|
|
options: TYP_VALUES.map((value) => ({ value, label: t(`projects.typHint.${value}`), tone: TYP_TONE[value] })),
|
|
},
|
|
{
|
|
key: "access",
|
|
label: t("projects.boards.columns.access"),
|
|
icon: <FeatherLock />,
|
|
tone: "blue-subtle",
|
|
selected: access,
|
|
options: ACCESS_VALUES.map((value) => ({ value, label: t(`projects.boards.access.${value}`) })),
|
|
},
|
|
{
|
|
key: "status",
|
|
label: t("projects.boards.columns.status"),
|
|
icon: <FeatherActivity />,
|
|
tone: "sky-subtle",
|
|
selected: status,
|
|
options: STATUS_VALUES.map((value) => ({
|
|
value,
|
|
label: value === "active" ? t("projects.boards.status.usable") : t("projects.boards.status.locked"),
|
|
})),
|
|
},
|
|
];
|
|
|
|
const FACET_SETTERS: Record<string, (value: string) => void> = {
|
|
typ: (value) => setTyp((current) => toggleValue(current, value)),
|
|
access: (value) => setAccess((current) => toggleValue(current, value)),
|
|
status: (value) => setStatus((current) => toggleValue(current, value)),
|
|
};
|
|
|
|
function resetFilters() {
|
|
setSearch("");
|
|
setTyp(EMPTY_SELECTION);
|
|
setAccess(EMPTY_SELECTION);
|
|
setStatus(EMPTY_SELECTION);
|
|
}
|
|
|
|
function renderAccessCell(row: BoardsStartRowVM) {
|
|
if (!row.locked) {
|
|
return (
|
|
<div className="flex items-center gap-1.5">
|
|
<FeatherCheckCircle className="text-body-small-regular-0 text-icon-feedback-positive" aria-hidden />
|
|
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
|
|
{t("projects.boards.access.granted")}
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|
|
return (
|
|
<div className="flex items-center gap-1.5">
|
|
<FeatherLock className="text-body-small-regular-0 text-icon-neutral-subtle" aria-hidden />
|
|
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
|
{row.requestPending ? t("projects.boards.access.pending") : t("projects.boards.locked.noPermission")}
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function renderActionCell(row: BoardsStartRowVM) {
|
|
// The row gear opens this board's settings (S04). It stays available on
|
|
// locked boards for admins — configuring a board is an admin capability,
|
|
// not a "can I work on it" capability.
|
|
const gear = row.settingsHref ? (
|
|
<AppLink href={row.settingsHref} aria-label={t("projects.boards.actions.boardSettings")} data-ui-id={`ui.projects.boards.settings.${row.id}`}>
|
|
<IconButton variant="ghost" size="small" icon={<FeatherSettings />} />
|
|
</AppLink>
|
|
) : null;
|
|
|
|
if (!row.locked) {
|
|
return (
|
|
<div className="flex items-center justify-end gap-1">
|
|
{row.openHref ? (
|
|
<AppLink href={row.openHref}>
|
|
<Button variant="tertiary" size="small" iconRight={<FeatherChevronRight />} data-ui-id={`ui.projects.boards.openButton.${row.id}`}>
|
|
{t("projects.boards.actions.open")}
|
|
</Button>
|
|
</AppLink>
|
|
) : null}
|
|
{gear}
|
|
</div>
|
|
);
|
|
}
|
|
return (
|
|
<div className="flex items-center justify-end gap-1">
|
|
{row.requestPending ? (
|
|
// No dead button: a pending request renders as a plain status badge.
|
|
<BadgeFeedback farbe="subtle-information" size="small" data-ui-id={`ui.projects.boards.requestPending.${row.id}`}>
|
|
{t("projects.boards.locked.requestPending")}
|
|
</BadgeFeedback>
|
|
) : (
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherUnlockKeyhole />}
|
|
disabled={submitting}
|
|
onClick={() => actions.onRequestAccess(row.id)}
|
|
data-ui-id={`ui.projects.boards.requestAccess.${row.id}`}
|
|
>
|
|
{t("projects.boards.locked.requestAccess")}
|
|
</Button>
|
|
)}
|
|
{gear}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<PageShell uiId="ui.projects.boards">
|
|
<PageHeader
|
|
icon={<FeatherKanbanSquare className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("projects.boards.title")}
|
|
subtitle={t("projects.boards.subtitle")}
|
|
actions={
|
|
data.canAdmin ? (
|
|
<>
|
|
{data.adminHref ? (
|
|
<AppLink href={data.adminHref} data-ui-id="ui.projects.boards.adminSettings">
|
|
<Button variant="tertiary" icon={<FeatherSettings />}>{t("projects.boards.actions.adminSettings")}</Button>
|
|
</AppLink>
|
|
) : null}
|
|
{data.lostReasonsHref ? (
|
|
<AppLink href={data.lostReasonsHref} data-ui-id="ui.projects.boards.lostReasons">
|
|
<Button variant="tertiary" icon={<FeatherXCircle />}>{t("projects.boards.actions.lostReasons")}</Button>
|
|
</AppLink>
|
|
) : null}
|
|
{data.newBoardHref ? (
|
|
<AppLink href={data.newBoardHref} data-ui-id="ui.projects.boards.newBoard">
|
|
<Button variant="primary" icon={<FeatherPlus />}>{t("projects.boards.actions.newBoard")}</Button>
|
|
</AppLink>
|
|
) : null}
|
|
</>
|
|
) : undefined
|
|
}
|
|
/>
|
|
|
|
{data.rows.length === 0 ? (
|
|
<div className="w-full p-6" data-ui-id="ui.projects.boards.empty">
|
|
<EmptyState
|
|
title={t("projects.boards.emptyTitle")}
|
|
body={data.canAdmin ? t("projects.boards.emptyAdminHint") : t("projects.boards.emptyReaderHint")}
|
|
action={
|
|
data.canAdmin && data.newBoardHref ? (
|
|
<AppLink href={data.newBoardHref} data-ui-id="ui.projects.boards.empty.newBoard">
|
|
<Button variant="primary" icon={<FeatherPlus />}>{t("projects.boards.actions.newBoard")}</Button>
|
|
</AppLink>
|
|
) : undefined
|
|
}
|
|
/>
|
|
</div>
|
|
) : (
|
|
<>
|
|
{/* --- Filter bar (S00: Typ / Zugriff / Status) --- */}
|
|
<FacetFilterBar
|
|
uiId="ui.projects.boards.filter"
|
|
facets={facets}
|
|
onToggle={(facetKey, value) => FACET_SETTERS[facetKey]?.(value)}
|
|
search={search}
|
|
onSearchChange={setSearch}
|
|
searchPlaceholder={t("projects.boards.searchPlaceholder")}
|
|
onReset={resetFilters}
|
|
labels={{ reset: t("projects.board.filter.reset"), removeChip: t("projects.board.filter.removeChip") }}
|
|
trailing={
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary" data-ui-id="ui.projects.boards.count">
|
|
{data.lockedCount > 0
|
|
? t("projects.boards.countLineWithLocked", { total: number(data.totalCount), usable: number(data.usableCount), locked: number(data.lockedCount) })
|
|
: t("projects.boards.countLine", { total: number(data.totalCount), usable: number(data.usableCount) })}
|
|
</span>
|
|
}
|
|
/>
|
|
|
|
{/* --- Boards table (the ~/ui Table ignores its emptyText prop, so the
|
|
no-matches state is rendered explicitly below) --- */}
|
|
{rows.length === 0 ? (
|
|
<div className="w-full px-6 pt-4 pb-6 mobile:px-4" data-ui-id="ui.projects.boards.noMatches">
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-tertiary">{t("projects.boards.noMatches")}</span>
|
|
</div>
|
|
) : (
|
|
<div className="w-full px-6 pt-4 pb-6 mobile:px-4">
|
|
<div className="w-full overflow-x-auto rounded-lg border border-solid border-border-default shadow-sm">
|
|
<Table
|
|
data-ui-id="ui.projects.boards.table"
|
|
header={
|
|
<Table.HeaderRow className="bg-surface-neutral-tertiary">
|
|
<Table.HeaderCell>{t("projects.boards.columns.board")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("projects.boards.columns.typ")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("projects.boards.columns.stages")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("projects.boards.columns.projects")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("projects.boards.columns.access")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("projects.boards.columns.status")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("projects.boards.columns.action")}</Table.HeaderCell>
|
|
</Table.HeaderRow>
|
|
}
|
|
>
|
|
{rows.map((row) => (
|
|
<Table.Row key={row.id} data-row-id={row.id} className={row.locked ? "bg-surface-neutral-tertiary" : undefined}>
|
|
<Table.Cell className={row.locked ? LOCKED_CELL_CLASS : undefined}>
|
|
<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-body-default-regular-0 text-icon-neutral-tertiary">
|
|
{TYP_ICON[row.typHint]}
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
{row.locked ? (
|
|
<>
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-tertiary" data-ui-id={`ui.projects.boards.lockedName.${row.id}`}>
|
|
{row.name}
|
|
</span>
|
|
<FeatherLock className="text-body-small-regular-0 text-icon-neutral-subtle" aria-hidden />
|
|
</>
|
|
) : (
|
|
<AppLink href={row.openHref!} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default" data-ui-id={`ui.projects.boards.open.${row.id}`}>
|
|
{row.name}
|
|
</AppLink>
|
|
)}
|
|
{row.isDefault ? (
|
|
<BadgeFeedback farbe="subtle-information" size="small">{t("projects.boards.defaultBadge")}</BadgeFeedback>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</Table.Cell>
|
|
<Table.Cell className={row.locked ? LOCKED_CELL_CLASS : undefined}>
|
|
<Tag_Label tone={row.locked ? "neutral-subtle" : TYP_TONE[row.typHint]} noAction size="small">
|
|
{t(row.typLabelKey)}
|
|
</Tag_Label>
|
|
</Table.Cell>
|
|
<Table.Cell className={row.locked ? LOCKED_CELL_CLASS : undefined}>
|
|
<span className="whitespace-nowrap text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
|
{t("projects.boards.stagesValue", { count: row.stageCount, formatted: number(row.stageCount) })}
|
|
</span>
|
|
</Table.Cell>
|
|
<Table.Cell className={row.locked ? LOCKED_CELL_CLASS : undefined}>
|
|
<span className="whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">{number(row.projectCount)}</span>
|
|
</Table.Cell>
|
|
<Table.Cell className={row.locked ? LOCKED_CELL_CLASS : undefined}>{renderAccessCell(row)}</Table.Cell>
|
|
<Table.Cell className={row.locked ? LOCKED_CELL_CLASS : undefined}>
|
|
<BadgeFeedback farbe={row.locked ? "subtle-neutral" : "subtle-positive"} size="small">
|
|
{row.locked ? t("projects.boards.status.locked") : t("projects.boards.status.usable")}
|
|
</BadgeFeedback>
|
|
</Table.Cell>
|
|
{/* Export pins the action column to the right edge. */}
|
|
<Table.Cell variant="align-right">{renderActionCell(row)}</Table.Cell>
|
|
</Table.Row>
|
|
))}
|
|
</Table>
|
|
</div>
|
|
{/* Footer line from the export: makes the locked rows self-explaining. */}
|
|
<div className="flex w-full items-center gap-3 pt-3 mobile:flex-col mobile:items-start" data-ui-id="ui.projects.boards.footer">
|
|
<span className="grow shrink-0 basis-0 text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
|
{data.lockedCount > 0
|
|
? t("projects.boards.footerLineWithLocked", { count: data.totalCount, formatted: number(data.totalCount) })
|
|
: t("projects.boards.footerLine", { count: data.totalCount, formatted: number(data.totalCount) })}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
export default BoardsStartPage;
|