fsanyoto commited on
Commit
7227e08
·
verified ·
1 Parent(s): 609fb78

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

Browse files
Files changed (1) hide show
  1. web/src/alerts/AlertsPane.tsx +0 -385
web/src/alerts/AlertsPane.tsx DELETED
@@ -1,385 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // alerts/AlertsPane.tsx — WAVE 20 item 25 (C-ALERT): the inbox.
3
- //
4
- // Two lists, one panel, and the order is the point: what HAPPENED first, what is
5
- // WATCHING second. An inbox that opens on its own configuration is a settings
6
- // screen wearing a bell.
7
- //
8
- // A drawer rather than a route, for the same reason the AI note is a modal: the
9
- // nav is server-filtered and an undeclared surface is denied by design (this
10
- // shell has no client-invented pages). Alerts are not a granted module — they
11
- // are this account's own inbox over its own views.
12
- // ---------------------------------------------------------------------------
13
-
14
- import { useCallback, useEffect, useState } from "react";
15
- import {
16
- deleteAlert,
17
- fetchAlerts,
18
- fetchInbox,
19
- markRead,
20
- runAlert,
21
- } from "./alertsApi";
22
- import {
23
- applyRead,
24
- canMarkAll,
25
- inboxOrder,
26
- isAutomationOutcome,
27
- isAutomationReview,
28
- paneView,
29
- routeForTopic,
30
- stampText,
31
- } from "./alertsModel";
32
- import type { Alert, Inbox, Notification } from "./alertsModel";
33
- // WAVE 27 C5 — the ONE generated loop mark, consumed rather than redrawn (C7's rule).
34
- import { Mark } from "../shell/Brand";
35
-
36
- /** The clock face this pane uses for its one glyph — drawn, never an emoji. */
37
- function BellIcon() {
38
- return (
39
- <svg className="alerts-bell" viewBox="0 0 16 16" aria-hidden="true">
40
- <path d="M8 2.2a3.6 3.6 0 0 1 3.6 3.6v2.4l1.2 2H3.2l1.2-2V5.8A3.6 3.6 0 0 1 8 2.2Z" />
41
- <path d="M6.6 12.6a1.5 1.5 0 0 0 2.8 0" />
42
- </svg>
43
- );
44
- }
45
-
46
- export default function AlertsPane({
47
- onClose,
48
- onOpenView,
49
- onOpenAutomation,
50
- onInbox,
51
- seed,
52
- onToast,
53
- }: {
54
- onClose: () => void;
55
- /** Navigate to the alert's view. The FRAME owns routing; this pane owns the row. */
56
- onOpenView: (topic: string, viewId: string) => void;
57
- /**
58
- * WAVE 23 (C6, wiring W23-W5) — the same division for a REVIEW notification: the frame routes
59
- * to `#/automation` and asks the surface to select this automation.
60
- *
61
- * ⛔ REQUIRED, NOT OPTIONAL, and that is the wave-20 lesson written into a type. An optional
62
- * callback the frame forgot to pass degrades to "clicking a review notification does nothing",
63
- * which is indistinguishable from "the feature was never built" and goes red in no gate. A
64
- * required prop fails `tsc` the moment it is unmounted.
65
- */
66
- onOpenAutomation: (autoId: string, stageId?: string) => void;
67
- /** Hand the freshly-read inbox back so the nav badge and the pane agree. */
68
- onInbox: (inbox: Inbox) => void;
69
- onToast: (message: string) => void;
70
- /**
71
- * ⭐⭐ WAVE 31 · T23 (owner item 1) — THE FRAME'S OWN INBOX, AS THE SEED.
72
- *
73
- * ⛔ REQUIRED, NOT OPTIONAL, for the reason `onOpenAutomation` above is: an optional seed the
74
- * frame forgot to pass degrades to `EMPTY_INBOX`, which is precisely the shipped bug, and no
75
- * gate would see it. `tsc` fails the moment it is unmounted.
76
- *
77
- * The frame has ALREADY fetched this — it is what paints the rail badge the user just clicked.
78
- * Starting from it means the panel opens knowing the count, so "Mark all read" is live from
79
- * the first frame and stays live if this pane's own read fails.
80
- */
81
- seed: Inbox;
82
- }) {
83
- const [inbox, setInbox] = useState<Inbox>(seed);
84
- const [alerts, setAlerts] = useState<Alert[]>([]);
85
- const [error, setError] = useState("");
86
- const [busy, setBusy] = useState(false);
87
- /**
88
- * ⛔ THE STATE THE PANE DID NOT HAVE. Without it, "no rows yet" and "no rows, ever" are the
89
- * same value, so an in-flight read — **3,280 ms live on tenant #0** — printed a confident
90
- * "Nothing new." over an inbox nobody had looked at yet.
91
- */
92
- const [phase, setPhase] = useState<"pending" | "ready" | "error">("pending");
93
-
94
- const publish = useCallback(
95
- (next: Inbox) => {
96
- setInbox(next);
97
- onInbox(next);
98
- },
99
- [onInbox]
100
- );
101
-
102
- const load = useCallback(async () => {
103
- const [inboxRes, alertRes] = await Promise.all([fetchInbox(), fetchAlerts()]);
104
- if (inboxRes.ok) {
105
- publish(inboxRes.value);
106
- setError("");
107
- setPhase("ready");
108
- } else {
109
- // ⚠ THE SEEDED INBOX SURVIVES A FAILED READ. Blanking it here would take the count — and
110
- // with it the Mark-all control — away from a reader who can see the badge, which is the
111
- // owner's second symptom. The failure is REPORTED (the message line below) and nothing the
112
- // frame already knew is discarded.
113
- setError(inboxRes.message);
114
- setPhase("error");
115
- }
116
- if (alertRes.ok) setAlerts(alertRes.value);
117
- }, [publish]);
118
-
119
- useEffect(() => {
120
- void load();
121
- }, [load]);
122
-
123
- // ⛔ Escape closes it, like every other panel in this shell — a scrim with no
124
- // keyboard way out is a trap (the wave-18 lesson, kept).
125
- useEffect(() => {
126
- const onKey = (e: KeyboardEvent) => {
127
- if (e.key === "Escape") onClose();
128
- };
129
- window.addEventListener("keydown", onKey);
130
- return () => window.removeEventListener("keydown", onKey);
131
- }, [onClose]);
132
-
133
- const toggleRead = useCallback(
134
- (n: Notification) => {
135
- // Optimistic, with the server's own convention (`ids`, `read`) sent
136
- // explicitly — and reverted out loud if the write is refused, because a
137
- // badge that silently disagrees with the list is how a reader learns to
138
- // stop trusting it.
139
- const before = inbox;
140
- publish(applyRead(inbox, [n.id], !n.read));
141
- void markRead([n.id], !n.read).then((r) => {
142
- if (!r.ok) {
143
- publish(before);
144
- onToast(r.message);
145
- }
146
- });
147
- },
148
- [inbox, publish, onToast]
149
- );
150
-
151
- const markAll = useCallback(() => {
152
- const before = inbox;
153
- // ⭐ W31-T23 — `applyRead(…, null, true)` zeroes the count from the ITEMS, which is right when
154
- // we have the page and wrong when we do not: a failed read leaves `items` empty while the
155
- // account really does have unread notifications, and the optimistic copy would still say 0.
156
- // It does — and that is CORRECT here, because the request below clears the whole account
157
- // (`ids: null`), so 0 is what the server is about to make true. The revert on failure is what
158
- // keeps it honest.
159
- publish({ ...applyRead(inbox, null, true), unread: 0 });
160
- void markRead(null, true).then((r) => {
161
- if (!r.ok) {
162
- publish(before);
163
- onToast(r.message);
164
- }
165
- });
166
- }, [inbox, publish, onToast]);
167
-
168
- const open = useCallback(
169
- (n: Notification) => {
170
- if (!n.read) {
171
- publish(applyRead(inbox, [n.id], true));
172
- void markRead([n.id], true);
173
- }
174
- // ⛔ WAVE 23 C6 — THE KIND BRANCH COMES FIRST, AND ITS ORDER IS THE WHOLE FIX. A review
175
- // notification has no `topic` a grid could render, so the view guard below would have
176
- // caught every one of them and told the reader their table was "no longer available" —
177
- // a confidently wrong sentence about a feature that is working. The destination decides
178
- // which guard applies, so the destination is decided first.
179
- if (isAutomationReview(n)) {
180
- onOpenAutomation(n.autoId!, n.stageId);
181
- onClose();
182
- return;
183
- }
184
- // ⭐ WAVE 27 C5 — a RUN OUTCOME routes to its automation too, and it carries the id in
185
- // `alertId` rather than `autoId` (`core.alerts.notify`'s shape, not `_queue_review`'s).
186
- // Beside the review branch and after it: a review notification satisfies BOTH predicates,
187
- // and only the review one knows about the stage to scroll to.
188
- if (isAutomationOutcome(n)) {
189
- onOpenAutomation(n.alertId, undefined);
190
- onClose();
191
- return;
192
- }
193
- // A route this client cannot resolve opens NOTHING and says so — alerts
194
- // outlive the surfaces they were made from.
195
- if (!routeForTopic(n.topic)) {
196
- onToast("That alert's table is no longer available to this account.");
197
- return;
198
- }
199
- onOpenView(n.topic, n.viewId);
200
- onClose();
201
- },
202
- [inbox, publish, onOpenView, onOpenAutomation, onClose, onToast]
203
- );
204
-
205
- const rows = inboxOrder(inbox.items);
206
- // ⭐ W31-T23 — the decision lives in `alertsModel` so `verify_alerts` can RUN it (this file is
207
- // TSX and the gate's harness is node); this line is the mount.
208
- const view = paneView(phase, rows.length, seed.unread);
209
-
210
- return (
211
- <div className="shell-newdb-scrim" onClick={onClose}>
212
- <aside
213
- className="alerts-pane"
214
- role="dialog"
215
- aria-label="Alerts"
216
- onClick={(e) => e.stopPropagation()}
217
- >
218
- <header className="alerts-head">
219
- <h2>
220
- <BellIcon /> Alerts
221
- </h2>
222
- <button
223
- type="button"
224
- className="alerts-markall"
225
- // ⭐⭐ W31-T23 (R6) — THE CONTROL THAT COULD NOT BE PRESSED. `inbox.unread === 0` was
226
- // this pane's OWN state, zero until its fetch landed and zero for ever if it failed,
227
- // so the one verb that clears the badge was disabled in exactly the two situations
228
- // the owner reported. The seeded count is the account's, so the button is live from
229
- // the first frame.
230
- disabled={!canMarkAll(inbox.unread, busy)}
231
- onClick={markAll}
232
- >
233
- Mark all read
234
- </button>
235
- </header>
236
-
237
- {error ? <p className="shell-newdb-err">{error}</p> : null}
238
-
239
- <div className="alerts-scroll">
240
- {view === "pending" ? (
241
- /* R6: the mark, never the word. `verify_icons` asserts this product ships no load
242
- TEXT — and the sentence that used to occupy this space was worse than a word, it
243
- was an ANSWER ("Nothing new.") to a question nobody had asked yet. */
244
- <p className="alerts-empty" aria-busy="true">
245
- <span className="lp-spin" role="status" aria-label="Loading alerts" />
246
- </p>
247
- ) : view === "error" ? (
248
- <p className="alerts-empty">
249
- These notifications could not be loaded. The count beside the bell is still this
250
- account&rsquo;s — &ldquo;Mark all read&rdquo; above clears it.
251
- </p>
252
- ) : view === "empty" ? (
253
- <p className="alerts-empty">
254
- Nothing new. An alert watches ONE view and tells you when a record it had
255
- never matched arrives in it — make one from a view&rsquo;s ··· menu.
256
- </p>
257
- ) : (
258
- <ul className="alerts-list">
259
- {rows.map((n) => (
260
- <li key={n.id} className={"alerts-row" + (n.read ? "" : " is-unread")}>
261
- <button
262
- type="button"
263
- className="alerts-row-main"
264
- onClick={() => open(n)}
265
- // The hover names the DESTINATION, which is now two different places.
266
- // "Open the alert's view" over a review notification described a journey
267
- // the click does not take.
268
- title={
269
- isAutomationReview(n) || isAutomationOutcome(n)
270
- ? "Open the automation"
271
- : `Open ${n.alertLabel || "the alert's view"}`
272
- }
273
- >
274
- {/* ⭐ WAVE 27 C5 — an automation's row wears the LOOP MARK.
275
- ⛔ NOT A STATUS DOT, and not a second one: wave-26 R14 deleted every
276
- status dot in the automation module on the grounds that *"these
277
- automations are basically loops"*, and a run that FAILED is already said
278
- in `n.label` (the run summary) in words. A coloured dot here would
279
- reintroduce, in the inbox, the vocabulary that was deleted from the
280
- surface it points at.
281
- ⛔ The generated `Mark`, never a redrawn path: `shell/Brand.tsx`'s header
282
- records a hand-copied version silently painting LAST WAVE'S BRAND while
283
- a comment claimed parity. */}
284
- <span className="alerts-row-label">
285
- {isAutomationOutcome(n) || isAutomationReview(n) ? (
286
- // ⚠ INSIDE the label span, not beside it. `.alerts-row-main` is a flex
287
- // COLUMN, so a sibling here becomes a third ROW stacked above the text
288
- // ([[wrong-parent-not-broken-control]]); inline, it sits on the line it
289
- // annotates and rides the same ellipsis.
290
- <span className="alerts-row-mark">
291
- <Mark size={12} />
292
- </span>
293
- ) : null}
294
- {n.label}
295
- </span>
296
- <span className="alerts-row-meta">
297
- {n.alertLabel ? `${n.alertLabel} · ` : ""}
298
- {/* Readable, but never re-derived: `stampText` is string surgery
299
- over the server's own UTC-with-offset stamp (D-18). Parsing it
300
- into a browser Date is how a tenant a day ahead gets told an
301
- event happened tomorrow. */}
302
- {stampText(n.at)}
303
- </span>
304
- </button>
305
- <button
306
- type="button"
307
- className="alerts-row-toggle"
308
- aria-label={n.read ? `Mark ${n.label} unread` : `Mark ${n.label} read`}
309
- title={n.read ? "Mark unread" : "Mark read"}
310
- onClick={() => toggleRead(n)}
311
- >
312
- {/* The ACTION, not the state: "Read" beside an unread row reads as
313
- a label for the row itself. */}
314
- {n.read ? "Mark unread" : "Mark read"}
315
- </button>
316
- </li>
317
- ))}
318
- </ul>
319
- )}
320
-
321
- {alerts.length > 0 ? (
322
- <section className="alerts-watching">
323
- <h3>Watching</h3>
324
- {alerts.map((a) => (
325
- <div key={a.id} className="alerts-watch-row">
326
- <span className="alerts-watch-label">{a.label}</span>
327
- <span className="alerts-watch-meta">
328
- {/* The remembered set's SIZE, which is what "no news" means here:
329
- an alert with 40 matches and nothing new is working. */}
330
- {a.matched.toLocaleString()} matched
331
- {a.lastError ? ` · ${a.lastError}` : ""}
332
- </span>
333
- <button
334
- type="button"
335
- className="alerts-watch-run"
336
- disabled={busy}
337
- onClick={() => {
338
- setBusy(true);
339
- void runAlert(a.id).then((r) => {
340
- setBusy(false);
341
- if (!r.ok) return onToast(r.message);
342
- const v = r.value as { new?: unknown[]; skipped?: string };
343
- onToast(
344
- v?.skipped
345
- ? `Skipped: ${v.skipped}`
346
- : `${(v?.new ?? []).length} new since the last check.`
347
- );
348
- void load();
349
- });
350
- }}
351
- >
352
- Check now
353
- </button>
354
- <button
355
- type="button"
356
- className="alerts-watch-del"
357
- disabled={busy}
358
- aria-label={`Delete the alert ${a.label}`}
359
- onClick={() => {
360
- setBusy(true);
361
- void deleteAlert(a.id).then((r) => {
362
- setBusy(false);
363
- if (!r.ok) return onToast(r.message);
364
- setAlerts((cur) => cur.filter((x) => x.id !== a.id));
365
- void load();
366
- });
367
- }}
368
- >
369
- Delete
370
- </button>
371
- </div>
372
- ))}
373
- </section>
374
- ) : null}
375
- </div>
376
-
377
- <div className="shell-newdb-actions alerts-foot">
378
- <button type="button" className="login-submit" onClick={onClose}>
379
- Close
380
- </button>
381
- </div>
382
- </aside>
383
- </div>
384
- );
385
- }