Step list
A linear automation: steps down a rail, branches nested under bands; add, move, remove in place.
import { StepList, insertStep, removeStep, moveStep, findStep } from "@forgeron/ui";- Trigger:
import { GitForkIcon, Mail01Icon, Message01Icon, TrophyIcon } from "@forgeron/icons";
import { StepList } from "@forgeron/ui";
export default function Default() {
return (
<div style={{ width: 340, paddingTop: 10 }}>
<StepList
readOnly
defaultSteps={[
{
id: "t",
kind: "trigger",
icon: TrophyIcon,
title: "Deal moved to Won",
subtitle: "CRM · onDealWon()",
},
{
id: "if",
kind: "logic",
icon: GitForkIcon,
title: "Above €5,000?",
subtitle: "Flows · ifElse()",
},
{
id: "chat",
icon: Message01Icon,
title: "Tell #sales",
subtitle: "Chat · postMessage()",
},
{
id: "mail",
icon: Mail01Icon,
title: "Thank the client",
subtitle: "Mail relay · send()",
},
]}
/>
</div>
);
}- Trigger:
- truefalse
import {
GitForkIcon,
Invoice01Icon,
Mail01Icon,
Message01Icon,
Task01Icon,
TrophyIcon,
} from "@forgeron/icons";
import {
Dialog,
StepList,
StepPicker,
insertStep,
type AutomationStep,
type StepOption,
type StepPlace,
} from "@forgeron/ui";
import { useState } from "react";
const actions: StepOption[] = [
{ id: "chat", group: "apps", icon: Message01Icon, app: "Chat", label: "Post a message" },
{ id: "mail", group: "apps", icon: Mail01Icon, app: "Mail relay", label: "Send an email" },
{ id: "task", group: "apps", icon: Task01Icon, app: "Tasks", label: "Create a task" },
{ id: "invoice", group: "apps", icon: Invoice01Icon, app: "Invoices", label: "Draft an invoice" },
];
const start: AutomationStep[] = [
{
id: "t",
kind: "trigger",
icon: TrophyIcon,
title: "Deal moved to Won",
subtitle: "CRM · onDealWon()",
},
{
id: "if",
kind: "logic",
icon: GitForkIcon,
title: "Above €5,000?",
subtitle: "Flows · ifElse()",
branches: [
{
id: "if-true",
label: "true",
steps: [
{ id: "cfo", icon: Mail01Icon, title: "Mail the CFO", subtitle: "Mail relay · send()" },
],
},
{ id: "if-false", label: "false", steps: [] },
],
},
{ id: "chat", icon: Message01Icon, title: "Tell #sales", subtitle: "Chat · postMessage()" },
];
let seq = 0;
// The list asks for a step at a place; the screen opens a picker and inserts what is picked.
// Alt + Up / Down moves the focused step, Delete removes it.
export default function EditorWithBranches() {
const [steps, setSteps] = useState<ReadonlyArray<AutomationStep>>(start);
const [selected, setSelected] = useState<string | null>("if");
const [place, setPlace] = useState<StepPlace | null>(null);
const pick = (id: string) => {
const option = actions.find((a) => a.id === id);
if (!option || !place) return;
const step: AutomationStep = {
id: `${id}-${(seq += 1)}`,
icon: option.icon,
title: option.label,
subtitle: `${option.app} · ${id}()`,
};
setSteps(insertStep(steps, step, place));
setSelected(step.id);
setPlace(null);
};
return (
<div style={{ width: "100%", maxWidth: 640, paddingTop: 10 }}>
<StepList
steps={steps}
onChange={setSteps}
selected={selected}
onSelect={setSelected}
onInsert={setPlace}
/>
{place ? (
<Dialog title="Add a step" onClose={() => setPlace(null)}>
<StepPicker options={actions} categories={false} onPick={pick} autoFocus />
</Dialog>
) : null}
</div>
);
}- Trigger: Succeeded
- Succeededtrue
- Succeeded
- Failed
false- Not reached
import { GitForkIcon, Invoice01Icon, Mail01Icon, Message01Icon, TrophyIcon } from "@forgeron/icons";
import { StepList } from "@forgeron/ui";
// A run replayed on the list: each step with its state, the branch not taken is not reached.
export default function AFailedRun() {
return (
<div style={{ width: "100%", maxWidth: 640, paddingTop: 10 }}>
<StepList
readOnly
defaultSteps={[
{
id: "t",
kind: "trigger",
icon: TrophyIcon,
title: "Deal moved to Won",
status: "success",
meta: "4 ms · 1 item",
},
{
id: "if",
kind: "logic",
icon: GitForkIcon,
title: "Above €5,000?",
status: "success",
meta: "1 ms · true",
branches: [
{
id: "y",
label: "true",
steps: [
{
id: "inv",
icon: Invoice01Icon,
title: "Draft the invoice",
status: "success",
meta: "310 ms · 1 item",
},
{
id: "mail",
icon: Mail01Icon,
title: "Send it",
status: "error",
error: "Mail relay answered 503 three times",
},
],
},
{
id: "n",
label: "false",
steps: [
{ id: "chat", icon: Message01Icon, title: "Tell #sales", status: "skipped" },
],
},
],
},
]}
/>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
steps / defaultSteps | AutomationStep[] | — | { id, title, subtitle?, icon, kind?, status?, meta?, error?, disabled?, branches?: { id, label, steps }[] }. |
onChange | (steps) => void | — | Every move and removal, as the new tree. |
selected / onSelect | string / (id) => void | — | The open step. |
onInsert | (place: { branch?, index }) => void | — | Asks for a step there: open a StepPicker, then insertStep. Without it, no add button. |
readOnly | boolean | — | Shows without editing: a run, a published version. |
empty | ReactNode | — | Shown when there is no step. |
className | string | — | Extra classes. |