2026-04-21 10:10:10 +02:00
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
import { History } from 'lucide-react';
|
|
|
|
|
import {
|
2026-04-21 13:10:43 +02:00
|
|
|
DataTable, EmptyState, useGlobalFilters,
|
2026-04-21 10:10:10 +02:00
|
|
|
} from '@cameleer/design-system';
|
|
|
|
|
import type { Column } from '@cameleer/design-system';
|
2026-04-20 13:49:52 +02:00
|
|
|
import { PageLoader } from '../../components/PageLoader';
|
2026-04-21 10:10:10 +02:00
|
|
|
import { SeverityBadge } from '../../components/SeverityBadge';
|
|
|
|
|
import {
|
|
|
|
|
useAlerts, 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:52 +02:00
|
|
|
import css from './alerts-page.module.css';
|
2026-04-21 10:10:10 +02:00
|
|
|
import tableStyles from '../../styles/table-section.module.css';
|
|
|
|
|
|
|
|
|
|
/** Duration in s/m/h/d. Pure, best-effort. */
|
|
|
|
|
function formatDuration(from?: string | null, to?: string | null): string {
|
|
|
|
|
if (!from || !to) return '—';
|
|
|
|
|
const ms = new Date(to).getTime() - new Date(from).getTime();
|
|
|
|
|
if (ms < 0 || Number.isNaN(ms)) return '—';
|
|
|
|
|
const sec = Math.floor(ms / 1000);
|
|
|
|
|
if (sec < 60) return `${sec}s`;
|
|
|
|
|
if (sec < 3600) return `${Math.floor(sec / 60)}m`;
|
|
|
|
|
if (sec < 86_400) return `${Math.floor(sec / 3600)}h`;
|
|
|
|
|
return `${Math.floor(sec / 86_400)}d`;
|
|
|
|
|
}
|
2026-04-20 13:49:52 +02:00
|
|
|
|
2026-04-20 13:44:44 +02:00
|
|
|
export default function HistoryPage() {
|
2026-04-21 13:10:43 +02:00
|
|
|
const { timeRange } = useGlobalFilters();
|
2026-04-21 10:10:10 +02:00
|
|
|
|
2026-04-21 13:10:43 +02:00
|
|
|
// useAlerts doesn't accept a time range today; filter client-side
|
|
|
|
|
// against the global TimeRangeDropdown in the top bar.
|
2026-04-20 13:49:52 +02:00
|
|
|
const { data, isLoading, error } = useAlerts({ state: 'RESOLVED', limit: 200 });
|
|
|
|
|
|
2026-04-21 10:10:10 +02:00
|
|
|
const filtered = (data ?? []).filter((a) => {
|
|
|
|
|
if (!a.firedAt) return false;
|
|
|
|
|
const t = new Date(a.firedAt).getTime();
|
2026-04-21 13:10:43 +02:00
|
|
|
return t >= timeRange.start.getTime() && t <= timeRange.end.getTime();
|
2026-04-21 10:10:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const columns: Column<AlertDto>[] = [
|
|
|
|
|
{
|
|
|
|
|
key: 'severity', header: 'Severity', width: '110px',
|
|
|
|
|
render: (_, row) => row.severity ? <SeverityBadge severity={row.severity} /> : null,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'title', header: 'Title',
|
|
|
|
|
render: (_, row) => (
|
|
|
|
|
<div className={css.titleCell}>
|
|
|
|
|
<Link to={`/alerts/inbox/${row.id}`}>{row.title ?? '(untitled)'}</Link>
|
|
|
|
|
{row.message && <span className={css.titlePreview}>{row.message}</span>}
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'firedAt', header: 'Fired at', width: '140px', sortable: true,
|
|
|
|
|
render: (_, row) =>
|
|
|
|
|
row.firedAt ? (
|
|
|
|
|
<span title={row.firedAt} style={{ fontVariantNumeric: 'tabular-nums' }}>
|
|
|
|
|
{formatRelativeTime(row.firedAt)}
|
|
|
|
|
</span>
|
|
|
|
|
) : '—',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'resolvedAt', header: 'Resolved at', width: '140px', sortable: true,
|
|
|
|
|
render: (_, row) =>
|
|
|
|
|
row.resolvedAt ? (
|
|
|
|
|
<span title={row.resolvedAt} style={{ fontVariantNumeric: 'tabular-nums' }}>
|
|
|
|
|
{formatRelativeTime(row.resolvedAt)}
|
|
|
|
|
</span>
|
|
|
|
|
) : '—',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'duration', header: 'Duration', width: '90px',
|
|
|
|
|
render: (_, row) => formatDuration(row.firedAt, row.resolvedAt),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2026-04-20 13:49:52 +02:00
|
|
|
if (isLoading) return <PageLoader />;
|
|
|
|
|
if (error) return <div className={css.page}>Failed to load history: {String(error)}</div>;
|
|
|
|
|
|
|
|
|
|
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}>
|
2026-04-21 11:48:33 +02:00
|
|
|
<h2 className={css.pageTitle}>Alert history</h2>
|
|
|
|
|
<span className={css.pageSubtitle}>
|
|
|
|
|
{filtered.length === 0
|
|
|
|
|
? 'No resolved alerts in range'
|
|
|
|
|
: `${filtered.length} resolved alert${filtered.length === 1 ? '' : 's'} in range`}
|
|
|
|
|
</span>
|
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>
|
|
|
|
|
</header>
|
2026-04-21 10:10:10 +02:00
|
|
|
|
|
|
|
|
{filtered.length === 0 ? (
|
|
|
|
|
<EmptyState
|
|
|
|
|
icon={<History size={32} />}
|
|
|
|
|
title="No resolved alerts"
|
|
|
|
|
description="Nothing in the selected date range. Try widening it."
|
|
|
|
|
/>
|
2026-04-20 13:49:52 +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:10:10 +02:00
|
|
|
<DataTable<AlertDto & { id: string }>
|
|
|
|
|
columns={columns as Column<AlertDto & { id: string }>[]}
|
|
|
|
|
data={filtered 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:10:10 +02:00
|
|
|
rowAccent={(row) => row.severity ? severityToAccent(row.severity) : undefined}
|
|
|
|
|
expandedContent={renderAlertExpanded}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-04-20 13:49:52 +02:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2026-04-20 13:44:44 +02:00
|
|
|
}
|