TheYuchen commited on
Commit ·
dee698c
1
Parent(s): 72fe4f4
Pickers: live on-canvas badges, honest zero-states, upload retry + spinner
Browse files- BlockPicker reads real canvas kinds (store bridge): "on canvas" badges are
live, and defaults already placed are not pre-checked (no duplicate
input/output on every Add blocks round-trip)
- NodePalette zero-state accounts for the family filter and offers
"Show all families"
- CircuitPicker: file input resets after handling (same file re-uploads),
upload button shows its busy spinner, circuit picks lock while running
frontend/src/components/BlockPicker.tsx
CHANGED
|
@@ -46,21 +46,28 @@ export function BlockPicker({
|
|
| 46 |
}) {
|
| 47 |
const [open, setOpen] = useState(false);
|
| 48 |
const [search, setSearch] = useState("");
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
const rootRef = useRef<HTMLDivElement>(null);
|
| 51 |
const searchRef = useRef<HTMLInputElement>(null);
|
| 52 |
const addBlocksToCanvas = useApp((s) => s.addBlocksToCanvas);
|
| 53 |
|
| 54 |
useDismissOn(open, rootRef, useCallback(() => setOpen(false), []));
|
| 55 |
|
| 56 |
-
// Reset to defaults + focus search on open.
|
|
|
|
|
|
|
|
|
|
| 57 |
useEffect(() => {
|
| 58 |
if (open) {
|
| 59 |
-
setChecked(
|
|
|
|
|
|
|
| 60 |
setSearch("");
|
| 61 |
searchRef.current?.focus();
|
| 62 |
}
|
| 63 |
-
}, [open]);
|
| 64 |
|
| 65 |
// Merge built-in catalog with the user's plugin manifests so the
|
| 66 |
// picker shows everything in one list, grouped by family.
|
|
|
|
| 46 |
}) {
|
| 47 |
const [open, setOpen] = useState(false);
|
| 48 |
const [search, setSearch] = useState("");
|
| 49 |
+
// Starts empty; the on-open effect below seeds the default checks
|
| 50 |
+
// (minus kinds already on the canvas).
|
| 51 |
+
const [checked, setChecked] = useState<Set<NodeKind>>(new Set());
|
| 52 |
const rootRef = useRef<HTMLDivElement>(null);
|
| 53 |
const searchRef = useRef<HTMLInputElement>(null);
|
| 54 |
const addBlocksToCanvas = useApp((s) => s.addBlocksToCanvas);
|
| 55 |
|
| 56 |
useDismissOn(open, rootRef, useCallback(() => setOpen(false), []));
|
| 57 |
|
| 58 |
+
// Reset to defaults + focus search on open. Defaults that are
|
| 59 |
+
// already on the canvas are NOT re-checked — pre-checking them
|
| 60 |
+
// produced duplicate input/output blocks on every "Add blocks"
|
| 61 |
+
// round-trip (audit S2); the "on canvas" badge marks them instead.
|
| 62 |
useEffect(() => {
|
| 63 |
if (open) {
|
| 64 |
+
setChecked(
|
| 65 |
+
new Set(DEFAULT_CHECKED.filter((k) => !canvasKinds.has(k))),
|
| 66 |
+
);
|
| 67 |
setSearch("");
|
| 68 |
searchRef.current?.focus();
|
| 69 |
}
|
| 70 |
+
}, [open, canvasKinds]);
|
| 71 |
|
| 72 |
// Merge built-in catalog with the user's plugin manifests so the
|
| 73 |
// picker shows everything in one list, grouped by family.
|
frontend/src/components/CircuitPicker.tsx
CHANGED
|
@@ -9,6 +9,9 @@ export function CircuitPicker({ onCollapse }: { onCollapse?: () => void } = {})
|
|
| 9 |
const [err, setErr] = useState<string | null>(null);
|
| 10 |
const [openPreview, setOpenPreview] = useState<string | null>(null);
|
| 11 |
const circuit = useApp((s) => s.circuit);
|
|
|
|
|
|
|
|
|
|
| 12 |
const setCircuit = useApp((s) => s.setCircuit);
|
| 13 |
const setSampleKey = useApp((s) => s.setSampleKey);
|
| 14 |
const fileRef = useRef<HTMLInputElement>(null);
|
|
@@ -73,18 +76,34 @@ export function CircuitPicker({ onCollapse }: { onCollapse?: () => void } = {})
|
|
| 73 |
</h3>
|
| 74 |
</div>
|
| 75 |
<button
|
| 76 |
-
className="btn-ghost shrink-0"
|
| 77 |
onClick={() => fileRef.current?.click()}
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
>
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
</button>
|
| 82 |
<input
|
| 83 |
ref={fileRef}
|
| 84 |
type="file"
|
| 85 |
accept=".qpy,.qasm,.qasm2,.qasm3"
|
| 86 |
hidden
|
| 87 |
-
onChange={(e) =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
/>
|
| 89 |
</div>
|
| 90 |
|
|
@@ -96,8 +115,10 @@ export function CircuitPicker({ onCollapse }: { onCollapse?: () => void } = {})
|
|
| 96 |
<span className="text-ink">Input circuit</span> block in your pipeline.
|
| 97 |
Or <button
|
| 98 |
type="button"
|
| 99 |
-
className="underline decoration-dotted hover:text-ink"
|
| 100 |
onClick={() => fileRef.current?.click()}
|
|
|
|
|
|
|
| 101 |
>
|
| 102 |
upload your own
|
| 103 |
</button>{" "}
|
|
@@ -132,8 +153,9 @@ export function CircuitPicker({ onCollapse }: { onCollapse?: () => void } = {})
|
|
| 132 |
<div className="flex items-stretch">
|
| 133 |
<button
|
| 134 |
onClick={() => pick(s.key)}
|
| 135 |
-
className="flex-1 text-left px-2 py-1.5 min-w-0"
|
| 136 |
-
disabled={busy === s.key}
|
|
|
|
| 137 |
>
|
| 138 |
<div className="flex items-center justify-between gap-2">
|
| 139 |
<span
|
|
|
|
| 9 |
const [err, setErr] = useState<string | null>(null);
|
| 10 |
const [openPreview, setOpenPreview] = useState<string | null>(null);
|
| 11 |
const circuit = useApp((s) => s.circuit);
|
| 12 |
+
// Authoring lock (audit S2): swapping the input circuit mid-run
|
| 13 |
+
// would desync the canvas from the run in flight.
|
| 14 |
+
const running = useApp((s) => s.running);
|
| 15 |
const setCircuit = useApp((s) => s.setCircuit);
|
| 16 |
const setSampleKey = useApp((s) => s.setSampleKey);
|
| 17 |
const fileRef = useRef<HTMLInputElement>(null);
|
|
|
|
| 76 |
</h3>
|
| 77 |
</div>
|
| 78 |
<button
|
| 79 |
+
className="btn-ghost shrink-0 disabled:opacity-40 disabled:cursor-not-allowed"
|
| 80 |
onClick={() => fileRef.current?.click()}
|
| 81 |
+
disabled={running || busy === "__upload__"}
|
| 82 |
+
title={
|
| 83 |
+
running
|
| 84 |
+
? "Locked while a run is in progress"
|
| 85 |
+
: "Upload your own .qpy (Qiskit) or .qasm (OpenQASM 2/3) file"
|
| 86 |
+
}
|
| 87 |
>
|
| 88 |
+
{busy === "__upload__" ? (
|
| 89 |
+
<Loader2 className="w-3 h-3 animate-spin" />
|
| 90 |
+
) : (
|
| 91 |
+
<FileUp className="w-3 h-3" />
|
| 92 |
+
)}{" "}
|
| 93 |
+
{busy === "__upload__" ? "uploading…" : "upload .qpy / .qasm"}
|
| 94 |
</button>
|
| 95 |
<input
|
| 96 |
ref={fileRef}
|
| 97 |
type="file"
|
| 98 |
accept=".qpy,.qasm,.qasm2,.qasm3"
|
| 99 |
hidden
|
| 100 |
+
onChange={(e) => {
|
| 101 |
+
const f = e.target.files?.[0];
|
| 102 |
+
if (f) void onUpload(f);
|
| 103 |
+
// Reset so picking the SAME file again re-fires change —
|
| 104 |
+
// without this a failed upload can't be retried (audit S2).
|
| 105 |
+
e.target.value = "";
|
| 106 |
+
}}
|
| 107 |
/>
|
| 108 |
</div>
|
| 109 |
|
|
|
|
| 115 |
<span className="text-ink">Input circuit</span> block in your pipeline.
|
| 116 |
Or <button
|
| 117 |
type="button"
|
| 118 |
+
className="underline decoration-dotted hover:text-ink disabled:opacity-40 disabled:cursor-not-allowed disabled:no-underline"
|
| 119 |
onClick={() => fileRef.current?.click()}
|
| 120 |
+
disabled={running || busy === "__upload__"}
|
| 121 |
+
title={running ? "Locked while a run is in progress" : undefined}
|
| 122 |
>
|
| 123 |
upload your own
|
| 124 |
</button>{" "}
|
|
|
|
| 153 |
<div className="flex items-stretch">
|
| 154 |
<button
|
| 155 |
onClick={() => pick(s.key)}
|
| 156 |
+
className="flex-1 text-left px-2 py-1.5 min-w-0 disabled:cursor-not-allowed"
|
| 157 |
+
disabled={busy === s.key || running}
|
| 158 |
+
title={running ? "Locked while a run is in progress" : undefined}
|
| 159 |
>
|
| 160 |
<div className="flex items-center justify-between gap-2">
|
| 161 |
<span
|
frontend/src/components/NodePalette.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import {
|
| 2 |
import { ChevronDown, FileText, Search, X } from "lucide-react";
|
| 3 |
import { api } from "../lib/api";
|
| 4 |
import {
|
|
@@ -44,14 +44,17 @@ const FAMILY_META: {
|
|
| 44 |
{ key: "sink", label: "Sink", description: "Aggregates final output" },
|
| 45 |
];
|
| 46 |
|
| 47 |
-
export function NodePalette({
|
| 48 |
-
canvasKinds = new Set(),
|
| 49 |
-
}: {
|
| 50 |
-
/** Kinds currently on the canvas — passed through to BlockPicker for
|
| 51 |
-
* "on canvas" badges. */
|
| 52 |
-
canvasKinds?: Set<NodeKind>;
|
| 53 |
-
} = {}) {
|
| 54 |
const [search, setSearch] = useState("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
const [expanded, setExpanded] = useState(true);
|
| 56 |
// null = show all families; a family key = show only that family.
|
| 57 |
const [activeFamily, setActiveFamily] = useState<NodeSpec["family"] | null>(null);
|
|
@@ -230,9 +233,27 @@ export function NodePalette({
|
|
| 230 |
</div>
|
| 231 |
);
|
| 232 |
})}
|
| 233 |
-
{filtered.
|
|
|
|
|
|
|
| 234 |
<div className="py-4 w-full text-center text-[11px] text-mute">
|
| 235 |
-
No blocks match "{search}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
</div>
|
| 237 |
)}
|
| 238 |
</div>
|
|
|
|
| 1 |
+
import { useMemo, useState } from "react";
|
| 2 |
import { ChevronDown, FileText, Search, X } from "lucide-react";
|
| 3 |
import { api } from "../lib/api";
|
| 4 |
import {
|
|
|
|
| 44 |
{ key: "sink", label: "Sink", description: "Aggregates final output" },
|
| 45 |
];
|
| 46 |
|
| 47 |
+
export function NodePalette() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
const [search, setSearch] = useState("");
|
| 49 |
+
// Kinds currently on the canvas — published by FlowCanvas (store
|
| 50 |
+
// bridge, audit S2) and passed to BlockPicker for live "on canvas"
|
| 51 |
+
// badges. The old prop defaulted to an empty set and no caller ever
|
| 52 |
+
// threaded the real kinds, so the badges were dead code.
|
| 53 |
+
const canvasKindsArr = useApp((s) => s.canvasKinds);
|
| 54 |
+
const canvasKinds = useMemo(
|
| 55 |
+
() => new Set<NodeKind>(canvasKindsArr),
|
| 56 |
+
[canvasKindsArr],
|
| 57 |
+
);
|
| 58 |
const [expanded, setExpanded] = useState(true);
|
| 59 |
// null = show all families; a family key = show only that family.
|
| 60 |
const [activeFamily, setActiveFamily] = useState<NodeSpec["family"] | null>(null);
|
|
|
|
| 233 |
</div>
|
| 234 |
);
|
| 235 |
})}
|
| 236 |
+
{filtered.filter(
|
| 237 |
+
(n) => activeFamily === null || n.family === activeFamily,
|
| 238 |
+
).length === 0 && (
|
| 239 |
<div className="py-4 w-full text-center text-[11px] text-mute">
|
| 240 |
+
No blocks match{search.trim() ? ` "${search}"` : ""}
|
| 241 |
+
{activeFamily !== null
|
| 242 |
+
? ` in the ${
|
| 243 |
+
FAMILY_META.find((f) => f.key === activeFamily)?.label ??
|
| 244 |
+
activeFamily
|
| 245 |
+
} family`
|
| 246 |
+
: ""}
|
| 247 |
+
.
|
| 248 |
+
{activeFamily !== null && (
|
| 249 |
+
<button
|
| 250 |
+
type="button"
|
| 251 |
+
className="ml-1.5 underline decoration-dotted hover:text-ink"
|
| 252 |
+
onClick={() => setActiveFamily(null)}
|
| 253 |
+
>
|
| 254 |
+
Show all families
|
| 255 |
+
</button>
|
| 256 |
+
)}
|
| 257 |
</div>
|
| 258 |
)}
|
| 259 |
</div>
|