// --------------------------------------------------------------------------- // automation/TriggerPicker.tsx — WAVE 25 item 5b (contract C2, ruling R9/R14): // ONE picker, TWO presentations. // // The owner's complaint (reference/ERROR 3.png) is precise: Properties → // Trigger details → Trigger type is a native `` missing its `value` // renders the FIRST option; a custom listbox renders NOTHING selected and lets // the next patch write the blank over a real stored key. `selectedTrigger` // (steps.ts, executed by `verify_steps.py`) owns that answer so it is asserted // rather than eyeballed — the grouping and the selection are the two things a // screenshot proves worst. // --------------------------------------------------------------------------- import { useEffect, useRef, useState } from "react"; import { brandForConnector, brandForKind, hasBrandKind } from "../connectors/brandMarks"; import type { TriggerOption } from "./automationApi"; import { groupTriggers, selectedTrigger } from "./steps"; /** * A trigger's icon, PER KIND. Drawn, never an emoji (owner constant). * * ⚠ MOVED HERE FROM `AutomationBuilder.tsx` (wave 25), unchanged apart from the two new keys. * It belongs with the picker that shows it: it was private to the builder while the ONLY marked * surface was the builder's own menu, and the whole of item 5b is that the compact control has * to wear the same marks. A second copy over there was the alternative, which is how two * controls choosing one thing come to look like two features in the first place. * * ⚠ THE FIRST VERSION DREW ONE GLYPH FOR ALL ELEVEN, and reading the suggested list settled it: * six identical arrows down the left edge is decoration, not information — the eye learns * nothing and the column just gets wider. Unknown keys keep the neutral arrow, so a trigger the * engine adds tomorrow renders plainly rather than not at all (the silent-drop rule, applied to * icons). */ export function TriggerMark({ kind = "" }: { kind?: string }) { /* ⭐⭐ WAVE 30 · ITEM 7 / R3 + R4 — A BRAND WINS OVER THE HOUSE GLYPH, and it is resolved HERE rather than at the four call sites. `TriggerMark` is drawn in the flyout, in the compact Properties control, and by `AutomationBuilder` on the trigger card; a per-call-site check is three chances to give the same trigger two identities on one screen. ⛔ The geometric glyphs BELOW ARE NOT DELETED. They are the fallback for every unbranded trigger and, for the two branded ones, the record of what this picker drew before the owner asked for logos — a magnifier with a person in it, and the same frame with a note. Deleting them would also delete the only description of why those two shapes differed. */ const brand = brandForKind(kind); if (brand) return brand; const common = { width: 15, height: 15, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" as const, strokeLinejoin: "round" as const, "aria-hidden": true, }; if (kind === "schedule") return ( ); if (kind === "event_field") return ( ); if (kind === "record_created") return ( ); if (kind === "record_updated") return ( ); if (kind === "enters_view") return ( ); if (kind === "webhook") return ( ); if (kind === "email") return ( ); if (kind === "form_submitted") return ( ); if (kind === "button_clicked") return ( ); if (kind === "comment_added") return ( ); /* WAVE 24 — a magnifier with a PERSON inside it: this one does not watch a database, it searches a corpus of profiles and makes rows out of what fits. ⚠ Deliberately not the bare magnifier — `ActionMark`'s `find_records` already owns that shape for "search a database", and two searches drawn identically would be the six-identical-arrows problem this component's header talks itself out of. */ if (kind === "ig_profile_match") return ( ); /* ⭐ WAVE 25 (R9) — THE TWO NEW PLANNED KEYS. They render FADED and `clean_trigger` refuses them at the door, but they still need a mark: an unmarked row in a marked list reads as a rendering fault rather than as "not built yet", and the neutral arrow is what every unknown key already gets — so the faded row would have been indistinguishable from a trigger this client has never heard of. */ // A PAGE with a delta on it: the thing being watched is a document, and what fires is that it // is DIFFERENT from last time. Not the magnifier — this one watches one page rather than // searching a corpus, which is the distinction the Scraper nest otherwise loses. if (kind === "web_page_changed") return ( ); // A MUSICAL NOTE inside the same search frame as `ig_profile_match`: same act (search a corpus // of profiles), different corpus. Drawing it as a second person-in-a-magnifier would say the two // are interchangeable, and they are not — the two networks have different schemas and, per wave // 29's R2, different `ut_*` families behind them. // ⚠ WAVE 29: this row is LIVE now (D-9 closed the trigger half). Nothing in this file changed to // make it so — `planned` rides the wire, which is the property that makes a server vocabulary // worth having. The sentence that used to end this note ("the claim D-9 is still open about") // was true when it was written and would have quietly aged into a lie. if (kind === "tiktok_profile_match") return ( ); return ( ); } /** * The state word a row wears, or `""`. * * TWO STATES, NOT ONE, and the difference is what the reader can DO: a PLANNED trigger is * waiting on us, a not-ready one is waiting on a connection THEY can make. Both render; only * the second offers an action (the Connect button, in Properties). */ function rowNote(t: TriggerOption): string { if (t.planned) return "Coming soon"; if (t.ready === false) return "Needs setting up"; return ""; } /** * The rows themselves, shared by both presentations — which is what makes them ONE control * rather than two that agree today. */ function TriggerList({ options, value, disabled, onPick, }: { options: TriggerOption[]; value: string; disabled: boolean; onPick: (key: string) => void; }) { const row = (t: TriggerOption) => { const on = t.key === value; return ( ); }; return ( <> {groupTriggers(options).map((g) => (
{/* An absent caption renders NO heading rather than the group id — a server older than this client gets one unlabelled section, which is honest, instead of a heading reading "connector" in lower case. */} {g.label ?

{g.label}

: null} {g.rows.map(row)} {/* ⭐⭐ WAVE 30 · ITEM 7 / R3 — THE CONNECTOR NEST IS A COLLAPSED DISCLOSURE NOW. The owner, verbatim and for the third wave: *"Only when I click 'Scraper' under each automation trigger and actions would I see the option to choose either Instagram OR TikTok. That's it."* ⛔ WHAT WAS HERE WAS THE COMPLAINT ITSELF, and it was an ASYMMETRY rather than a missing feature: this rendered `
` with a `

` heading — always open, merely indented — while `AutomationBuilder`'s action menu four inches away already used exactly the markup below. One menu asked you to click; the other showed you everything. So this is not a new pattern, it is the OTHER menu's pattern, copied verbatim so the two cannot drift apart again. ⚠ `

` and not a hand-built disclosure: it opens on Enter and Space with no keydown handler, it needs no open/closed state of its own to get wrong, and it is CLOSED by default, which is the whole ruling. ⚠ The summary wears the same 26px `autox-card-mark` the rows beneath it wear (T19's marks). A smaller slot here was the first version and it made the heading look like a different KIND of thing from its own children — which is the asymmetry again, one level down. */} {g.sub.map((s) => (
{brandForConnector(s.key) ? ( {brandForConnector(s.key)} ) : null} {s.label} {s.rows.length} trigger{s.rows.length === 1 ? "" : "s"} {s.rows.map(row)}
))}
))} ); } /** * ONE PICKER, TWO PRESENTATIONS. * * · `menu` — the open flyout the empty state's "+ Add trigger" box opens. The CALLER owns * whether it is open, because it is anchored to that box. * · `field` — the compact control in Properties → Trigger details → Trigger type. It shows the * current choice and opens the same list beneath itself. * * ⚠ `onPick` IS THE CALLER'S DECISION TO CONFIRM OR NOT. Changing a trigger can invalidate the * configuration under it, so the builder asks first when there IS something configured — that * rule lives with the automation, not in a picker, and duplicating it here would be a second * copy free to disagree with the dialog's own wording. */ export default function TriggerPicker({ variant, options, value, disabled, onPick, onDismiss, }: { variant: "menu" | "field"; options: TriggerOption[]; /** The stored trigger key. `""` = nothing picked yet. */ value: string; disabled: boolean; onPick: (key: string) => void; /** `menu` only: the caller closes itself. Ignored by `field`, which owns its own popover. */ onDismiss?: () => void; }) { const [open, setOpen] = useState(false); const wrap = useRef(null); const picked = selectedTrigger(options, value); // ⛔ ESCAPE AND AN OUTSIDE CLICK BOTH CLOSE IT, or the popover is a trap — the shell has // already paid for a scrim with no Escape (wave 24: every subsequent click swallowed by an // invisible full-screen div). Bound only while open, so the app carries no idle listeners. useEffect(() => { if (variant !== "field" || !open) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") setOpen(false); }; const onDown = (e: MouseEvent) => { if (!wrap.current?.contains(e.target as Node)) setOpen(false); }; window.addEventListener("keydown", onKey); window.addEventListener("mousedown", onDown); return () => { window.removeEventListener("keydown", onKey); window.removeEventListener("mousedown", onDown); }; }, [variant, open]); if (variant === "menu") { return (
{ onPick(k); onDismiss?.(); }} />
); } return (