Set up a workflow step: its app, account and fields mapped from earlier steps, then test it.
2. Create contact
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { StepConfigurator } from "./ui/uicontext/components/kit/Mapper.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { catalog, formData } from "./automation.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 34rem)", containerType: "inline-size" } })const Message = UiSchema.TaggedEnum({ SetField: { field: Schema.String, value: Schema.String }, ChoseAccount: { account: Schema.String }, Tested: {}, FinishedTest: {},})// Stands in for the server running the step with the samples.const RunTest = Command.make("CreateContactDemo.RunTest", {}, () => Effect.sleep("700 millis").pipe(Effect.as(Message.FinishedTest())))const Model = Schema.Struct({ fields: Schema.Record(Schema.String, Schema.String), account: Schema.String, test: Schema.Literals(["none", "running", "done"]), stale: Schema.Boolean,})export const CreateContact = Html.component({ name: "CreateContact", model: Model, message: Message,}).make({ init: () => ({ fields: { email: "{{form.work_email}}", name: "{{form.name}}", company: "{{form.company}}", stage: "lead", note: "Asked for a demo on {{form.submitted_at}}." }, account: "sales", test: "none", stale: false, }), update: { SetField: ($, { field, value }) => $.evolve({ fields: (f) => ({ ...f, [field]: value }), stale: $.model.test === "done" }), ChoseAccount: ($, { account }) => $.evolve({ account }), Tested: ($) => $.evolve({ test: "running" }).run(RunTest.make()), FinishedTest: ($) => $.evolve({ test: "done", stale: false }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( StepConfigurator(h, { key: "contact", props: { id: "contact", agentId: "step:mapper-demo", title: "2. Create contact", app: { value: "crm", options: [] }, event: { value: "create-contact", options: [] }, catalog: { apps: catalog, for: "action" }, account: { label: "Pipeline CRM account", value: model.account, options: [ { value: "sales", label: "Sales team · [email protected]" }, { value: "support", label: "Support · [email protected]" }, ], }, fields: [ { id: "email", label: "Email", kind: "text", type: "email", required: true, value: model.fields.email ?? "" }, { id: "name", label: "Full name", kind: "text", type: "text", value: model.fields.name ?? "" }, { id: "company", label: "Company", kind: "text", type: "text", value: model.fields.company ?? "" }, { id: "size", label: "Seats", kind: "text", type: "number", value: model.fields.size ?? "", placeholder: "Insert data or type a number" }, { id: "stage", label: "Stage", kind: "select", mappable: true, value: model.fields.stage ?? "", options: [{ value: "lead", label: "Lead" }, { value: "qualified", label: "Qualified" }, { value: "customer", label: "Customer" }], }, { id: "note", label: "Note", kind: "long", value: model.fields.note ?? "" }, ], data: formData.slice(0, 1), test: { note: "Testing creates a real contact.", ...(model.test === "running" ? { status: "running" as const } : model.test === "done" ? { status: "succeeded" as const, stale: model.stale, fields: [{ label: "Contact ID", value: "c_8124" }, { label: "Contact link", value: "https://crm.northwind.example/c/8124" }], output: JSON.stringify({ id: "c_8124", url: "https://crm.northwind.example/c/8124", owner: "Jonah Okafor" }, null, 2), } : {}), }, can: ["test", "connect", "rename", "change"], }, onEmit: { RequestedApp: () => undefined, RequestedEvent: () => undefined, RequestedAppEvent: () => undefined, RequestedAccount: ({ account }) => Message.ChoseAccount({ account }), RequestedConnect: () => undefined, RequestedOptions: () => undefined, RequestedField: ({ field, value }) => Message.SetField({ field, value }), RequestedSample: () => undefined, RequestedRename: () => undefined, RequestedTest: () => Message.Tested(), }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/mapperUsage
import { type MapperData, type MapperField, StepConfigurator } from "./ui/uicontext/components/kit/Mapper.ts"import type { StepPickerApp } from "./ui/uicontext/components/kit/StepPicker.ts"const Message = UiSchema.TaggedEnum({ PickedStep: { step: Schema.String, app: Schema.String, event: Schema.String }, SetStepField: { step: Schema.String, field: Schema.String, value: Schema.String }, TestedStep: { step: Schema.String },})export const StepSetup = ( h: Html.H<typeof Message.Type>, step: { readonly id: string; readonly app: string | null; readonly event: string | null }, apps: ReadonlyArray<StepPickerApp>, fields: ReadonlyArray<MapperField>, data: ReadonlyArray<MapperData>,) => StepConfigurator(h, { key: step.id, props: { id: step.id, title: "2. Create contact", app: { value: step.app, options: [] }, event: { value: step.event, options: [] }, catalog: { apps, for: "action" }, fields, data, test: { note: "Testing creates a real contact." }, can: ["test", "change"], }, onEmit: { RequestedAppEvent: ({ id, app, event }) => Message.PickedStep({ step: id, app, event }), RequestedField: ({ id, field, value }) => Message.SetStepField({ step: id, field, value }), RequestedTest: ({ id }) => Message.TestedStep({ step: id }), RequestedApp: () => undefined, RequestedEvent: () => undefined, RequestedAccount: () => undefined, RequestedConnect: () => undefined, RequestedOptions: () => undefined, RequestedSample: () => undefined, RequestedRename: () => undefined, }, })Examples
A new step
A step added from the canvas opens the catalog first; once chosen, Change opens it again.
3. New step
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { StepConfigurator } from "./ui/uicontext/components/kit/Mapper.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { catalog, formData } from "./automation.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 34rem)" } })const Message = UiSchema.TaggedEnum({ Picked: { app: Schema.String, event: Schema.String } })export const NewStep = Html.component({ name: "NewStep", model: Schema.Struct({ app: Schema.NullOr(Schema.String), event: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ app: null, event: null }), update: { Picked: ($, { app, event }) => ({ app, event }) }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( StepConfigurator(h, { key: "new", props: { id: "new", agentId: "step:mapper-choose", title: "3. New step", app: { value: model.app, options: [] }, event: { value: model.event, options: [] }, catalog: { apps: catalog, for: "action", recent: ["chat"] }, fields: [{ id: "message", label: "Message", kind: "long", required: true, value: "" }], data: formData, can: ["change"], }, onEmit: { RequestedAppEvent: ({ app, event }) => Message.Picked({ app, event }), RequestedApp: () => undefined, RequestedEvent: () => undefined, RequestedAccount: () => undefined, RequestedConnect: () => undefined, RequestedOptions: () => undefined, RequestedField: () => undefined, RequestedSample: () => undefined, RequestedRename: () => undefined, RequestedTest: () => undefined, }, }), ),})Filter conditions
A filter or a path takes rules: data, a comparison and a value, joined by all or any.
2. Only big companies
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { encodeConditions, StepConfigurator } from "./ui/uicontext/components/kit/Mapper.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { catalog, formData, operators } from "./automation.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 40rem)" } })const Message = UiSchema.TaggedEnum({ SetConditions: { value: Schema.String } })export const OnlyBigCompanies = Html.component({ name: "OnlyBigCompanies", model: Schema.String, message: Message,}).make({ init: () => encodeConditions({ match: "all", rules: [ { left: "{{form.company_size}}", op: "gt", right: "200" }, { left: "{{form.work_email}}", op: "exists", right: "" }, ], }), update: { SetConditions: (_$, { value }) => value }, view: (h, conditions) => h.div.attrs(sx(styles.frame)).children( StepConfigurator(h, { key: "filter", props: { id: "filter", agentId: "step:mapper-filter", title: "2. Only big companies", app: { value: "filter", options: [] }, event: { value: "only-if", options: [] }, catalog: { apps: catalog, for: "action" }, fields: [{ id: "conditions", label: "Conditions", kind: "conditions", required: true, value: conditions, operators }], data: formData.slice(0, 1), can: ["change"], }, onEmit: { RequestedField: ({ value }) => Message.SetConditions({ value }), RequestedAppEvent: () => undefined, RequestedApp: () => undefined, RequestedEvent: () => undefined, RequestedAccount: () => undefined, RequestedConnect: () => undefined, RequestedOptions: () => undefined, RequestedSample: () => undefined, RequestedRename: () => undefined, RequestedTest: () => undefined, }, }), ),})A trigger with an expired account
The trigger's test found records to choose a sample from; its account needs signing in again before it can run.
1. New form response
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { StepConfigurator } from "./ui/uicontext/components/kit/Mapper.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { catalog } from "./automation.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 34rem)" } })const Message = UiSchema.TaggedEnum({ ChoseSample: { sample: Schema.String } })export const TriggerSamples = Html.component({ name: "TriggerSamples", model: Schema.String, message: Message,}).make({ init: () => "resp-118", update: { ChoseSample: (_$, { sample }) => sample }, view: (h, sample) => h.div.attrs(sx(styles.frame)).children( StepConfigurator(h, { key: "trigger", props: { id: "form", agentId: "step:mapper-trigger", title: "1. New form response", app: { value: "forms", options: [] }, event: { value: "new-response", options: [] }, catalog: { apps: catalog, for: "trigger" }, account: { label: "Forms account", value: "maya", options: [{ value: "maya", label: "[email protected]", note: "Sign-in expired" }], reconnect: "This Forms account can’t be used: the sign-in expired on Nov 24.", }, fields: [{ id: "form", label: "Form", kind: "select", required: true, value: "inquiries", options: [{ value: "inquiries", label: "Website inquiries" }, { value: "cancellation", label: "Cancellation survey" }], }], test: { status: "succeeded", note: "Finds recent responses to use as sample data for later steps.", samples: { value: sample, options: [ { id: "resp-118", label: "Iris Morrow, Halcyon Health", detail: "Nov 30 · “We’d like a demo for our care team.”" }, { id: "resp-117", label: "Tomas Reyes, Northwind Freight", detail: "Nov 29 · No work email" }, { id: "resp-116", label: "Ana Lindqvist, Brightline Studio", detail: "Nov 28" }, ], }, }, can: ["test", "connect", "change"], }, onEmit: { RequestedSample: ({ sample: next }) => Message.ChoseSample({ sample: next }), RequestedAppEvent: () => undefined, RequestedApp: () => undefined, RequestedEvent: () => undefined, RequestedAccount: () => undefined, RequestedConnect: () => undefined, RequestedOptions: () => undefined, RequestedField: () => undefined, RequestedRename: () => undefined, RequestedTest: () => undefined, }, }), ),})API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
idrequired | string | — | The step's id, sent back with every request |
titlerequired | string | — | "2. Create contact" |
apprequired | MapperChoice | — | Which app the step uses, and the apps to choose from |
event | MapperChoice | — | Shown once there's an app |
catalog | MapperCatalog | — | The catalog to choose the app and event from; replaces the app and event lists |
account | { connectLabel, reconnect } | — | Shown once there's an event that needs one; reconnect says why the chosen account needs signing in again |
fields | MapperField[] | — | The step's inputs, shown once the app, event and account are chosen |
data | MapperData[] | — | Data from earlier steps, with samples, that fields can insert |
test | MapperTest | — | The last test of the step and what testing does |
canrequired | StepConfiguratorCapability[] | — | What the viewer may do: test the step, connect an account, rename it, change its app |
readOnly | Notice | — | Why the step can't be changed; shows its setup without controls |
outcome | Outcome | null | — | The app's answer to the request in flight; its request is "app", "event", "account", "field", "test", "connect", "rename" or "sample" |
agentId | string | step:<id> | The id agents know this step by; step:<id> by default |
autoFocus | boolean | — | Move focus to the catalog's search when it shows, as for a step just added |
Events
| Event | Payload | Description |
|---|---|---|
RequestedApp | { id: string; app: string } | The person picked an app for the step |
RequestedEvent | { id: string; event: string } | The person picked the app's event or action |
RequestedAppEvent | { id: string; app: string; event: string } | The person picked an app and its event at once, from the catalog |
RequestedAccount | { id: string; account: string } | The person picked a connected account |
RequestedConnect | { id: string; account?: string } | Start connecting an account (the app runs the sign-in); account names one to sign in to again |
RequestedOptions | { id: string; field: string } | Load a select field's choices again |
RequestedField | { id: string; field: string; value: string } | A field's new value: when a text field is left, a pill goes in or out, or a select or switch changes |
RequestedSample | { id: string; sample: string } | The person chose the record later steps use as their sample |
RequestedRename | { id: string; title: string } | The step's new name |
RequestedTest | { id: string } | Run a test of the step |
Agent actions
| Action | Description |
|---|---|
ChoseApp | Choose the app by value (see page_query) |
ChoseEvent | Choose the event by value |
PickedStepPicker | Choose what the step does from the catalog, by app id and event id (choices app/event) |
ChoseAccount | Choose the account by value |
ClickedConnect | Start connecting a new account (a person signs in) |
SetField | Set a field by id. Map data with {{step.path}} tokens from page_query; a conditions field takes JSON {match, rules:[{left, op, right}]}. |
ChoseSample | Choose the sample record later steps use |
ClickedTest | Test the step with the data it maps |
Accessibility
- Setup, fields and test are fieldsets with legends; each field's hint, type warning and error are tied to it with
aria-describedby. - A field's text and pills are one labelled group. Backspace at the start of a text run removes the pill before it, and the arrow keys step over pills.
- Insert data opens a searchable list of earlier steps' outputs; the arrows and Enter insert one at the caret.
- A text field sends its value when you leave it, so typing never sends a request per key. The test result is announced when it arrives.