What happened to a record, who did it and when.
Sunday, Nov 29
Yesterday
Today
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Activity, ActivityEntry } from "./ui/uicontext/components/kit/Activity.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"import { ada, now } from "./team.ts"import { history } from "./history.ts"// An issue's history, by day. Restoring a version asks the app; here it records a new entry.const styles = stylex.create({ frame: { display: "grid", gap: space.md, inlineSize: "min(100%, 36rem)" },})const Message = UiSchema.TaggedEnum({ RequestedRestore: { entry: Schema.String } })export const IssueHistory = Html.component({ name: "IssueHistory", model: Schema.Struct({ entries: Schema.Array(ActivityEntry) }), message: Message,}).make({ init: () => ({ entries: history }), update: { RequestedRestore: ($, { entry }) => $.evolve({ entries: (all) => [ ...all, { id: `restored-${entry}`, actor: ada, action: "restored an earlier description", at: now }, ], }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( Activity(h, { props: { label: "Activity on PAY-412", agentId: "activity-demo", entries: model.entries, now }, onEmit: { RequestedRestore: ({ entry }) => Message.RequestedRestore({ entry }) }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/activityUsage
import { Activity, type ActivityEntry } from "./ui/uicontext/components/kit/Activity.ts"const Message = UiSchema.TaggedEnum({ RequestedRestore: { entry: Schema.String } })// the app keeps the entries; `now` makes times read "2 hours ago" and days "Today"export const IssueActivity = (h: Html.H<typeof Message.Type>, entries: ReadonlyArray<ActivityEntry>, now: string) => Activity(h, { props: { label: "Activity", entries, now }, onEmit: { RequestedRestore: ({ entry }) => Message.RequestedRestore({ entry }) }, })Examples
A long history
2,400 entries: the newest 25 show, and each press adds 25 more. Runs of one actor's changes fold.
Today
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"import { Activity, type ActivityEntry } from "./ui/uicontext/components/kit/Activity.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { ben, mira, now } from "./team.ts"// A record a sync has touched every few minutes for a week: 2,400 entries. The feed draws the newest// page and adds one page per press. A run of one actor's changes folds after three.const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" } })const sync: Actor = { id: "sync", name: "Inventory sync", kind: "integration" }const fields = ["Stock", "Reorder point", "Price", "Supplier"]const start = Date.parse(now) - 2400 * 4 * 60 * 1000// a fixed series, so every visitor sees the same historyconst entries: ReadonlyArray<ActivityEntry> = Array.from({ length: 2400 }, (_, i) => { const at = new Date(start + i * 4 * 60 * 1000).toISOString() if (i % 97 === 0) return { id: `l${i}`, actor: i % 2 === 0 ? mira : ben, action: "changed the reorder point to", to: { label: String(40 + (i % 30)) }, at } return { id: `l${i}`, actor: sync, via: "the API", action: `updated ${fields[i % fields.length]!.toLowerCase()} to`, to: { label: String(100 + ((i * 37) % 400)) }, at }})export const SkuHistory = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( Activity(h, { props: { label: "History of SKU-2210", agentId: "activity-long", entries, now, shown: 25 }, onEmit: { RequestedRestore: () => undefined }, }), )Versions, newest first
presentation: "compact" gives each version its own row; restoreDisabled says why Restore is off.
Scout is still writing. Restore when it finishes.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Activity, type ActivityEntry } from "./ui/uicontext/components/kit/Activity.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { ada, mira, now, scout } from "./team.ts"// A page's versions, newest first, one row each. Restore is off while an agent is still writing.const styles = stylex.create({ frame: { inlineSize: "min(100%, 32rem)" } })const versions: ReadonlyArray<ActivityEntry> = [ { id: "v4", actor: scout, onBehalfOf: ada, action: "rewrote the summary", at: "2026-12-01T11:40:00Z", restore: "Restore" }, { id: "v3", actor: ada, action: "added the rollout plan", at: "2026-12-01T10:05:00Z", restore: "Restore" }, { id: "v2", actor: mira, action: "edited the goals", at: "2026-11-30T15:22:00Z", restore: "Restore" }, { id: "v1", actor: ada, action: "created the page", at: "2026-11-27T09:00:00Z", restore: "Restore" },]export const PageVersions = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( Activity(h, { props: { label: "Versions of Checkout retries", agentId: "activity-revisions", entries: versions, now, order: "newest-first", presentation: "compact", restoreDisabled: "Scout is still writing. Restore when it finishes.", }, onEmit: { RequestedRestore: () => undefined }, }), )API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | The feed's accessible name: "Activity" |
agentId | string | activity:<label> | This feed's id for agents, unique on the page; activity:<label> by default |
entriesrequired | ActivityEntry[] | — | What happened, each with its actor, verb, target and time |
now | string | — | Now, as an ISO timestamp, for "2 hours ago"; absolute dates when absent |
shown | number | 20 | How many of the newest entries show, and how many more each "Show earlier" adds; 20 by default |
order | "oldest-first" | "newest-first" | — | The order the application already supplied. Oldest first by default. |
presentation | "timeline" | "compact" | — | Compact gives every entry its own row. Timeline groups nearby entries by actor. |
restoreDisabled | string | — | Why restoring isn't possible now: "A generation is in progress" |
loading | boolean | — | Shows placeholder rows while the entries load |
locale | string | — | The locale dates and times are formatted in; the browser's by default |
timeZone | string | — | The time zone times are shown in; the reader's when left out |
Events
| Event | Payload | Description |
|---|---|---|
RequestedRestore | { entry: string } | Bring back the version this entry recorded |
Agent actions
| Action | Description |
|---|---|
ClickedRestoreasks first | Restore the object to this entry's version; it replaces the current one |
ClickedShowEarlier | Show the earlier entries |
Accessibility
- The history is an ordered list in a named section, and each time is a
<time>with the full date as a tooltip. - Restore is a real button; when restoring is off, the reason is tied to it as its description.
- Agents read the entries, who acted for whom, and must name the entry they restore.