Who did what in a workspace, and when.
Showing 25 of 300
import { Command, Component, UiSchema } from "@effect/ui"import { Html, HtmlFiles } from "@effect/ui/html"import { Effect, Schema } from "effect"import { AuditLog, type AuditFilter, auditToCsv, filterAudit } from "./ui/uicontext/components/kit/Audit.ts"import { auditEntries } from "./workspace.ts"// Three hundred entries filtered and searched in memory, 25 at a time. Export makes a CSV of// every match, not only the rows on screen. With a server, send the filters and the search with// the request instead.const all = auditEntries(300)const PAGE = 25const filters: ReadonlyArray<AuditFilter> = [ { id: "who", label: "Who", field: "actorKind", options: [ { value: "person", label: "People" }, { value: "agent", label: "Agents" }, { value: "routine", label: "Routines" }, { value: "integration", label: "Integrations" }, ], }, { id: "outcome", label: "Outcome", field: "status", options: [ { value: "succeeded", label: "Done" }, { value: "failed", label: "Failed" }, { value: "refused", label: "Refused" }, { value: "waiting", label: "Held" }, ], },]const Message = UiSchema.TaggedEnum({ FilteredLog: { selected: Schema.Record(Schema.String, Schema.String) }, SearchedLog: { query: Schema.String }, RequestedMoreLog: {}, ExportedLog: { format: Schema.Literals(["csv", "json"]), selected: Schema.Record(Schema.String, Schema.String), query: Schema.String },})// A real app asks its server for the file; here it's made from the entries in memory.const DownloadLog = Command.make( "DownloadLog", { args: { format: Schema.Literals(["csv", "json"]), selected: Schema.Record(Schema.String, Schema.String), query: Schema.String } }, ({ format, selected, query }) => { const rows = filterAudit(all, filters, selected, query) const file = format === "csv" ? new File([auditToCsv(rows)], "audit-log.csv", { type: "text/csv" }) : new File([JSON.stringify(rows, null, 2)], "audit-log.json", { type: "application/json" }) return HtmlFiles.download(file).pipe(Effect.as(Component.noop)) },)export const AuditDemo = Html.component({ name: "AuditDemo", model: Schema.Struct({ selected: Schema.Record(Schema.String, Schema.String), query: Schema.String, shown: Schema.Number }), message: Message,}).make({ init: () => ({ selected: {}, query: "", shown: PAGE }), update: { FilteredLog: ($, { selected }) => $.evolve({ selected, shown: PAGE }), SearchedLog: ($, { query }) => $.evolve({ query, shown: PAGE }), RequestedMoreLog: ($) => $.evolve({ shown: (n) => n + PAGE }), ExportedLog: ($, args) => $.run(DownloadLog.make(args)), }, view: (h, model) => { const matching = filterAudit(all, filters, model.selected, model.query) return AuditLog(h, { props: { agentId: "audit-demo", label: "Audit log", entries: matching.slice(0, model.shown), total: matching.length, hasMore: matching.length > model.shown, filters, selected: model.selected, search: { placeholder: "Person, action or place" }, query: model.query, exportFormats: ["csv", "json"], timeZone: "Europe/Lisbon", locale: "en-GB", }, onEmit: { RequestedFilters: ({ selected }) => Message.FilteredLog({ selected }), RequestedQuery: ({ query }) => Message.SearchedLog({ query }), RequestedMore: () => Message.RequestedMoreLog(), RequestedExport: (args) => Message.ExportedLog(args), RequestedRowAction: () => undefined, }, }) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/auditUsage
import { AuditLog, type AuditEntry } from "./ui/uicontext/components/kit/Audit.ts"const Message = UiSchema.TaggedEnum({ FilteredAudit: { selected: Schema.Record(Schema.String, Schema.String) }, RequestedMoreAudit: {},})export const WorkspaceAudit = ( h: Html.H<typeof Message.Type>, entries: ReadonlyArray<AuditEntry>, selected: Readonly<Record<string, string>>, hasMore: boolean,) => AuditLog(h, { props: { label: "Audit log", entries, hasMore, selected, filters: [{ id: "who", label: "Who", field: "actorKind", options: [{ value: "agent", label: "Agents" }] }], }, onEmit: { RequestedFilters: ({ selected }) => Message.FilteredAudit({ selected }), RequestedMore: () => Message.RequestedMoreAudit(), RequestedQuery: () => undefined, RequestedExport: () => undefined, RequestedRowAction: () => undefined, }, })Examples
Sign-ins
A row action on each live session. Ending one marks its entry ended.
4 entries
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import { Schema } from "effect"import { AuditLog, type AuditEntry } from "./ui/uicontext/components/kit/Audit.ts"import { ana, ben } from "./workspace.ts"// Sign-ins with an action on each live one. Ending a session marks the entry ended.const entries: ReadonlyArray<AuditEntry> = [ { id: "s1", at: "2026-12-01T09:12:00Z", actor: ana, action: "Signed in with", target: { label: "a passkey" }, place: "Lisbon, Portugal", detail: "Chrome on macOS", result: { status: "info", label: "Active" }, rowAction: "End session" }, { id: "s2", at: "2026-11-30T22:40:00Z", actor: ana, action: "Signed in with", target: { label: "a magic link" }, place: "Porto, Portugal", detail: "Safari on iPhone", result: { status: "info", label: "Active" }, rowAction: "End session" }, { id: "s3", at: "2026-11-30T18:03:00Z", actor: ben, action: "Tried to sign in with", target: { label: "a password" }, place: "Lagos, Nigeria", result: { status: "refused", reason: "Wrong password, 5 times. Locked for 15 minutes." } }, { id: "s4", at: "2026-11-29T08:55:00Z", actor: ben, action: "Signed in with", target: { label: "a password" }, place: "Lagos, Nigeria", detail: "Firefox on Windows", result: { status: "info", label: "Ended" } },]const Message = UiSchema.TaggedEnum({ EndedSession: { id: Schema.String } })export const SignIns = Html.component({ name: "AuditSignIns", model: Schema.Struct({ ended: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ ended: [] }), update: { EndedSession: ($, { id }) => $.evolve({ ended: (e) => [...e, id] }) }, view: (h, { ended }) => AuditLog(h, { props: { agentId: "audit-sign-ins", label: "Sign-ins", timeZone: "Europe/Lisbon", locale: "en-GB", entries: entries.map((e) => { if (!ended.includes(e.id)) return e const { rowAction: _, ...rest } = e return { ...rest, result: { status: "info" as const, label: "Ended by you" } } }), }, onEmit: { RequestedRowAction: ({ id }) => Message.EndedSession({ id }), RequestedFilters: () => undefined, RequestedQuery: () => undefined, RequestedExport: () => undefined, RequestedMore: () => undefined, }, }),})Empty
A new workspace's log says what will show up in it.
import type { Html } from "@effect/ui/html"import { AuditLog } from "./ui/uicontext/components/kit/Audit.ts"// A workspace whose log has nothing in it yet.export const EmptyLog = <M>(h: Html.H<M>) => AuditLog(h, { props: { agentId: "audit-empty", label: "Audit log", entries: [], emptyTitle: "Nothing recorded yet", emptyHint: "Sign-ins, setting changes and every agent action show here.", }, onEmit: { RequestedFilters: () => undefined, RequestedQuery: () => undefined, RequestedExport: () => undefined, RequestedMore: () => undefined, RequestedRowAction: () => undefined, }, })API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
agentId | string | — | This log's id for agents, unique on the page: "audit-admin" |
labelrequired | string | — | "Activity", "Audit log", "Network events" |
entriesrequired | AuditEntry[] | — | What happened, newest first: who did what to which target, and when |
filters | AuditFilter[] | — | The filters above the log, each a field and its choices |
selected | Record<string, string> | — | The chosen value per filter id; "" or absent for all |
query | string | — | The search text, controlled: matches who, what, the target, where and the reason |
search | { placeholder } | — | Show the search field; its placeholder is Search the log unless you give one |
exportFormats | ("csv" | "json")[] | — | Formats the log can be exported in; shows Export, which asks for the current filters |
exporting | boolean | — | An export is being made: the button shows busy |
total | number | — | How many entries match in all, when the app knows: "Showing 50 of 1,284" |
hasMore | boolean | — | More entries exist past these |
loadingMore | boolean | — | More entries are loading: the load-more button shows busy |
rowActionConsequential | boolean | true | Is the row action consequential (ending a session is); true by default |
emptyTitle | string | Nothing recorded yet | What an empty log says; Nothing recorded yet by default |
emptyHint | string | — | A hint under the empty title |
timeZone | string | — | The time zone (IANA) times are shown in |
locale | string | — | The locale times are formatted in; the browser's by default |
Events
| Event | Payload | Description |
|---|---|---|
RequestedFilters | { selected: Record<string, string> } | The whole selection after the change |
RequestedMore | {} | Load the entries past these |
RequestedRowAction | { id: string } | An entry's action was pressed, such as ending a session |
RequestedQuery | { query: string } | The search text changed; filter on the server, or with filterAudit |
RequestedExport | { format: "csv" | "json"; selected: Record<string, string>; query: string } | Export every entry the current filters and search match, not only the loaded ones |
Agent actions
| Action | Description |
|---|---|
ChoseFilter | Filter by one field: { filter, value } (from page_query "filter=value"); value "" shows all. |
UpdatedQuery | Search the log by who, what, target, place or reason |
ClickedExport | Export every entry the current filters and search match, as csv or json |
ClickedMore | Load older entries |
ClickedRowAction | Take an entry's row action (its rowAction, such as ending a session). Target: { id, rowAction, result }. |
Accessibility
- The log is a captioned table; each time is a
<time>in the reader's time zone. - Filters are native selects inside a
searchlandmark, and loading older entries is announced.