import { Badge, Button, InlineCopyText, Table, Text } from "@cloudflare/kumo"; import type { Snapshot } from "@cloudhal/core-contracts"; import { GearSix, GitDiff, type Icon, Robot, User } from "@phosphor-icons/react"; import type { ReactNode } from "react"; import { SectionEmpty } from "./SectionEmpty.tsx"; export interface SnapshotTimelineLabels { empty: string; emptyDescription?: string; live: string; publish: string; rollBack: string; /** Label of the "compare" action (shown when `onCompare` is set). */ compare: string; /** Accessible name of the actions column (it has no visible header). */ actions?: string; columns: { snapshot: string; actor: string; changes: string; when: string }; reasons: Record; } export interface SnapshotTimelineProps { snapshots: Snapshot[]; publishedSnapshotId?: string | undefined; onPublish?: ((snapshot: Snapshot) => void) | undefined; onRollback?: ((snapshot: Snapshot) => void) | undefined; /** Opens a diff of this snapshot against its predecessor or the live one. */ onCompare?: ((snapshot: Snapshot) => void) | undefined; /** * The person's role cannot publish: the button stays in place, disabled, with this reason as its * tooltip ("Only Authors and above can publish"). DESIGN.md §2s. */ publishDisabledReason?: string | undefined; /** The same for rolling back. */ rollbackDisabledReason?: string | undefined; labels: SnapshotTimelineLabels; emptyIcon?: ReactNode; /** CTA under the empty state (e.g. the page's "Create snapshot" button). */ emptyContents?: ReactNode; /** Renders the creation time; lists pass a relative time with the absolute one in a tooltip. */ renderTime: (iso: string) => ReactNode; } const ACTOR_ICON: Record = { human: User, agent: Robot, system: GearSix, }; /** * Newest-first table of a site's snapshots (DESIGN.md §2a): label with the live badge, reason and * copyable id; author; change counts; creation time; then Compare and Publish / Roll back in * their own columns so the actions line up row to row. Render it inside `LayerCard p-0`. */ export function SnapshotTimeline({ snapshots, publishedSnapshotId, onPublish, onRollback, onCompare, publishDisabledReason, rollbackDisabledReason, labels, emptyIcon, emptyContents, renderTime: time, }: SnapshotTimelineProps) { if (snapshots.length === 0) { return ( ); } const publishedIndex = snapshots.findIndex((s) => s.id === publishedSnapshotId); const showCompare = onCompare !== undefined; return ( {labels.columns.snapshot} {labels.columns.actor} {labels.columns.changes} {labels.columns.when} {showCompare && } {labels.actions} {snapshots.map((s, i) => { const isLive = s.id === publishedSnapshotId; const isOlderThanLive = publishedIndex !== -1 && i > publishedIndex; const canCompare = !!s.parentId || (!!publishedSnapshotId && !isLive); const ActorIcon = ACTOR_ICON[s.actor.kind]; return (
{s.label ?? labels.reasons[s.reason]} {isLive && ( {labels.live} )}
{s.label && ( {labels.reasons[s.reason]} )} {s.id}
{s.actor.name ?? s.actor.id} +{s.summary.added} ~{s.summary.changed} −{s.summary.removed} {time(s.createdAt)} {showCompare && ( {canCompare && ( )} )} {!isLive && onPublish && !isOlderThanLive && ( )} {!isLive && onRollback && isOlderThanLive && ( )}
); })}
); }