Settings as rows, each with its control.
Email me when a workflow run fails.
You won’t hear about failures until you open run history.
Runs, tasks used and what failed, every Monday.
Team Chat channel for alerts everyone should see.
Anyone with the link can see a run’s steps.
Members sign in through your identity provider.
Only the Owner can change this.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { accepted, pending, refused } from "./ui/uicontext/components/domain/Outcome.ts"import { SettingItem, SettingList } from "./ui/uicontext/components/kit/SettingList.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 40rem)" } })const Message = UiSchema.TaggedEnum({ Switched: { id: Schema.String, on: Schema.Boolean }, Chose: { id: Schema.String, value: Schema.String }, Answered: { id: Schema.String, ok: Schema.Boolean },})// Stands in for the server: each change saves on its own. Public sharing is refused here, to show a refusal.const SaveSetting = Command.make("Notifications.Save", { args: { id: Schema.String } }, ({ id }) => Effect.sleep("500 millis").pipe(Effect.as(Message.Answered({ id, ok: id !== "public" }))))const seed: ReadonlyArray<SettingItem> = [ { id: "failures", label: "Run failures", description: "Email me when a workflow run fails.", on: true, whenOff: "You won’t hear about failures until you open run history." }, { id: "digest", label: "Weekly summary", description: "Runs, tasks used and what failed, every Monday.", on: false }, { id: "channel", label: "Where alerts go", description: "Team Chat channel for alerts everyone should see.", options: [{ value: "#ops", label: "#ops" }, { value: "#automation", label: "#automation" }, { value: "none", label: "Nowhere" }], value: "#ops" }, { id: "public", label: "Public run links", description: "Anyone with the link can see a run’s steps.", on: false }, { id: "sso", label: "Require single sign-on", description: "Members sign in through your identity provider.", on: true, readOnly: "Only the Owner can change this." },]export const InstantSettings = Html.component({ name: "InstantSettings", model: Schema.Struct({ items: Schema.Array(SettingItem), was: Schema.Record(Schema.String, SettingItem) }), message: Message,}).make({ init: () => ({ items: seed, was: {} }), update: { // optimistic: the row changes at once, and goes back if the server refuses Switched: ($, { id, on }) => { const before = $.model.items.find((i) => i.id === id) return $.evolve({ items: (items) => items.map((i) => (i.id === id ? { ...i, on, outcome: pending(id) } : i)), was: (w) => (before === undefined ? w : { ...w, [id]: before }), }).run(SaveSetting.make({ id })) }, Chose: ($, { id, value }) => { const before = $.model.items.find((i) => i.id === id) return $.evolve({ items: (items) => items.map((i) => (i.id === id ? { ...i, value, outcome: pending(id) } : i)), was: (w) => (before === undefined ? w : { ...w, [id]: before }), }).run(SaveSetting.make({ id })) }, Answered: ($, { id, ok }) => $.evolve({ items: (items) => items.map((i) => { if (i.id !== id) return i const before = $.model.was[id] ?? i return ok ? { ...i, outcome: accepted(id) } : { ...before, outcome: refused(id, "Your plan doesn’t include public links. Nothing changed.") } }), }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( SettingList(h, { props: { label: "Notifications", agentId: "settings-instant", items: model.items }, onEmit: { RequestedSwitch: ({ id, on }) => Message.Switched({ id, on }), RequestedChoice: ({ id, value }) => Message.Chose({ id, value }), }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/setting-listUsage
import { type SettingItem, SettingList } from "./ui/uicontext/components/kit/SettingList.ts"const Message = UiSchema.TaggedEnum({ SwitchedSetting: { id: Schema.String, on: Schema.Boolean }, ChoseSetting: { id: Schema.String, value: Schema.String },})export const Notifications = (h: Html.H<typeof Message.Type>, items: ReadonlyArray<SettingItem>) => SettingList(h, { props: { label: "Notifications", items }, onEmit: { RequestedSwitch: ({ id, on }) => Message.SwitchedSetting({ id, on }), RequestedChoice: ({ id, value }) => Message.ChoseSetting({ id, value }), }, })API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | The list's accessible name: "Organization switches" |
agentId | string | settings:<label> | The id agents know this list by; settings:<label> by default |
itemsrequired | SettingItem[] | — | The rows: each a switch or a choice, with its description and state |
readOnly | string | — | Why nothing in the list can change here, said once above it: "Only the Owner can change these." |
Events
| Event | Payload | Description |
|---|---|---|
RequestedSwitch | { id: string; on: boolean } | Turn a row's switch on or off |
RequestedChoice | { id: string; value: string } | Choose a value for a choice row |
Agent actions
| Action | Description |
|---|---|
Toggledasks first | Turn an on/off row on or off, by id. Target: { id, value } as the snapshot shows it now. |
Choseasks first | Choose a value on a choice row, by id (values in the snapshot's options). Target: { id, value }. |
Accessibility
- On and off rows are switches (
role="switch"); choice rows are native selects. Each is described by its row's description. - A row waiting on the app is marked busy, and a refusal is announced under it.
- A read-only list says why once, above it.