fsanyoto commited on
Commit
6ec9d3b
·
verified ·
1 Parent(s): 895e79a

Prune files not in the deploy set (stale build context)

Browse files
web/src/automation/AutomationBoard.tsx DELETED
@@ -1,413 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // automation/AutomationBoard.tsx — the automation AS A BOARD (owner ruling R1).
3
- //
4
- // THE MODEL, and it is the whole point of the wave: the columns are the flow's
5
- // stages and THE CARDS ARE RECORDS. A record walks left to right; where it
6
- // currently is lives in a single-select stage field on the target database, so
7
- // the same field drives an ordinary Kanban view of that database and this board
8
- // is not a second, private opinion about where anything is. A REVIEW stage holds
9
- // its cards until a person clicks them along, and that click IS the promotion —
10
- // not a UI gesture that later gets synced.
11
- //
12
- // ⭐ WAVE 26 · ITEM 15 / R6 — "on the discovery flow it is literally the `tracked`
13
- // tick" USED TO FOLLOW THAT SENTENCE AND IS NOW FALSE. The owner deleted the
14
- // column: *"We already have a Field called stage to track the progress of the
15
- // Automation per Record. We don't need another checkbox for this."* Then, asked
16
- // whether the board keeps the Approve/Decline gesture writing to stage: no —
17
- // *"drop the review board's terminals entirely."* The automation stops having an
18
- // opinion about what happens to a candidate after it is found.
19
- //
20
- // ⛔ AND ITEM 15 TURNED OUT TO BE A VERIFICATION, NOT A DELETION, which is worth
21
- // saying plainly rather than reporting a change that did not happen. This file
22
- // never drew the built-in terminals: it renders `board.stages` verbatim (the C1
23
- // law two paragraphs down), so when A stopped APPENDING `tracked`/`declined` the
24
- // board stopped drawing them, with no client edit at all. What was left was this
25
- // comment and two in `AutomationDetail` — prose asserting a live column that no
26
- // longer exists, which is how the next session reintroduces one with a rationale
27
- // attached. The rendering was already right; the description was not.
28
- //
29
- // ⛔ IT RENDERS ONLY WHAT RIDES THE PAYLOAD (C1). Stages, their order, their
30
- // switches, their dots, the routes between them, which cards exist, which of
31
- // them may move and where to — all of it is `GET /automations/{id}/board`. This
32
- // file decides pixels. It cannot show a stage the engine stopped running, and it
33
- // does not decide whether a move is legal: it posts the drop it was given and
34
- // prints the server's refusal verbatim.
35
- //
36
- // WHAT IT COPIES AND WHAT IT DOES NOT. The look is `customer-grid`'s KanbanView
37
- // — tinted lane pill, count beside it, a column of quiet cards, drag with
38
- // post-drag click suppression — because two boards in one product that look like
39
- // two products is the defect DESIGN.md calls variety. It copies the LOOK and
40
- // shares no code: the grid tree is the asset that also ships inside the embed,
41
- // and an automation surface must not grow an edge into it (the same rule
42
- // `automationApi.ts` is built on).
43
- //
44
- // TWO TRAPS, both paid for already ([[ui-invisible-to-assertions]]):
45
- // 1. A FINISHED DRAG MUST NOT FIRE A CLICK. Browsers can deliver a click after
46
- // `dragend`, and the thing under the pointer here is an advance button —
47
- // i.e. a promotion nobody asked for. One drag suppresses exactly one click.
48
- // 2. A CAPPED LANE MUST SAY SO. `counts` is the true per-stage total and
49
- // `cards` may be shorter — server-side or by this file's own page size — so
50
- // a lane whose list is shorter than its count discloses the difference. A
51
- // silent `[:N]` is a defect, not a rendering detail
52
- // ([[no-unverifiable-aggregates]]).
53
- // ---------------------------------------------------------------------------
54
- import type { DragEvent as ReactDragEvent } from "react";
55
- import { useRef, useState } from "react";
56
-
57
- import type { Board, BoardCard, BoardStage } from "./automationApi";
58
-
59
- /** How many cards a lane paints before it offers the rest. Disclosed, never silent. */
60
- const LANE_PAGE = 25;
61
-
62
- interface Props {
63
- board: Board;
64
- /** The selected STAGE id — the right-hand panel shows that stage's config. */
65
- selected: string;
66
- onSelect: (stageId: string) => void;
67
- onToggle: (stageId: string) => void;
68
- busyStage: string;
69
- /** Post a card move. The caller answers with a fresh board (or a refusal). */
70
- onMove: (rowId: string, to: string) => void;
71
- movingRow: string;
72
- }
73
-
74
- /**
75
- * A stage's tint class.
76
- *
77
- * DESIGN.md 3's fixed semantics, applied: yellow = attention, and a review stage
78
- * is the one that is WAITING FOR A PERSON; purple = group/routing controls, which
79
- * is what a branch is; blue = the ordinary interactive body of the flow. Anything
80
- * the server names that this file has never heard of lands on the neutral face
81
- * and is still drawn — a stage that renders plainly is visible, a stage that
82
- * renders as nothing is the silent drop this codebase keeps paying for.
83
- */
84
- function tintOf(stage: BoardStage): string {
85
- if (stage.kind === "review" || stage.posture === "strict") return " is-review";
86
- if (stage.kind === "branch") return " is-branch";
87
- if (stage.kind === "action") return " is-action";
88
- return "";
89
- }
90
-
91
- function postureTitle(stage: BoardStage): string {
92
- if (stage.posture === "strict")
93
- return `${stage.label} — holds each record until a person moves it along`;
94
- if (stage.posture === "auto") return `${stage.label} — the automation moves records through`;
95
- return stage.label;
96
- }
97
-
98
- /** A timestamp trimmed to the minute. Never a record VALUE — those arrive composed (C1). */
99
- function whenText(iso: string): string {
100
- const raw = String(iso || "");
101
- return raw ? raw.replace("T", " ").slice(0, 16) : "";
102
- }
103
-
104
- export default function AutomationBoard({
105
- board,
106
- selected,
107
- onSelect,
108
- onToggle,
109
- busyStage,
110
- onMove,
111
- movingRow,
112
- }: Props) {
113
- const [expanded, setExpanded] = useState<Set<string>>(new Set());
114
- const [dragging, setDragging] = useState<BoardCard | null>(null);
115
- const draggedRef = useRef(false);
116
-
117
- const stages = board?.stages || [];
118
- const labels = new Map(stages.map((s) => [s.id, s.label]));
119
- // ⚠ NOT EVERY STAGE IS A PLACE. Two kinds of stage cannot hold a record and must not
120
- // be drawn as lanes:
121
- // · the TRIGGER — a record is never "at" the trigger; the trigger is what puts one
122
- // on the board. Its configuration lives in the trigger face above this component.
123
- // · anything the server marks `record: false` — the things the automation DOES
124
- // (find, collect, write). On a real discovery flow that is three of six stages, so
125
- // drawing them as lanes puts three permanently empty columns between the trigger
126
- // and the first column that ever holds anything.
127
- // They render as the PROCESS STRIP: still clickable, still switchable, still carrying
128
- // their own dot — everything except a column of cards they can never contain.
129
- //
130
- // `record` is OPTIONAL and absent means LANE (see its note in automationApi): only an
131
- // explicit `false` moves a stage into the strip, so a server that ships C1's contract
132
- // text and not this field still draws the board it describes.
133
- const boardStages = stages.filter((s) => s.kind !== "trigger");
134
- /*
135
- * ⭐ WAVE 24 (owner item 9) — THE PROCESS STRIP IS GONE, AND `record` IS NOT.
136
- *
137
- * The strip drew the things the automation DOES — Capture / Bright Data / Anonymous / Post
138
- * engagement / Write — as chips above the lanes. C-CFG moves every one of those bodies, and
139
- * the FOUR switches they carried (`capture_paid`, `capture_anon`, `capture_metrics` and
140
- * `write`'s dry run), into Properties → Configuration → "How this fetches". The board is for
141
- * reading where records ARE; a stage that can never hold one was never a place.
142
- *
143
- * ⛔ THE `record` FIELD STAYS IN THE TYPE AND THIS FILTER STAYS IN THE CODE. The server still
144
- * sends `record: false` stages — `graph()` still emits those nodes and the engine still RUNS
145
- * them; only the drawing stopped. Deleting the field would be a CLIENT UNION OVER A SERVER
146
- * VOCABULARY, and the failure mode is the silent one this file's own header warns about: with
147
- * no `record` to test, every one of those stages would come back as a LANE, and a discovery
148
- * flow would paint three permanently empty columns between the trigger and the first real one.
149
- * So `record === false` still means "not a lane" — it just no longer means "a chip" either.
150
- */
151
- const laneStages = boardStages.filter((s) => s.record !== false);
152
- const cols = [...new Set(laneStages.map((s) => s.col))].sort((a, b) => a - b);
153
-
154
- const byStage = new Map<string, BoardCard[]>();
155
- for (const c of board?.cards || []) {
156
- const list = byStage.get(c.stageId);
157
- if (list) list.push(c);
158
- else byStage.set(c.stageId, [c]);
159
- }
160
-
161
- const advance = (card: BoardCard, to: string) => {
162
- // Trap 1: swallow the click a finished drag can produce.
163
- if (draggedRef.current) return;
164
- onMove(card.rowId, to);
165
- };
166
-
167
- const onDrop = (stage: BoardStage) => (e: ReactDragEvent<HTMLDivElement>) => {
168
- e.preventDefault();
169
- const rowId = e.dataTransfer.getData("text/plain");
170
- setDragging(null);
171
- if (!rowId) return;
172
- const card = (board.cards || []).find((c) => c.rowId === rowId);
173
- if (!card || card.stageId === stage.id) return;
174
- onMove(rowId, stage.id);
175
- };
176
-
177
- const cardBox = (card: BoardCard) => {
178
- const moving = movingRow === card.rowId;
179
- const nexts = card.canAdvance ? card.next || [] : [];
180
- return (
181
- <div
182
- key={card.rowId}
183
- className={
184
- "autob-card" +
185
- (card.canAdvance ? " is-draggable" : "") +
186
- (moving ? " is-moving" : "")
187
- }
188
- draggable={card.canAdvance && !moving}
189
- title={
190
- card.canAdvance
191
- ? undefined
192
- : "The server does not allow you to move this card."
193
- }
194
- onDragStart={
195
- card.canAdvance
196
- ? (e) => {
197
- draggedRef.current = true;
198
- setDragging(card);
199
- e.dataTransfer.setData("text/plain", card.rowId);
200
- }
201
- : undefined
202
- }
203
- onDragEnd={() => {
204
- setDragging(null);
205
- // Cleared a tick later: the post-drag click arrives before this fires.
206
- window.setTimeout(() => {
207
- draggedRef.current = false;
208
- }, 0);
209
- }}
210
- >
211
- <span className="autob-card-title">
212
- {card.title}
213
- {/*
214
- ⭐ C5's CYCLE BADGE. A record that has been round the flow more than once is a
215
- different fact from a record on its first pass — on a reset-mode automation it is
216
- the difference between "working" and "looping" — so the card says so.
217
- ⚠ FROM 2 UPWARDS ONLY, and that is what makes an ABSENT count safe: every card
218
- would otherwise wear "x1", which is noise on the common case and, worse, a claim
219
- about a number the server has not sent yet (see `BoardCard.cycles`).
220
- */}
221
- {typeof card.cycles === "number" && card.cycles >= 2 ? (
222
- <span
223
- className="autob-card-cycles"
224
- title={`This record has been round this flow ${card.cycles} times`}
225
- >
226
- &times;{card.cycles}
227
- </span>
228
- ) : null}
229
- </span>
230
- {card.sub ? <span className="autob-card-sub">{card.sub}</span> : null}
231
- {card.movedAt ? (
232
- <span className="autob-card-when">{whenText(card.movedAt)}</span>
233
- ) : null}
234
- {nexts.length ? (
235
- <div className="autob-card-moves">
236
- {nexts.map((to) => (
237
- <button
238
- key={to}
239
- type="button"
240
- className="autob-card-advance"
241
- disabled={moving}
242
- title={`Move ${card.title} to ${labels.get(to) || to}`}
243
- onClick={() => advance(card, to)}
244
- >
245
- {nexts.length === 1 ? "Move on" : labels.get(to) || to}
246
- <svg width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
247
- <path
248
- d="M3.4 8h9.2M9 4.4 12.6 8 9 11.6"
249
- stroke="currentColor"
250
- strokeWidth="1.5"
251
- strokeLinecap="round"
252
- strokeLinejoin="round"
253
- />
254
- </svg>
255
- </button>
256
- ))}
257
- </div>
258
- ) : null}
259
- </div>
260
- );
261
- };
262
-
263
- const lane = (stage: BoardStage) => {
264
- const all = byStage.get(stage.id) || [];
265
- const open = expanded.has(stage.id);
266
- const shown = open ? all : all.slice(0, LANE_PAGE);
267
- // The TRUE total is the server's count; the list may be shorter for two
268
- // independent reasons, and the disclosure covers both without pretending to
269
- // know which one applied.
270
- const total = typeof board.counts?.[stage.id] === "number"
271
- ? board.counts[stage.id]
272
- : all.length;
273
- // TWO independent caps, and they need different controls. This file hiding
274
- // cards it HAS is expandable; the server not having SENT them is not — and an
275
- // expander offered for the second case is a control that lies.
276
- const clientCapped = shown.length < all.length;
277
- // A DERIVED bucket takes no drop: `record && !assignable` means cards appear there
278
- // from what is true about the row, and nothing may stamp one in. The server would
279
- // refuse it anyway — this just stops the board from inviting the refusal.
280
- const droppable = stage.assignable !== false;
281
- const legal = droppable && !!dragging && (dragging.next || []).includes(stage.id);
282
- const outgoing = (board.routes || []).filter((r) => r.from === stage.id && r.condition);
283
-
284
- return (
285
- <div
286
- key={stage.id}
287
- className={
288
- "autob-lane" +
289
- tintOf(stage) +
290
- (stage.id === selected ? " is-selected" : "") +
291
- (stage.enabled ? "" : " is-off") +
292
- (legal ? " is-target" : "")
293
- }
294
- onDragOver={droppable ? (e) => e.preventDefault() : undefined}
295
- onDrop={droppable ? onDrop(stage) : undefined}
296
- >
297
- <div className="autob-lane-head">
298
- <button
299
- type="button"
300
- className="autob-lane-hit"
301
- aria-pressed={stage.id === selected}
302
- title={postureTitle(stage)}
303
- onClick={() => onSelect(stage.id)}
304
- >
305
- <span className="autob-lane-pill">{stage.label}</span>
306
- <span className="autob-lane-count">{total.toLocaleString()}</span>
307
- {/* ⭐ WAVE 26 · ITEM 18 / R14 — THE LANE'S STATUS DOT IS DELETED.
308
- ⚠ NOT REPLACED BY THE LOOP MARK, and that is the ruling read carefully: R14 says
309
- each AUTOMATION carries the mark. A lane is not an automation — it is one stage of
310
- one — so painting the same mark on every column would say nothing and repeat it
311
- per lane. The lane already carries the two facts it owns: its name and its count.
312
- `postureTitle(stage)` still explains the lane on the button's own tooltip. */}
313
- </button>
314
- {stage.toggle ? (
315
- <button
316
- type="button"
317
- className={"auto-step-switch autob-lane-switch" + (stage.enabled ? " is-on" : "")}
318
- disabled={busyStage === stage.id}
319
- aria-pressed={stage.enabled}
320
- aria-label={`${stage.enabled ? "Turn off" : "Turn on"} ${stage.label}`}
321
- title={`${stage.enabled ? "Turn off" : "Turn on"} ${stage.label}`}
322
- onClick={() => onToggle(stage.id)}
323
- >
324
- <span className="auto-step-switch-knob" />
325
- </button>
326
- ) : null}
327
- </div>
328
-
329
- <div className="autob-lane-cards">{shown.map(cardBox)}</div>
330
-
331
- {clientCapped ? (
332
- <button
333
- type="button"
334
- className="autob-lane-more"
335
- onClick={() => setExpanded((prev) => new Set(prev).add(stage.id))}
336
- >
337
- Showing {shown.length.toLocaleString()} of {total.toLocaleString()} — show all
338
- </button>
339
- ) : shown.length < total ? (
340
- // The rest were never sent, so there is nothing here to expand. `truncated` is
341
- // the server saying so in its own words; the arithmetic agrees either way, and
342
- // the field is what makes the sentence a quotation rather than a deduction.
343
- <p
344
- className="autob-lane-more is-flat"
345
- title={
346
- (board.truncated || []).includes(stage.id)
347
- ? "The server sent the first batch for this stage; the count is the true total."
348
- : undefined
349
- }
350
- >
351
- Showing {shown.length.toLocaleString()} of {total.toLocaleString()}
352
- </p>
353
- ) : null}
354
-
355
- {outgoing.length ? (
356
- <div className="autob-lane-routes">
357
- {outgoing.map((r) => (
358
- <span key={`${r.from}-${r.to}`} className="autob-route" title="Records matching this go there next">
359
- {r.label ||
360
- `${r.condition?.field} ${r.condition?.op} ${r.condition?.value ?? ""}`.trim()}
361
- {" → "}
362
- {labels.get(r.to) || r.to}
363
- </span>
364
- ))}
365
- </div>
366
- ) : null}
367
- </div>
368
- );
369
- };
370
-
371
- if (!boardStages.length) {
372
- return (
373
- <div className="autob-board">
374
- <p className="autob-board-note">This automation has no stages yet.</p>
375
- </div>
376
- );
377
- }
378
-
379
- return (
380
- <div className="autob-board">
381
- {!board.stageField ? (
382
- <p className="autob-board-note">
383
- Records appear here once this flow is bound to a database.
384
- </p>
385
- ) : null}
386
- {/*
387
- ⛔ THE PROCESS STRIP WAS RENDERED HERE AND IS DELETED (wave 24, owner item 9).
388
- Capture / Bright Data / Anonymous / Post engagement / Write drew as chips above the
389
- lanes. Their bodies AND their four switches now live in Properties > Configuration >
390
- "How this fetches" (C-CFG); session B confirmed both R7 switches — Bright Data's paid
391
- rung and Write's dry run — arrived there before this was removed, because the strip was
392
- the ONLY surface either of them appeared on and deleting it first would have taken a
393
- money control and a write-vs-report control out of the product with every gate green.
394
- The `record === false` filter above survives and must: it still keeps those stages out
395
- of the LANES.
396
- */}
397
- <div className="autob-cols">
398
- {cols.map((col) => (
399
- <div className="autob-col" key={col}>
400
- {/* STACKED LANES ARE THE BRANCH PATHS (R5). Two stages at the same column
401
- are two places a record can be at the same point in the flow — the
402
- routing decides which — so they stack rather than sitting side by side,
403
- which would read as "then". */}
404
- {laneStages
405
- .filter((s) => s.col === col)
406
- .sort((a, b) => a.row - b.row)
407
- .map(lane)}
408
- </div>
409
- ))}
410
- </div>
411
- </div>
412
- );
413
- }