Table
An interactive, virtualized record grid.
Table
How it works
A grid: arrows move between cells and the header, Enter or F2 edits, typing starts an edit, Delete clears, Tab saves and moves on, Mod+C copies, and pasting tab-separated text fills a block. Click a header to sort. Press Shift+F10 on a focused header to open column actions. Resize by dragging a column edge or pressing Alt+Left or Alt+Right on the header. ✦ marks a cell an agent filled. A negative budget is refused and the cell goes back.
Installation
npx shadcn@latest add checkfu/uicontext/tableIntegration
Table owns the active cell, selection, and optimistic display. Handle RequestedEdit with an app command. Use the original request ID when replying through outcomes.
On success, publish the saved row together with the accepted outcome. On refusal, publish the reason and keep the saved row unchanged. Native edits and allowed agent edits can share the same command and write rules.
bun run test:consumer --case contracts --keepRun this from the UiContext checkout. From the temporary app it prints, run bunx vite to open it.
View the executable example
import { Command, UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { Effect, Schema } from "effect"
import { Outcome, type Property, Value } from "./ui/uicontext/components/kit/Property.ts"
import { Table } from "./ui/uicontext/components/kit/Table.ts"
const Status = Schema.Literals(["Ready", "Paused"])
const isStatus = Schema.is(Status)
const Workflow = Schema.Struct({ id: Schema.String, name: Schema.String, status: Status })
const Edit = { request: Schema.String, item: Schema.String, key: Schema.String, value: Value }
const SaveResult = Schema.Union([
Schema.TaggedStruct("Saved", { status: Status }),
Schema.TaggedStruct("Refused", { reason: Schema.String }),
])
export class SaveWorkflow extends Command.Service<SaveWorkflow>()("recipe/SaveWorkflow", {
args: Edit,
success: SaveResult,
mode: "queue",
group: ["item"],
}) {
static readonly layer = this.toLayer(({ item, key, value }) =>
Effect.sleep("350 millis").pipe(Effect.map(() => {
if (key !== "status" || !isStatus(value)) {
return { _tag: "Refused", reason: "Enter Ready or Paused." }
}
if (item === "billing" && value === "Paused") {
return { _tag: "Refused", reason: "Billing sync must stay ready." }
}
return { _tag: "Saved", status: value }
})),
)
}
const Message = UiSchema.TaggedEnum({
RequestedEdit: Edit,
SavedEdit: { request: Schema.String, item: Schema.String, result: SaveResult },
RequestedArchive: { items: Schema.Array(Schema.String) },
})
const properties: ReadonlyArray<Property> = [{ key: "status", label: "Status", kind: "text" }]
const archive = [{ id: "archive", label: "Archive selected", consequential: true }] as const
export const Workflows = Html.component({
name: "WorkflowStatus",
model: Schema.Struct({
workflows: Schema.Array(Workflow),
pending: Schema.Array(Schema.String),
outcomes: Schema.Array(Outcome),
notice: Schema.String,
}),
message: Message,
}).make({
init: () => ({
workflows: [
{ id: "digest", name: "Daily digest", status: "Ready" },
{ id: "billing", name: "Billing sync", status: "Ready" },
],
pending: [],
outcomes: [],
notice: "Changes are kept until you reload this page.",
}),
update: {
RequestedEdit: ($, { request, item, key, value }) =>
$.evolve({ pending: (pending) => [...pending, request] })
.run(Command.map(
SaveWorkflow.make({ request, item, key, value }),
(result) => Message.SavedEdit({ request, item, result }),
)),
SavedEdit: ($, { request, item, result }) => {
if (!$.model.pending.includes(request)) return $.model
const saved = result._tag === "Saved"
return $.evolve({
workflows: saved
? $.model.workflows.map((workflow) => workflow.id === item ? { ...workflow, status: result.status } : workflow)
: $.model.workflows,
pending: (pending) => pending.filter((id) => id !== request),
outcomes: (outcomes) => [...outcomes, { request, refused: saved ? null : result.reason }],
notice: saved ? "Status saved." : "Status left unchanged.",
})
},
RequestedArchive: ($, { items }) => {
if ($.model.pending.length !== 0) return $.model
return $.evolve({
workflows: (workflows) => workflows.filter(({ id }) => !items.includes(id)),
notice: "Selection archived.",
})
},
},
view: (h, model) => {
const items = model.workflows.map(({ id, name, status }) => ({ id, title: name, values: { status } }))
return h.section.attr("aria-labelledby", "workflow-heading").children(
h.header.children(
h.h2.attr("id", "workflow-heading").children("Workflow status"),
h.p.children("Press Enter on a status to edit it. Try pausing Billing sync to see a refused save."),
),
h.div.attr("class", "table").children(
Table(h, {
key: "workflows",
props: {
agentId: "workflows",
label: "Workflows",
title: { label: "Workflow", width: 176 },
columns: [{ key: "status", width: 160 }],
rowHeight: 40,
items,
properties,
outcomes: model.outcomes,
actions: model.pending.length === 0 ? archive : [],
},
onEmit: {
RequestedEdit: (edit) => Message.RequestedEdit(edit),
RequestedAction: ({ action, items }) => action === "archive" ? Message.RequestedArchive({ items }) : undefined,
RequestedOpen: () => undefined,
RequestedCreate: () => undefined,
RequestedSort: () => undefined,
RequestedCellAction: () => undefined,
ResizedColumn: () => undefined,
RequestedAddColumn: () => undefined,
RequestedColumnAction: () => undefined,
Selected: () => undefined,
},
}),
),
h.p.attrs({ class: "feedback", role: "status" }).children(
model.pending.length > 0 ? "Saving changes…" : model.notice,
),
)
},
})workflows.ts on GitHub