2026-04-21 10:05:39 +02:00
|
|
|
import { useMemo, useState } from 'react';
|
|
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
import { Inbox } from 'lucide-react';
|
|
|
|
|
import {
|
fix(alerts/ui): page header, scroll, title preview, bell badge polish
Visual regressions surfaced during browser smoke:
1. Page headers — `SectionHeader` renders as 12px uppercase gray (a
section divider, not a page title). Replace with proper h2 title
+ inline subtitle (`N firing · N total` etc.) and right-aligned
actions, styled from `alerts-page.module.css`.
2. Undefined `--space-*` tokens — the project (and `@cameleer/design-system`)
has never shipped `--space-sm|md|lg|xl`, even though many modules
(SensitiveKeysPage, alerts CSS, …) reference them. The fallback
to `initial` silently collapsed gaps/paddings to 0. Define the
scale in `ui/src/index.css` so every consumer picks it up.
3. List scrolling — DataTable was using default pagination, but with
no flex sizing the whole page scrolled. Add `fillHeight` and raise
`pageSize`/list `limit` to 200 so the table gets sticky header +
internal scroll + pinned pagination footer (Gmail-style). True
cursor-based infinite scroll needs a backend change (filed as
follow-up — `/alerts` only accepts `limit` today).
4. Title column clipping — `.titlePreview` used `white-space: nowrap`
+ fixed `max-width`, truncating message mid-UUID. Switch to a
2-line `-webkit-line-clamp` so full context is visible.
5. Notification bell badge invisible — `NotificationBell.module.css`
referenced undefined tokens (`--fg`, `--hover-bg`, `--bg`,
`--muted`). Map to real DS tokens (`--text-primary`, `--bg-hover`,
`#fff`, `--text-muted`). The admin user currently sees no badge
because the backend `/alerts/unread-count` returns 0 (read
receipts) — that's data, not UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 10:40:28 +02:00
|
|
|
Button, DataTable, EmptyState, useToast,
|
2026-04-21 10:05:39 +02:00
|
|
|
} from '@cameleer/design-system';
|
|
|
|
|
import type { Column } from '@cameleer/design-system';
|
2026-04-20 13:49:23 +02:00
|
|
|
import { PageLoader } from '../../components/PageLoader';
|
2026-04-21 10:05:39 +02:00
|
|
|
import { SeverityBadge } from '../../components/SeverityBadge';
|
|
|
|
|
import { AlertStateChip } from '../../components/AlertStateChip';
|
|
|
|
|
import {
|
|
|
|
|
useAlerts, useAckAlert, useBulkReadAlerts, useMarkAlertRead,
|
|
|
|
|
type AlertDto,
|
|
|
|
|
} from '../../api/queries/alerts';
|
|
|
|
|
import { severityToAccent } from './severity-utils';
|
|
|
|
|
import { formatRelativeTime } from './time-utils';
|
|
|
|
|
import { renderAlertExpanded } from './alert-expanded';
|
2026-04-20 13:49:23 +02:00
|
|
|
import css from './alerts-page.module.css';
|
2026-04-21 10:05:39 +02:00
|
|
|
import tableStyles from '../../styles/table-section.module.css';
|
2026-04-20 13:49:23 +02:00
|
|
|
|
2026-04-20 13:44:44 +02:00
|
|
|
export default function InboxPage() {
|
fix(alerts/ui): page header, scroll, title preview, bell badge polish
Visual regressions surfaced during browser smoke:
1. Page headers — `SectionHeader` renders as 12px uppercase gray (a
section divider, not a page title). Replace with proper h2 title
+ inline subtitle (`N firing · N total` etc.) and right-aligned
actions, styled from `alerts-page.module.css`.
2. Undefined `--space-*` tokens — the project (and `@cameleer/design-system`)
has never shipped `--space-sm|md|lg|xl`, even though many modules
(SensitiveKeysPage, alerts CSS, …) reference them. The fallback
to `initial` silently collapsed gaps/paddings to 0. Define the
scale in `ui/src/index.css` so every consumer picks it up.
3. List scrolling — DataTable was using default pagination, but with
no flex sizing the whole page scrolled. Add `fillHeight` and raise
`pageSize`/list `limit` to 200 so the table gets sticky header +
internal scroll + pinned pagination footer (Gmail-style). True
cursor-based infinite scroll needs a backend change (filed as
follow-up — `/alerts` only accepts `limit` today).
4. Title column clipping — `.titlePreview` used `white-space: nowrap`
+ fixed `max-width`, truncating message mid-UUID. Switch to a
2-line `-webkit-line-clamp` so full context is visible.
5. Notification bell badge invisible — `NotificationBell.module.css`
referenced undefined tokens (`--fg`, `--hover-bg`, `--bg`,
`--muted`). Map to real DS tokens (`--text-primary`, `--bg-hover`,
`#fff`, `--text-muted`). The admin user currently sees no badge
because the backend `/alerts/unread-count` returns 0 (read
receipts) — that's data, not UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 10:40:28 +02:00
|
|
|
const { data, isLoading, error } = useAlerts({ state: ['FIRING', 'ACKNOWLEDGED'], limit: 200 });
|
2026-04-20 13:49:23 +02:00
|
|
|
const bulkRead = useBulkReadAlerts();
|
2026-04-21 10:05:39 +02:00
|
|
|
const markRead = useMarkAlertRead();
|
|
|
|
|
const ack = useAckAlert();
|
2026-04-20 13:49:23 +02:00
|
|
|
const { toast } = useToast();
|
|
|
|
|
|
2026-04-21 10:05:39 +02:00
|
|
|
const [selected, setSelected] = useState<Set<string>>(new Set());
|
|
|
|
|
const rows = data ?? [];
|
|
|
|
|
|
2026-04-20 13:49:23 +02:00
|
|
|
const unreadIds = useMemo(
|
2026-04-21 10:05:39 +02:00
|
|
|
() => rows.filter((a) => a.state === 'FIRING').map((a) => a.id),
|
|
|
|
|
[rows],
|
2026-04-20 13:49:23 +02:00
|
|
|
);
|
|
|
|
|
|
2026-04-21 10:05:39 +02:00
|
|
|
const toggleSelected = (id: string) => {
|
|
|
|
|
setSelected((prev) => {
|
|
|
|
|
const next = new Set(prev);
|
|
|
|
|
if (next.has(id)) next.delete(id); else next.add(id);
|
|
|
|
|
return next;
|
|
|
|
|
});
|
|
|
|
|
};
|
2026-04-20 13:49:23 +02:00
|
|
|
|
2026-04-21 10:05:39 +02:00
|
|
|
const onAck = async (id: string, title?: string) => {
|
|
|
|
|
try {
|
|
|
|
|
await ack.mutateAsync(id);
|
|
|
|
|
toast({ title: 'Acknowledged', description: title, variant: 'success' });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast({ title: 'Ack failed', description: String(e), variant: 'error' });
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-04-20 13:49:23 +02:00
|
|
|
|
2026-04-21 10:05:39 +02:00
|
|
|
const onBulkRead = async (ids: string[]) => {
|
|
|
|
|
if (ids.length === 0) return;
|
2026-04-20 13:49:23 +02:00
|
|
|
try {
|
2026-04-21 10:05:39 +02:00
|
|
|
await bulkRead.mutateAsync(ids);
|
|
|
|
|
setSelected(new Set());
|
|
|
|
|
toast({ title: `Marked ${ids.length} as read`, variant: 'success' });
|
2026-04-20 13:49:23 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
toast({ title: 'Bulk read failed', description: String(e), variant: 'error' });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-21 10:05:39 +02:00
|
|
|
const columns: Column<AlertDto>[] = [
|
|
|
|
|
{
|
|
|
|
|
key: 'select', header: '', width: '40px',
|
|
|
|
|
render: (_, row) => (
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={selected.has(row.id)}
|
|
|
|
|
onChange={() => toggleSelected(row.id)}
|
|
|
|
|
aria-label={`Select ${row.title ?? row.id}`}
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'severity', header: 'Severity', width: '110px',
|
|
|
|
|
render: (_, row) =>
|
|
|
|
|
row.severity ? <SeverityBadge severity={row.severity} /> : null,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'state', header: 'State', width: '140px',
|
|
|
|
|
render: (_, row) =>
|
|
|
|
|
row.state ? <AlertStateChip state={row.state} silenced={row.silenced} /> : null,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'title', header: 'Title',
|
|
|
|
|
render: (_, row) => {
|
|
|
|
|
const unread = row.state === 'FIRING';
|
|
|
|
|
return (
|
|
|
|
|
<div className={`${css.titleCell} ${unread ? css.titleCellUnread : ''}`}>
|
|
|
|
|
<Link to={`/alerts/inbox/${row.id}`} onClick={() => markRead.mutate(row.id)}>
|
|
|
|
|
{row.title ?? '(untitled)'}
|
|
|
|
|
</Link>
|
|
|
|
|
{row.message && <span className={css.titlePreview}>{row.message}</span>}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'age', header: 'Age', width: '100px', sortable: true,
|
|
|
|
|
render: (_, row) =>
|
|
|
|
|
row.firedAt ? (
|
|
|
|
|
<span title={row.firedAt} style={{ fontVariantNumeric: 'tabular-nums' }}>
|
|
|
|
|
{formatRelativeTime(row.firedAt)}
|
|
|
|
|
</span>
|
|
|
|
|
) : '—',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'ack', header: '', width: '70px',
|
|
|
|
|
render: (_, row) =>
|
|
|
|
|
row.state === 'FIRING' ? (
|
|
|
|
|
<Button size="sm" variant="secondary" onClick={() => onAck(row.id, row.title ?? undefined)}>
|
|
|
|
|
Ack
|
|
|
|
|
</Button>
|
|
|
|
|
) : null,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (isLoading) return <PageLoader />;
|
|
|
|
|
if (error) return <div className={css.page}>Failed to load alerts: {String(error)}</div>;
|
|
|
|
|
|
|
|
|
|
const selectedIds = Array.from(selected);
|
|
|
|
|
|
fix(alerts/ui): page header, scroll, title preview, bell badge polish
Visual regressions surfaced during browser smoke:
1. Page headers — `SectionHeader` renders as 12px uppercase gray (a
section divider, not a page title). Replace with proper h2 title
+ inline subtitle (`N firing · N total` etc.) and right-aligned
actions, styled from `alerts-page.module.css`.
2. Undefined `--space-*` tokens — the project (and `@cameleer/design-system`)
has never shipped `--space-sm|md|lg|xl`, even though many modules
(SensitiveKeysPage, alerts CSS, …) reference them. The fallback
to `initial` silently collapsed gaps/paddings to 0. Define the
scale in `ui/src/index.css` so every consumer picks it up.
3. List scrolling — DataTable was using default pagination, but with
no flex sizing the whole page scrolled. Add `fillHeight` and raise
`pageSize`/list `limit` to 200 so the table gets sticky header +
internal scroll + pinned pagination footer (Gmail-style). True
cursor-based infinite scroll needs a backend change (filed as
follow-up — `/alerts` only accepts `limit` today).
4. Title column clipping — `.titlePreview` used `white-space: nowrap`
+ fixed `max-width`, truncating message mid-UUID. Switch to a
2-line `-webkit-line-clamp` so full context is visible.
5. Notification bell badge invisible — `NotificationBell.module.css`
referenced undefined tokens (`--fg`, `--hover-bg`, `--bg`,
`--muted`). Map to real DS tokens (`--text-primary`, `--bg-hover`,
`#fff`, `--text-muted`). The admin user currently sees no badge
because the backend `/alerts/unread-count` returns 0 (read
receipts) — that's data, not UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 10:40:28 +02:00
|
|
|
const subtitle =
|
|
|
|
|
selectedIds.length > 0
|
|
|
|
|
? `${selectedIds.length} selected`
|
|
|
|
|
: `${unreadIds.length} firing · ${rows.length} total`;
|
|
|
|
|
|
2026-04-20 13:49:23 +02:00
|
|
|
return (
|
|
|
|
|
<div className={css.page}>
|
fix(alerts/ui): page header, scroll, title preview, bell badge polish
Visual regressions surfaced during browser smoke:
1. Page headers — `SectionHeader` renders as 12px uppercase gray (a
section divider, not a page title). Replace with proper h2 title
+ inline subtitle (`N firing · N total` etc.) and right-aligned
actions, styled from `alerts-page.module.css`.
2. Undefined `--space-*` tokens — the project (and `@cameleer/design-system`)
has never shipped `--space-sm|md|lg|xl`, even though many modules
(SensitiveKeysPage, alerts CSS, …) reference them. The fallback
to `initial` silently collapsed gaps/paddings to 0. Define the
scale in `ui/src/index.css` so every consumer picks it up.
3. List scrolling — DataTable was using default pagination, but with
no flex sizing the whole page scrolled. Add `fillHeight` and raise
`pageSize`/list `limit` to 200 so the table gets sticky header +
internal scroll + pinned pagination footer (Gmail-style). True
cursor-based infinite scroll needs a backend change (filed as
follow-up — `/alerts` only accepts `limit` today).
4. Title column clipping — `.titlePreview` used `white-space: nowrap`
+ fixed `max-width`, truncating message mid-UUID. Switch to a
2-line `-webkit-line-clamp` so full context is visible.
5. Notification bell badge invisible — `NotificationBell.module.css`
referenced undefined tokens (`--fg`, `--hover-bg`, `--bg`,
`--muted`). Map to real DS tokens (`--text-primary`, `--bg-hover`,
`#fff`, `--text-muted`). The admin user currently sees no badge
because the backend `/alerts/unread-count` returns 0 (read
receipts) — that's data, not UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 10:40:28 +02:00
|
|
|
<header className={css.pageHeader}>
|
|
|
|
|
<div className={css.pageTitleGroup}>
|
|
|
|
|
<h2 className={css.pageTitle}>Inbox</h2>
|
|
|
|
|
<span className={css.pageSubtitle}>{subtitle}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={css.pageActions}>
|
2026-04-21 10:05:39 +02:00
|
|
|
<Button
|
|
|
|
|
variant="secondary"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => onBulkRead(selectedIds)}
|
|
|
|
|
disabled={selectedIds.length === 0 || bulkRead.isPending}
|
|
|
|
|
>
|
|
|
|
|
Mark selected read
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="secondary"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => onBulkRead(unreadIds)}
|
|
|
|
|
disabled={unreadIds.length === 0 || bulkRead.isPending}
|
|
|
|
|
>
|
|
|
|
|
Mark all read
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
fix(alerts/ui): page header, scroll, title preview, bell badge polish
Visual regressions surfaced during browser smoke:
1. Page headers — `SectionHeader` renders as 12px uppercase gray (a
section divider, not a page title). Replace with proper h2 title
+ inline subtitle (`N firing · N total` etc.) and right-aligned
actions, styled from `alerts-page.module.css`.
2. Undefined `--space-*` tokens — the project (and `@cameleer/design-system`)
has never shipped `--space-sm|md|lg|xl`, even though many modules
(SensitiveKeysPage, alerts CSS, …) reference them. The fallback
to `initial` silently collapsed gaps/paddings to 0. Define the
scale in `ui/src/index.css` so every consumer picks it up.
3. List scrolling — DataTable was using default pagination, but with
no flex sizing the whole page scrolled. Add `fillHeight` and raise
`pageSize`/list `limit` to 200 so the table gets sticky header +
internal scroll + pinned pagination footer (Gmail-style). True
cursor-based infinite scroll needs a backend change (filed as
follow-up — `/alerts` only accepts `limit` today).
4. Title column clipping — `.titlePreview` used `white-space: nowrap`
+ fixed `max-width`, truncating message mid-UUID. Switch to a
2-line `-webkit-line-clamp` so full context is visible.
5. Notification bell badge invisible — `NotificationBell.module.css`
referenced undefined tokens (`--fg`, `--hover-bg`, `--bg`,
`--muted`). Map to real DS tokens (`--text-primary`, `--bg-hover`,
`#fff`, `--text-muted`). The admin user currently sees no badge
because the backend `/alerts/unread-count` returns 0 (read
receipts) — that's data, not UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 10:40:28 +02:00
|
|
|
</header>
|
2026-04-21 10:05:39 +02:00
|
|
|
|
2026-04-20 13:49:23 +02:00
|
|
|
{rows.length === 0 ? (
|
2026-04-21 10:05:39 +02:00
|
|
|
<EmptyState
|
|
|
|
|
icon={<Inbox size={32} />}
|
|
|
|
|
title="All clear"
|
|
|
|
|
description="No open alerts for you in this environment."
|
|
|
|
|
/>
|
2026-04-20 13:49:23 +02:00
|
|
|
) : (
|
fix(alerts/ui): page header, scroll, title preview, bell badge polish
Visual regressions surfaced during browser smoke:
1. Page headers — `SectionHeader` renders as 12px uppercase gray (a
section divider, not a page title). Replace with proper h2 title
+ inline subtitle (`N firing · N total` etc.) and right-aligned
actions, styled from `alerts-page.module.css`.
2. Undefined `--space-*` tokens — the project (and `@cameleer/design-system`)
has never shipped `--space-sm|md|lg|xl`, even though many modules
(SensitiveKeysPage, alerts CSS, …) reference them. The fallback
to `initial` silently collapsed gaps/paddings to 0. Define the
scale in `ui/src/index.css` so every consumer picks it up.
3. List scrolling — DataTable was using default pagination, but with
no flex sizing the whole page scrolled. Add `fillHeight` and raise
`pageSize`/list `limit` to 200 so the table gets sticky header +
internal scroll + pinned pagination footer (Gmail-style). True
cursor-based infinite scroll needs a backend change (filed as
follow-up — `/alerts` only accepts `limit` today).
4. Title column clipping — `.titlePreview` used `white-space: nowrap`
+ fixed `max-width`, truncating message mid-UUID. Switch to a
2-line `-webkit-line-clamp` so full context is visible.
5. Notification bell badge invisible — `NotificationBell.module.css`
referenced undefined tokens (`--fg`, `--hover-bg`, `--bg`,
`--muted`). Map to real DS tokens (`--text-primary`, `--bg-hover`,
`#fff`, `--text-muted`). The admin user currently sees no badge
because the backend `/alerts/unread-count` returns 0 (read
receipts) — that's data, not UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 10:40:28 +02:00
|
|
|
<div className={`${tableStyles.tableSection} ${css.tableWrap}`}>
|
2026-04-21 10:05:39 +02:00
|
|
|
<DataTable<AlertDto & { id: string }>
|
|
|
|
|
columns={columns as Column<AlertDto & { id: string }>[]}
|
|
|
|
|
data={rows as Array<AlertDto & { id: string }>}
|
|
|
|
|
sortable
|
|
|
|
|
flush
|
fix(alerts/ui): page header, scroll, title preview, bell badge polish
Visual regressions surfaced during browser smoke:
1. Page headers — `SectionHeader` renders as 12px uppercase gray (a
section divider, not a page title). Replace with proper h2 title
+ inline subtitle (`N firing · N total` etc.) and right-aligned
actions, styled from `alerts-page.module.css`.
2. Undefined `--space-*` tokens — the project (and `@cameleer/design-system`)
has never shipped `--space-sm|md|lg|xl`, even though many modules
(SensitiveKeysPage, alerts CSS, …) reference them. The fallback
to `initial` silently collapsed gaps/paddings to 0. Define the
scale in `ui/src/index.css` so every consumer picks it up.
3. List scrolling — DataTable was using default pagination, but with
no flex sizing the whole page scrolled. Add `fillHeight` and raise
`pageSize`/list `limit` to 200 so the table gets sticky header +
internal scroll + pinned pagination footer (Gmail-style). True
cursor-based infinite scroll needs a backend change (filed as
follow-up — `/alerts` only accepts `limit` today).
4. Title column clipping — `.titlePreview` used `white-space: nowrap`
+ fixed `max-width`, truncating message mid-UUID. Switch to a
2-line `-webkit-line-clamp` so full context is visible.
5. Notification bell badge invisible — `NotificationBell.module.css`
referenced undefined tokens (`--fg`, `--hover-bg`, `--bg`,
`--muted`). Map to real DS tokens (`--text-primary`, `--bg-hover`,
`#fff`, `--text-muted`). The admin user currently sees no badge
because the backend `/alerts/unread-count` returns 0 (read
receipts) — that's data, not UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 10:40:28 +02:00
|
|
|
fillHeight
|
|
|
|
|
pageSize={200}
|
2026-04-21 10:05:39 +02:00
|
|
|
rowAccent={(row) => row.severity ? severityToAccent(row.severity) : undefined}
|
|
|
|
|
expandedContent={renderAlertExpanded}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-04-20 13:49:23 +02:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2026-04-20 13:44:44 +02:00
|
|
|
}
|