# Activity Feed

> What happened to a record, who did it and when.

Page: https://uicontext.com/docs/components/activity-feed

Group: Documents.

## When to use

What happened to a record, who did it and when. Use [Audit Log](https://uicontext.com/docs/components/audit-log.md) instead when the log is for a whole workspace's admins.

## Usage

```ts
import { Activity, type ActivityEntry } from "./ui/uicontext/components/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

Each example is a complete file. Its imports point where the CLI installs the source.

### An issue's history

The example the page opens with: Activity Feed in “An issue's history”.

```ts title="src/demo.ts" source="www/src/examples/activity-feed/demo.ts"
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/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 }) },
			}),
		),
})
```

### A long history

2,400 entries: the newest 25 show, and each press adds 25 more. Runs of one actor's changes fold.

```ts title="src/long-history.ts" source="www/src/examples/activity-feed/long-history.ts"
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/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 history
const 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.

```ts title="src/revisions.ts" source="www/src/examples/activity-feed/revisions.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Activity, type ActivityEntry } from "./ui/uicontext/components/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 },
		}),
	)
```

### Sample data

The examples above import these files.

```ts title="src/team.ts" source="www/src/examples/_shared/team.ts"
import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"

// The people in the examples: three teammates and their agent.

export const ada: Actor = { id: "ada", name: "Ada Lovelace", kind: "person" }
export const ben: Actor = { id: "ben", name: "Ben Okafor", kind: "person" }
export const mira: Actor = { id: "mira", name: "Mira Patel", kind: "person" }
export const scout: Actor = { id: "scout", name: "Scout", kind: "agent" }
export const members: ReadonlyArray<Actor> = [scout, ben, mira, ada]

/** "Today" in these examples, so the day separators read the same for every visitor. */
export const now = "2026-12-01T12:00:00Z"
```

```ts title="src/history.ts" source="www/src/examples/activity-feed/history.ts"
import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"
import type { ActivityEntry, ActivityValue } from "./ui/uicontext/components/Activity.ts"
import { color } from "./ui/uicontext/components/tokens.stylex.ts"
import { ada, ben, mira, scout } from "./team.ts"

// PAY-412's history over three days: people, an agent acting for Ada, a nightly routine, and
// versions of the description that can be restored.

export const triage: Actor = { id: "triage", name: "Nightly triage", kind: "routine" }

const ring = (label: string, progress: number, tone: string, dashed = false): ActivityValue => ({
	label,
	glyph: { _tag: "Ring", color: tone, progress, label, ...(dashed ? { dashed } : {}) },
})
export const backlog = ring("Backlog", 0, color.faint, true)
export const todo = ring("Todo", 0, color.muted)
export const doing = ring("In Progress", 0.5, color.caution)
export const review = ring("In Review", 0.75, color.info)

export const history: ReadonlyArray<ActivityEntry> = [
	{ id: "h1", actor: ben, action: "created the issue", at: "2026-11-29T16:52:00Z" },
	{ id: "h2", actor: ben, action: "set the priority to", to: { label: "Urgent" }, at: "2026-11-29T16:53:00Z" },
	{ id: "h3", actor: ben, action: "added the label", to: { label: "Checkout" }, at: "2026-11-29T16:54:00Z" },
	{ id: "h4", actor: triage, action: "changed the status", from: backlog, to: todo, at: "2026-11-30T02:00:00Z" },
	{
		id: "h5",
		actor: scout,
		onBehalfOf: ada,
		via: "team chat",
		action: "linked",
		to: { label: "PAY-398" },
		detail: "Same stack trace: the retry reuses the first attempt's idempotency key.",
		at: "2026-12-01T09:43:00Z",
		href: "#run-218",
	},
	{ id: "h6", actor: mira, action: "assigned the issue to", to: { label: "Mira Patel" }, at: "2026-12-01T09:46:00Z" },
	{ id: "h7", actor: mira, action: "changed the status", from: todo, to: doing, at: "2026-12-01T09:47:00Z" },
	{ id: "h8", actor: mira, action: "edited the description", restore: "Restore this version", at: "2026-12-01T10:20:00Z" },
	{ id: "h9", actor: ada, action: "changed the status", from: doing, to: review, at: "2026-12-01T11:32:00Z" },
]
```

## API reference

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `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 |
| `entries` (required) | `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 |
| --- | --- |
| `ClickedRestore` (asks first) | Restore the object to this entry's version; it replaces the current one |
| `ClickedShowEarlier` | Show the earlier entries |

## Keyboard and 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.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/activity-feed
```

With npm: `npx shadcn@latest add checkfu/uicontext/activity-feed`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/activity-feed`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/activity-feed`.

It writes these files:

- `src/ui/uicontext/components/Activity.ts`
- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Direction.ts`
- `src/ui/uicontext/components/Glyph.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Actor.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Glyph.ts`
- `src/ui/uicontext/components/domain/Time.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Activity.ts](https://github.com/checkfu/uicontext/blob/main/src/Activity.ts)

## Used in

- [Task manager](https://uicontext.com/blocks/issue-tracker.md)
- [CRM](https://uicontext.com/blocks/crm.md)
- [Helpdesk](https://uicontext.com/blocks/helpdesk.md)

## Related

- [Editor](https://uicontext.com/docs/components/editor.md) (`editor`): A block editor with a slash menu for headings, lists, to-dos and more.
- [Document Blocks](https://uicontext.com/docs/components/document-blocks.md) (`document-blocks`): Read-only rendering of a document's blocks.
- [Markdown](https://uicontext.com/docs/components/markdown.md) (`markdown`): Renders Markdown with readable type.
- [Code Block](https://uicontext.com/docs/components/code-block.md) (`code-block`): Code to read and copy, with highlighting, a file name and line numbers.
- [JSON Viewer](https://uicontext.com/docs/components/json-viewer.md) (`json-viewer`): A JSON value as a tree to open, search and walk with the arrow keys, such as a webhook's payload or a tool call's result.
- [Log Viewer](https://uicontext.com/docs/components/log-viewer.md) (`log-viewer`): A log that follows its newest line, with a filter, level buttons and Wrap, such as a deploy's or a server's.
