Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,174 @@
// AK-P3 Interim-UI (AD-28) — Notification-Center preview screen composed from
// ~/ui. Pure presentational component: renders the (live-merged) VM passed as a
// prop; mark-read/bulk-clear run through injected action callbacks (M014), the
// SSE subscription lives in the hosting route (useNotificationsStream). Final
// Subframe optics land as a tracked design-nachzug once David's D-P3 ships.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import type { NotificationCenterItemVM, NotificationCenterVM } from "@hivegrid/view-models";
import { Alert } from "~/ui/components/Alert";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { EmptyState } from "~/ui/components/EmptyState";
import { Tabs } from "~/ui/components/Tabs";
export type NotificationCenterActions = {
onMarkRead: (deliveryId: string) => void;
onMarkAllRead: () => void;
};
export type NotificationCenterPageProps = {
vm: NotificationCenterVM;
/** i18n key describing the SSE connection state (sr-only live region). */
connectionStatusKey: string;
actions: NotificationCenterActions;
};
type BadgeFarbe = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral";
function statusFarbe(status: string): BadgeFarbe {
switch (status) {
case "READ":
return "subtle-positive";
case "FAILED":
return "subtle-negative";
case "PENDING":
return "subtle-warning";
default:
return "subtle-neutral";
}
}
export function NotificationCenterPage({ vm, connectionStatusKey, actions }: NotificationCenterPageProps) {
const { t, i18n } = useTranslation();
const [activeTab, setActiveTab] = useState<"all" | "unread">("all");
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
if (vm.status !== "ready" || !vm.data) {
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.notifications.center" />;
}
const { items, totalCount, unreadCount, emptyHeadlineKey, emptyBodyKey, unreadEmptyKey } = vm.data;
const visibleItems = activeTab === "unread" ? items.filter((item) => !item.isRead) : items;
const numberFormatter = new Intl.NumberFormat(i18n.language);
return (
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.notifications.center">
{/* Header: title + subtitle (0px rhythm) */}
<div className="flex flex-col gap-0">
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("notifications.center.title")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("notifications.center.diagnostics")}
</span>
<span className="sr-only" role="status">
{t(connectionStatusKey)}
</span>
</div>
{totalCount === 0 ? (
<div data-ui-id="ui.notifications.center.empty">
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
</div>
) : (
<>
<div className="flex flex-wrap items-center justify-between gap-4">
<div className="max-w-[360px] flex-1" data-ui-id="ui.notifications.center.tabs">
<Tabs>
<Tabs.Item active={activeTab === "all"} onClick={() => setActiveTab("all")} role="tab" aria-selected={activeTab === "all"}>
{`${t("notifications.center.tabs.all")} (${numberFormatter.format(totalCount)})`}
</Tabs.Item>
<Tabs.Item
active={activeTab === "unread"}
onClick={() => setActiveTab("unread")}
role="tab"
aria-selected={activeTab === "unread"}
>
{`${t("notifications.center.tabs.unread")} (${numberFormatter.format(unreadCount)})`}
</Tabs.Item>
</Tabs>
</div>
{unreadCount > 0 ? (
<Button variant="secondary" onClick={() => actions.onMarkAllRead()} data-ui-id="ui.notifications.center.bulkClear">
{t("notifications.center.bulkClear")}
</Button>
) : null}
</div>
{visibleItems.length === 0 ? (
<div data-ui-id="ui.notifications.center.unreadEmpty">
<EmptyState title={t(unreadEmptyKey)} body={t(emptyBodyKey)} />
</div>
) : (
<ul className="flex list-none flex-col gap-4 p-0" aria-label={String(t("notifications.center.listLabel"))}>
{visibleItems.map((item) => (
<NotificationCard key={item.id} item={item} onMarkRead={actions.onMarkRead} />
))}
</ul>
)}
</>
)}
</div>
);
}
function NotificationCard({ item, onMarkRead }: { item: NotificationCenterItemVM; onMarkRead: (deliveryId: string) => void }) {
const { t, i18n } = useTranslation();
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
const messageLabel = i18n.exists(item.messageKey) ? String(t(item.messageKey)) : String(t("notifications.center.unknownMessage"));
const enumLabel = (key: string, fallbackKey: string) => (i18n.exists(key) ? String(t(key)) : String(t(fallbackKey)));
const formatTimestamp = (iso: string | null) =>
iso ? dateTimeFormatter.format(new Date(iso)) : String(t("notifications.center.timestamps.notRecorded"));
return (
<li
className="flex flex-col gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary p-4"
data-row-id={item.id}
data-read={item.isRead}
>
<div className="flex flex-wrap items-start justify-between gap-4">
<div className="flex flex-col gap-0">
{item.deeplinkHref ? (
<a
href={item.deeplinkHref}
className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default no-underline"
data-ui-id="ui.notifications.center.deeplink"
>
{messageLabel}
</a>
) : (
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{messageLabel}</span>
)}
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
{enumLabel(item.categoryKey, "notifications.center.categories.unknown")} ·{" "}
{enumLabel(item.channelKey, "notifications.center.channels.unknown")} · {formatTimestamp(item.sentAtIso ?? item.createdAtIso)}
</span>
</div>
<BadgeFeedback farbe={statusFarbe(item.status)} size="small">
{enumLabel(item.statusKey, "notifications.center.statuses.unknown")}
</BadgeFeedback>
</div>
{item.bounceKey ? (
<div data-ui-id="ui.notifications.center.bounce">
<Alert variant="error" title={t(item.bounceKey)} description={item.lastErrorRedacted ?? undefined} />
</div>
) : null}
{!item.isRead ? (
<div className="flex">
<Button
size="small"
variant="secondary"
onClick={() => onMarkRead(item.id)}
aria-label={String(t("notifications.center.markReadLabel", { message: messageLabel }))}
data-ui-id="ui.notifications.center.markRead"
>
{t("notifications.center.markRead")}
</Button>
</div>
) : null}
</li>
);
}
@@ -0,0 +1,146 @@
// AK-P3 Interim-UI (AD-28) — Notification-Settings preview screen composed from
// ~/ui (A6 settings archetype). Pure presentational component: renders the
// server-built NotificationSettingsVM passed as a prop; toggles run through
// injected action callbacks (M014) implemented fetcher-side by the hosting
// route. Final Subframe optics land as a tracked design-nachzug once David's
// D-P3 ships.
import { useTranslation } from "react-i18next";
import type { NotificationSettingChannel, NotificationSettingsVM } from "@hivegrid/view-models";
import { Alert } from "~/ui/components/Alert";
import { Switch } from "~/ui/components/Switch";
export type NotificationSettingsActions = {
onTogglePreference: (input: { category: string; channel: NotificationSettingChannel; enabled: boolean }) => void;
/** Master switch: true = turn ALL emails off (writes every category). */
onSetEmailMaster: (disableAllEmails: boolean) => void;
};
export type NotificationSettingsPageProps = {
vm: NotificationSettingsVM;
/** Plain-text result of the last save action (null = nothing saved yet). */
saveState: { ok: boolean; errorText?: string } | null;
actions: NotificationSettingsActions;
};
export function NotificationSettingsPage({ vm, saveState, actions }: NotificationSettingsPageProps) {
const { t } = useTranslation();
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
if (vm.status !== "ready" || !vm.data) {
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.settings.notifications.page" />;
}
const { groups, allEmailsDisabled } = vm.data;
return (
<div className="mx-auto flex w-full max-w-3xl flex-col gap-6 p-6" data-ui-id="ui.settings.notifications.page">
{/* Header: title + subtitle (0px rhythm) */}
<div className="flex flex-col gap-0">
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("settings.notifications.heading")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.notifications.description")}
</span>
</div>
{saveState ? (
<div data-ui-id="ui.settings.notifications.saveState">
{saveState.ok ? (
<Alert variant="success" title={t("settings.notifications.saved")} />
) : (
<Alert variant="error" title={saveState.errorText ?? t("settings.notifications.errors.invalidPreferenceAction")} />
)}
</div>
) : null}
{/* Master switch: all emails off (card surface, 16px padding) */}
<div
className="flex flex-wrap items-center justify-between gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary p-4"
data-ui-id="ui.settings.notifications.master.email"
>
<div className="flex flex-col gap-0">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{t("settings.notifications.master.heading")}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
{t("settings.notifications.master.description")}
</span>
</div>
<label className="flex items-center gap-2">
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
{t("settings.notifications.master.disableAllEmails")}
</span>
<Switch
checked={allEmailsDisabled}
onCheckedChange={(checked: boolean) => actions.onSetEmailMaster(checked)}
data-ui-id="ui.settings.notifications.master.switch"
/>
</label>
</div>
{/* Event types grouped per module (A6) */}
<div className="flex flex-col gap-4">
{groups.map((group) => (
<div
key={group.module}
className="flex flex-col rounded-md border border-solid border-border-default bg-surface-neutral-primary"
data-ui-id={`ui.settings.notifications.module.${group.module}`}
>
<span className="border-b border-solid border-border-default px-4 py-2 text-body-small-medium-0 font-body-small-medium-0 uppercase text-text-neutral-tertiary">
{t(group.moduleLabelKey)}
</span>
{group.categories.map((category) => (
<div
key={category.category}
className="flex flex-wrap items-center justify-between gap-4 p-4"
data-ui-id={`ui.settings.notifications.category.${category.category}`}
>
<div className="flex flex-col gap-0">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{t(category.labelKey)}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
{t("settings.notifications.categoryDescription", { category: String(t(category.labelKey)).toLowerCase() })}
</span>
</div>
<div className="flex flex-wrap items-center gap-4">
<ChannelToggle
label={t("settings.notifications.channels.inApp")}
checked={category.channels.IN_APP}
uiId={`ui.settings.notifications.preference.${category.category}.in_app`}
onChange={(enabled) => actions.onTogglePreference({ category: category.category, channel: "IN_APP", enabled })}
/>
<ChannelToggle
label={t("settings.notifications.channels.email")}
checked={category.channels.EMAIL}
uiId={`ui.settings.notifications.preference.${category.category}.email`}
onChange={(enabled) => actions.onTogglePreference({ category: category.category, channel: "EMAIL", enabled })}
/>
</div>
</div>
))}
</div>
))}
</div>
</div>
);
}
function ChannelToggle({
label,
checked,
uiId,
onChange,
}: {
label: string;
checked: boolean;
uiId: string;
onChange: (enabled: boolean) => void;
}) {
return (
<label className="flex items-center gap-2" data-ui-id={uiId}>
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{label}</span>
<Switch checked={checked} onCheckedChange={onChange} />
</label>
);
}
@@ -0,0 +1,59 @@
import { vi, describe, it, expect } from "vitest";
import "@testing-library/jest-dom";
import { fireEvent, render } from "@testing-library/react";
import { toNotificationCenterItemVM, type NotificationCenterItemVM } from "@hivegrid/view-models";
import { NotificationsDrawer } from "./NotificationsDrawer";
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (str: string) => str,
i18n: { language: "de", exists: (key: string) => key === "team.invite.created" },
}),
}));
function item(overrides: Partial<Parameters<typeof toNotificationCenterItemVM>[0]> = {}): NotificationCenterItemVM {
return toNotificationCenterItemVM({
id: "delivery_1",
messageKey: "team.invite.created",
category: "team",
channel: "IN_APP",
status: "SENT",
attemptsMade: 1,
createdAtIso: "2026-07-01T10:00:00.000Z",
sentAtIso: "2026-07-01T10:01:00.000Z",
...overrides,
});
}
describe("NotificationsDrawer (interim-UI)", () => {
it("renders items with unread badge and deeplink when open", () => {
render(
<NotificationsDrawer
open
items={[item({ payloadMetadata: { deeplink: "/acme/settings/members" } }), item({ id: "d2", status: "READ" })]}
allHref="/acme/notifications"
onClose={vi.fn()}
/>,
);
expect(document.querySelector('[data-ui-id="ui.notifications.drawer"]')).toBeInTheDocument();
expect(document.querySelector('[data-row-id="delivery_1"]')).toHaveAttribute("data-read", "false");
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.deeplink"]')).toHaveAttribute("href", "/acme/settings/members");
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.showAll"]')).toHaveAttribute("href", "/acme/notifications");
});
it("shows the empty state and closes via the close button", () => {
const onClose = vi.fn();
render(<NotificationsDrawer open items={[]} allHref="/acme/notifications" onClose={onClose} />);
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.empty"]')).toBeInTheDocument();
fireEvent.click(document.querySelector('[data-ui-id="ui.notifications.drawer.close"]')!);
expect(onClose).toHaveBeenCalledTimes(1);
});
it("renders nothing visible when closed", () => {
render(<NotificationsDrawer open={false} items={[item()]} allHref="/acme/notifications" onClose={vi.fn()} />);
expect(document.querySelector('[data-ui-id="ui.notifications.drawer"]')).not.toBeInTheDocument();
});
});
@@ -0,0 +1,105 @@
// AK-P3 Interim-UI (AD-28) — topbar notifications drawer composed from ~/ui
// (real Drawer, not a card fake — D07). Pure presentational: the host (NavBar)
// owns the SSE subscription and open state; items arrive as VM props, clicks
// follow validated deeplinks. Final Subframe optics land as a tracked
// design-nachzug once David's D-P3 ships.
import { useTranslation } from "react-i18next";
import type { NotificationCenterItemVM } from "@hivegrid/view-models";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { Drawer } from "~/ui/components/Drawer";
import { EmptyState } from "~/ui/components/EmptyState";
const DRAWER_MAX_ITEMS = 10;
export type NotificationsDrawerProps = {
open: boolean;
items: readonly NotificationCenterItemVM[];
/** Href of the full notification center route ("show all"). */
allHref: string;
onClose: () => void;
};
export function NotificationsDrawer({ open, items, allHref, onClose }: NotificationsDrawerProps) {
const { t, i18n } = useTranslation();
const visibleItems = items.slice(0, DRAWER_MAX_ITEMS);
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "short", timeStyle: "short" });
return (
<Drawer open={open} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onClose())}>
<Drawer.Content>
<div className="flex w-96 max-w-full flex-col gap-6 p-6" data-ui-id="ui.notifications.drawer">
<div className="flex items-start justify-between gap-4">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("notifications.center.drawer.title")}</span>
<Button variant="tertiary" size="small" onClick={onClose} data-ui-id="ui.notifications.drawer.close">
{t("notifications.center.drawer.close")}
</Button>
</div>
{visibleItems.length === 0 ? (
<div data-ui-id="ui.notifications.drawer.empty">
<EmptyState title={t("notifications.center.drawer.empty")} body={t("notifications.center.emptyHelper")} />
</div>
) : (
<ul className="flex list-none flex-col gap-3 p-0" aria-label={String(t("notifications.center.listLabel"))}>
{visibleItems.map((item) => (
<DrawerItem key={item.id} item={item} formatter={dateTimeFormatter} />
))}
</ul>
)}
<div className="flex justify-end">
<a href={allHref} className="no-underline" data-ui-id="ui.notifications.drawer.showAll">
<Button variant="secondary">{t("notifications.center.drawer.showAll")}</Button>
</a>
</div>
</div>
</Drawer.Content>
</Drawer>
);
}
function DrawerItem({ item, formatter }: { item: NotificationCenterItemVM; formatter: Intl.DateTimeFormat }) {
const { t, i18n } = useTranslation();
const messageLabel = i18n.exists(item.messageKey) ? String(t(item.messageKey)) : String(t("notifications.center.unknownMessage"));
const timestampIso = item.sentAtIso ?? item.createdAtIso;
const body = (
<div className="flex flex-col gap-0">
<span
className={
item.isRead
? "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"
: "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"
}
>
{messageLabel}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
{timestampIso ? formatter.format(new Date(timestampIso)) : String(t("notifications.center.timestamps.notRecorded"))}
</span>
</div>
);
return (
<li
className="flex items-start justify-between gap-3 rounded-md border border-solid border-border-default p-3"
data-row-id={item.id}
data-read={item.isRead}
>
{item.deeplinkHref ? (
<a href={item.deeplinkHref} className="no-underline" data-ui-id="ui.notifications.drawer.deeplink">
{body}
</a>
) : (
body
)}
{!item.isRead ? (
<BadgeFeedback farbe="subtle-warning" size="small">
{t("notifications.center.statuses.unread")}
</BadgeFeedback>
) : null}
</li>
);
}