Move toolbar notice into a canvas-bottom toast
Browse filesThe single-line truncated notice in the toolbar was always going to
lose to any non-trivial amount of text on narrow screens. Even after
the fit-the-toolbar rewrite, users were still seeing "(hover for 3
not..." cut off at the right edge.
Surface feedback as a toast pinned to the bottom-center of the canvas
instead. The toast:
* Shows the summary line at top and renders each Auto-connect
warning as its own bullet below (via `notice.detail`), so
multi-warning results become readable without hover.
* Caps at 36rem wide, centred over the canvas, so it never fights
the toolbar or the side panels for space.
* Tone-coded icons (Check / AlertTriangle / AlertCircle) with
matching border + tinted background.
* Explicit × dismiss button plus auto-fade (ok: 4s, warn: 8s).
* Runner errors (danger tone) stay sticky — a 6-second auto-fade
on a stack trace the user didn't finish reading is worse than
a small × button.
* role="status" / role="alert" + aria-live so screen readers
announce it appropriately.
Toolbar goes back to just the block/link counter on the left, giving
the button cluster the full remaining row for breathing room.
|
@@ -15,7 +15,16 @@ import {
|
|
| 15 |
type NodeTypes,
|
| 16 |
type OnConnect,
|
| 17 |
} from "@xyflow/react";
|
| 18 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
import { NODE_BY_KIND, type NodeKind } from "../lib/nodeCatalog";
|
| 20 |
import {
|
| 21 |
DEFAULT_PRESET_KEY,
|
|
@@ -31,11 +40,15 @@ import { PresetPicker } from "./PresetPicker";
|
|
| 31 |
import { ShareButton } from "./ShareButton";
|
| 32 |
import { EmptyCanvas } from "./EmptyCanvas";
|
| 33 |
|
| 34 |
-
/**
|
| 35 |
-
*
|
| 36 |
-
* `
|
| 37 |
-
*
|
| 38 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
type Notice = {
|
| 40 |
text: string;
|
| 41 |
tone: "danger" | "warn" | "ok";
|
|
@@ -109,11 +122,15 @@ export function FlowCanvas() {
|
|
| 109 |
const setRunning = useApp((s) => s.setRunning);
|
| 110 |
const useLiveIbm = useApp((s) => s.useLiveIbm);
|
| 111 |
const [notice, setNotice] = useState<Notice>(null);
|
| 112 |
-
// Non-danger
|
| 113 |
-
//
|
|
|
|
|
|
|
|
|
|
| 114 |
useEffect(() => {
|
| 115 |
if (!notice || notice.tone === "danger") return;
|
| 116 |
-
const
|
|
|
|
| 117 |
return () => window.clearTimeout(t);
|
| 118 |
}, [notice]);
|
| 119 |
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
@@ -201,15 +218,12 @@ export function FlowCanvas() {
|
|
| 201 |
setNotice({ text: base, tone: "ok" });
|
| 202 |
return;
|
| 203 |
}
|
| 204 |
-
//
|
| 205 |
-
//
|
| 206 |
-
// can hover to read every warning.
|
| 207 |
-
const n = result.warnings.length;
|
| 208 |
-
const hint = n === 1 ? "hover for 1 note" : `hover for ${n} notes`;
|
| 209 |
setNotice({
|
| 210 |
-
text:
|
| 211 |
tone: "warn",
|
| 212 |
-
detail:
|
| 213 |
});
|
| 214 |
};
|
| 215 |
|
|
@@ -247,29 +261,10 @@ export function FlowCanvas() {
|
|
| 247 |
return (
|
| 248 |
<div className="flex-1 flex flex-col min-h-0">
|
| 249 |
<div className="h-12 shrink-0 border-b border-edge px-4 flex items-center justify-between gap-4">
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
which only engages when the element has a definite max width. */}
|
| 255 |
-
<div className="flex items-center gap-2 text-xs text-mute flex-1 min-w-0">
|
| 256 |
-
<span className="shrink-0">{nodes.length} blocks</span>
|
| 257 |
-
<span className="text-edge shrink-0">·</span>
|
| 258 |
-
<span className="shrink-0">{edges.length} links</span>
|
| 259 |
-
{notice && (
|
| 260 |
-
<span
|
| 261 |
-
className={`ml-3 truncate min-w-0 ${
|
| 262 |
-
notice.tone === "danger"
|
| 263 |
-
? "text-danger"
|
| 264 |
-
: notice.tone === "warn"
|
| 265 |
-
? "text-warn"
|
| 266 |
-
: "text-ok"
|
| 267 |
-
}`}
|
| 268 |
-
title={notice.detail ?? notice.text}
|
| 269 |
-
>
|
| 270 |
-
{notice.text}
|
| 271 |
-
</span>
|
| 272 |
-
)}
|
| 273 |
</div>
|
| 274 |
<div className="flex items-center gap-2 shrink-0">
|
| 275 |
<PresetPicker onPick={loadPreset} />
|
|
@@ -340,7 +335,71 @@ export function FlowCanvas() {
|
|
| 340 |
/>
|
| 341 |
</ReactFlow>
|
| 342 |
{nodes.length === 0 && <EmptyCanvas />}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
</div>
|
| 345 |
);
|
| 346 |
}
|
|
|
|
| 15 |
type NodeTypes,
|
| 16 |
type OnConnect,
|
| 17 |
} from "@xyflow/react";
|
| 18 |
+
import {
|
| 19 |
+
AlertCircle,
|
| 20 |
+
AlertTriangle,
|
| 21 |
+
Check,
|
| 22 |
+
Loader2,
|
| 23 |
+
Play,
|
| 24 |
+
Trash2,
|
| 25 |
+
Wand2,
|
| 26 |
+
X,
|
| 27 |
+
} from "lucide-react";
|
| 28 |
import { NODE_BY_KIND, type NodeKind } from "../lib/nodeCatalog";
|
| 29 |
import {
|
| 30 |
DEFAULT_PRESET_KEY,
|
|
|
|
| 40 |
import { ShareButton } from "./ShareButton";
|
| 41 |
import { EmptyCanvas } from "./EmptyCanvas";
|
| 42 |
|
| 43 |
+
/** One-shot feedback surfaced as a toast at the bottom of the canvas.
|
| 44 |
+
*
|
| 45 |
+
* - `tone: "danger"` is runner errors; stays until explicitly dismissed.
|
| 46 |
+
* - `tone: "warn"` / `"ok"` come from Auto-connect; auto-dismiss after a
|
| 47 |
+
* few seconds.
|
| 48 |
+
* - `detail`, when present, is rendered underneath `text` in the toast
|
| 49 |
+
* body (one warning per line), so long advisories no longer have to
|
| 50 |
+
* fit on a single truncated header line.
|
| 51 |
+
*/
|
| 52 |
type Notice = {
|
| 53 |
text: string;
|
| 54 |
tone: "danger" | "warn" | "ok";
|
|
|
|
| 122 |
const setRunning = useApp((s) => s.setRunning);
|
| 123 |
const useLiveIbm = useApp((s) => s.useLiveIbm);
|
| 124 |
const [notice, setNotice] = useState<Notice>(null);
|
| 125 |
+
// Non-danger toasts auto-fade; success is quick, warnings linger a bit
|
| 126 |
+
// longer so the user has time to read every bullet. Runner errors stay
|
| 127 |
+
// put until the next action (Run, Clear, preset change) clears them —
|
| 128 |
+
// losing a stack trace to a 6-second fade is a much worse UX than a
|
| 129 |
+
// sticky notice you can dismiss with ×.
|
| 130 |
useEffect(() => {
|
| 131 |
if (!notice || notice.tone === "danger") return;
|
| 132 |
+
const ms = notice.tone === "ok" ? 4000 : 8000;
|
| 133 |
+
const t = window.setTimeout(() => setNotice(null), ms);
|
| 134 |
return () => window.clearTimeout(t);
|
| 135 |
}, [notice]);
|
| 136 |
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
|
|
| 218 |
setNotice({ text: base, tone: "ok" });
|
| 219 |
return;
|
| 220 |
}
|
| 221 |
+
// Toast renders `detail` as a bulleted list under `text`, so we can
|
| 222 |
+
// just hand the raw warnings through — no truncation, no hover hint.
|
|
|
|
|
|
|
|
|
|
| 223 |
setNotice({
|
| 224 |
+
text: base,
|
| 225 |
tone: "warn",
|
| 226 |
+
detail: result.warnings.join("\n"),
|
| 227 |
});
|
| 228 |
};
|
| 229 |
|
|
|
|
| 261 |
return (
|
| 262 |
<div className="flex-1 flex flex-col min-h-0">
|
| 263 |
<div className="h-12 shrink-0 border-b border-edge px-4 flex items-center justify-between gap-4">
|
| 264 |
+
<div className="flex items-center gap-2 text-xs text-mute shrink-0">
|
| 265 |
+
<span>{nodes.length} blocks</span>
|
| 266 |
+
<span className="text-edge">·</span>
|
| 267 |
+
<span>{edges.length} links</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
</div>
|
| 269 |
<div className="flex items-center gap-2 shrink-0">
|
| 270 |
<PresetPicker onPick={loadPreset} />
|
|
|
|
| 335 |
/>
|
| 336 |
</ReactFlow>
|
| 337 |
{nodes.length === 0 && <EmptyCanvas />}
|
| 338 |
+
{notice && (
|
| 339 |
+
<CanvasToast notice={notice} onDismiss={() => setNotice(null)} />
|
| 340 |
+
)}
|
| 341 |
+
</div>
|
| 342 |
+
</div>
|
| 343 |
+
);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
/**
|
| 347 |
+
* Absolute-positioned toast pinned to the bottom-center of the canvas.
|
| 348 |
+
* Handles Auto-connect summaries, Auto-connect warnings (multi-line via
|
| 349 |
+
* `notice.detail`), and runner errors. Sits above React Flow's controls
|
| 350 |
+
* (z-30) and caps at a readable width regardless of canvas size.
|
| 351 |
+
*/
|
| 352 |
+
function CanvasToast({
|
| 353 |
+
notice,
|
| 354 |
+
onDismiss,
|
| 355 |
+
}: {
|
| 356 |
+
notice: NonNullable<Notice>;
|
| 357 |
+
onDismiss: () => void;
|
| 358 |
+
}) {
|
| 359 |
+
const palette = {
|
| 360 |
+
ok: {
|
| 361 |
+
border: "border-ok/40",
|
| 362 |
+
bg: "bg-ok/10",
|
| 363 |
+
icon: <Check className="w-4 h-4 text-ok" />,
|
| 364 |
+
},
|
| 365 |
+
warn: {
|
| 366 |
+
border: "border-warn/40",
|
| 367 |
+
bg: "bg-warn/10",
|
| 368 |
+
icon: <AlertTriangle className="w-4 h-4 text-warn" />,
|
| 369 |
+
},
|
| 370 |
+
danger: {
|
| 371 |
+
border: "border-danger/40",
|
| 372 |
+
bg: "bg-danger/10",
|
| 373 |
+
icon: <AlertCircle className="w-4 h-4 text-danger" />,
|
| 374 |
+
},
|
| 375 |
+
}[notice.tone];
|
| 376 |
+
const warnings = notice.detail ? notice.detail.split("\n") : [];
|
| 377 |
+
|
| 378 |
+
return (
|
| 379 |
+
<div
|
| 380 |
+
role={notice.tone === "danger" ? "alert" : "status"}
|
| 381 |
+
aria-live={notice.tone === "danger" ? "assertive" : "polite"}
|
| 382 |
+
className={`absolute left-1/2 -translate-x-1/2 bottom-4 z-30 w-[min(36rem,calc(100%-2rem))] rounded-lg border ${palette.border} ${palette.bg} bg-surface/95 backdrop-blur-sm shadow-xl px-4 py-3 flex items-start gap-3`}
|
| 383 |
+
>
|
| 384 |
+
<div className="shrink-0 mt-0.5">{palette.icon}</div>
|
| 385 |
+
<div className="flex-1 min-w-0 text-sm text-ink">
|
| 386 |
+
<div className="leading-snug">{notice.text}</div>
|
| 387 |
+
{warnings.length > 0 && (
|
| 388 |
+
<ul className="mt-1.5 space-y-0.5 text-xs text-mute list-disc pl-4 leading-relaxed">
|
| 389 |
+
{warnings.map((w, i) => (
|
| 390 |
+
<li key={i}>{w}</li>
|
| 391 |
+
))}
|
| 392 |
+
</ul>
|
| 393 |
+
)}
|
| 394 |
</div>
|
| 395 |
+
<button
|
| 396 |
+
type="button"
|
| 397 |
+
onClick={onDismiss}
|
| 398 |
+
aria-label="Dismiss"
|
| 399 |
+
className="shrink-0 text-mute hover:text-ink transition-colors"
|
| 400 |
+
>
|
| 401 |
+
<X className="w-4 h-4" />
|
| 402 |
+
</button>
|
| 403 |
</div>
|
| 404 |
);
|
| 405 |
}
|