// — the fields of the picked node, and what can be done to // it: move it under another node, change when it runs among its siblings, // remove it. Every change goes out as an `Edit` of the flow; the editor shows // the reason when one is refused. New nodes come from the canvas palette. import { Button } from "../../ui/button/Button.js"; import { Card } from "../../ui/card/Card.js"; import { CheckboxField } from "../../ui/checkbox-field/CheckboxField.js"; import { SelectField } from "../../ui/select-field/SelectField.js"; import { TextAreaField } from "../../ui/text-area-field/TextAreaField.js"; import { TextField } from "../../ui/text-field/TextField.js"; import { moveAmongSiblings, parentOf, removeNode, reparent, replaceNode, siblingPosition, type Edit, type Limits, withOp, } from "./FlowDraft.js"; import { kindValues, ordinal, type Condition, type Described, type Flow, type FlowNode, type FlowSchema, } from "./FlowTypes.js"; type TodoNode = Extract; const OPS_FALLBACK = ["upsert", "clear"]; // The kinds this editor has fields for. const KNOWN_KINDS: string[] = ["source", "match", "todo", "request_reviewer"]; function options(list: Described[]) { return list.map((d) => ({ value: d.name, label: d.description ? `${d.name} — ${d.description}` : d.name, })); } export function NodeInspector({ flow, node, schema, limits, onEdit, }: { flow: Flow; node: FlowNode; schema: FlowSchema; limits: Limits; // `select` is the node to pick once the edit is applied. onEdit: (edit: Edit, select?: string) => void; }) { const set = (next: FlowNode) => onEdit(replaceNode(flow, next)); const fieldOptions = options(schema.fields); const firstField = schema.fields[0]?.name ?? ""; const key = `ne-${node.id}`; const parent = parentOf(flow, node.id); // Where it can go: under its current parent, or under any node it could be // moved to. const parents = flow.nodes .filter( (n) => n.id === parent || (n.id !== node.id && reparent(flow, node.id, n.id, limits).ok), ) .map((n) => ({ value: n.id, label: `${n.kind} ${n.id}` })); const order = siblingPosition(flow, node.id); return (

{node.kind}{" "} {node.id !== node.kind ? ( {node.id} ) : null}

{node.kind === "source" ? (
forge events {schema.source_events.map((ev) => ( set({ ...node, events: on ? [...node.events, ev.name] : node.events.filter((e) => e !== ev.name), }) } /> ))}
) : null} {node.kind === "match" ? ( ) : null} {node.kind === "todo" ? ( ) : null} {node.kind === "request_reviewer" ? (
asks for a review set({ ...node, reviewer })} />
) : null} {!KNOWN_KINDS.includes(node.kind) ? (

This editor does not know how to edit a {node.kind}. It is kept as it is when you save.

) : null} {order.count > 1 ? (
runs {ordinal(order.index + 1)} of {order.count} below its parent
) : null}
{node.kind !== "source" ? ( ) : null}
{node.kind !== "source" && parent !== undefined ? ( onEdit(reparent(flow, node.id, p, limits))} /> ) : null}
); } function MatchFields({ node, keyPrefix, fieldOptions, firstField, onChange, }: { node: Extract; keyPrefix: string; fieldOptions: { value: string; label: string }[]; firstField: string; onChange: (next: FlowNode) => void; }) { const setWhen = (when: Condition[]) => onChange({ ...node, when }); return (
passes when all of these hold {node.when.length === 0 ?

no condition: passes everything

: null} {node.when.map((c, i) => (
setWhen(node.when.map((x, j) => (j === i ? { ...x, field } : x))) } /> setWhen(node.when.map((x, j) => (j === i ? { ...x, equals } : x))) } />
))}
); } function TodoFields({ node, keyPrefix, schema, fieldOptions, firstField, onChange, }: { node: TodoNode; keyPrefix: string; schema: FlowSchema; fieldOptions: { value: string; label: string }[]; firstField: string; onChange: (next: FlowNode) => void; }) { const ops = kindValues(schema, "todo", "op"); const opList = (ops.length > 0 ? ops : OPS_FALLBACK).map((o) => ({ value: o, label: o, })); const byField = "field" in node.to; const hint = schema.fields.map((f) => `{${f.name}}`).join(" "); return (
emits a todo onChange(withOp(node, op as TodoNode["op"]))} /> onChange({ ...node, to: kind === "field" ? { field: firstField } : { agent: "" }, }) } /> {"field" in node.to ? ( onChange({ ...node, to: { field } })} /> ) : ( onChange({ ...node, to: { agent } })} /> )} onChange({ ...node, key: k })} /> {node.op === "clear" ? ( onChange({ ...node, prefix })} /> ) : ( onChange({ ...node, text })} /> )}

The key and text can use {hint}

); }