Yuchen Yuan commited on
Commit
fdae5ba
·
1 Parent(s): 4637580

Make both side panels collapsible with rotated-label expand strip

Browse files

- Left / right aside can collapse to a 32 px strip with vertical label
and chevron; click the strip to re-expand.
- Collapse buttons in each pane header (Pipeline input, Results).
- Drag handles auto-hide when the adjacent pane is collapsed.
- Collapsed state persists to localStorage alongside the widths.
- When a pipeline run kicks off, auto-expand the right pane so the
"executing..." indicator is visible and the demo doesn't look frozen.

frontend/src/App.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import { useCallback, useEffect, useRef, useState } from "react";
2
  import { ReactFlowProvider } from "@xyflow/react";
3
  import "@xyflow/react/dist/style.css";
 
4
  import { api } from "./lib/api";
5
  import { useApp } from "./lib/store";
6
  import { TopBar } from "./components/TopBar";
@@ -17,8 +18,12 @@ const LEFT_MAX = 560;
17
  const RIGHT_DEFAULT = 400;
18
  const RIGHT_MIN = 300;
19
  const RIGHT_MAX = 720;
 
 
20
  const LS_LEFT = "jqub.leftPaneWidth";
21
  const LS_RIGHT = "jqub.rightPaneWidth";
 
 
22
 
23
  function loadWidth(key: string, def: number, min: number, max: number): number {
24
  if (typeof window === "undefined") return def;
@@ -33,8 +38,20 @@ function loadWidth(key: string, def: number, min: number, max: number): number {
33
  }
34
  }
35
 
 
 
 
 
 
 
 
 
 
 
 
36
  export default function App() {
37
  const setHealth = useApp((s) => s.setHealth);
 
38
  const [ready, setReady] = useState(false);
39
  const [tourOpen, setTourOpen] = useFirstVisitTour();
40
 
@@ -44,6 +61,12 @@ export default function App() {
44
  const [rightW, setRightW] = useState<number>(() =>
45
  loadWidth(LS_RIGHT, RIGHT_DEFAULT, RIGHT_MIN, RIGHT_MAX),
46
  );
 
 
 
 
 
 
47
 
48
  // Persist user's preferred widths.
49
  useEffect(() => {
@@ -60,6 +83,35 @@ export default function App() {
60
  /* ignore quota errors */
61
  }
62
  }, [rightW]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  useEffect(() => {
65
  api
@@ -71,41 +123,68 @@ export default function App() {
71
  .catch(() => setReady(true));
72
  }, [setHealth]);
73
 
 
 
 
74
  return (
75
  <div className="h-screen w-screen flex flex-col overflow-hidden">
76
  <TopBar onOpenTour={() => setTourOpen(true)} />
77
  <div className="flex-1 flex min-h-0">
78
  <aside
79
- style={{ width: leftW }}
80
- className="shrink-0 border-r border-edge flex flex-col min-h-0 overflow-y-auto"
 
 
81
  >
82
- <CircuitPicker />
 
 
 
 
 
 
 
 
83
  </aside>
84
- <PaneResizer
85
- onResize={(dx) =>
86
- setLeftW((w) => Math.min(LEFT_MAX, Math.max(LEFT_MIN, w + dx)))
87
- }
88
- onDoubleClick={() => setLeftW(LEFT_DEFAULT)}
89
- ariaLabel="Resize pipeline input pane"
90
- />
 
 
91
  <main className="flex-1 min-w-0 flex flex-col min-h-0">
92
  <NodePalette />
93
  <ReactFlowProvider>
94
  <FlowCanvas />
95
  </ReactFlowProvider>
96
  </main>
97
- <PaneResizer
98
- onResize={(dx) =>
99
- setRightW((w) => Math.min(RIGHT_MAX, Math.max(RIGHT_MIN, w - dx)))
100
- }
101
- onDoubleClick={() => setRightW(RIGHT_DEFAULT)}
102
- ariaLabel="Resize results pane"
103
- />
 
 
104
  <aside
105
- style={{ width: rightW }}
106
- className="shrink-0 border-l border-edge flex flex-col min-h-0"
 
 
107
  >
108
- <ResultsPane />
 
 
 
 
 
 
 
 
109
  </aside>
110
  </div>
111
  {!ready && (
@@ -118,6 +197,43 @@ export default function App() {
118
  );
119
  }
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  /**
122
  * 4-px wide vertical drag handle between two panes.
123
  *
 
1
  import { useCallback, useEffect, useRef, useState } from "react";
2
  import { ReactFlowProvider } from "@xyflow/react";
3
  import "@xyflow/react/dist/style.css";
4
+ import { ChevronLeft, ChevronRight } from "lucide-react";
5
  import { api } from "./lib/api";
6
  import { useApp } from "./lib/store";
7
  import { TopBar } from "./components/TopBar";
 
18
  const RIGHT_DEFAULT = 400;
19
  const RIGHT_MIN = 300;
20
  const RIGHT_MAX = 720;
21
+ const COLLAPSED_W = 32;
22
+
23
  const LS_LEFT = "jqub.leftPaneWidth";
24
  const LS_RIGHT = "jqub.rightPaneWidth";
25
+ const LS_LEFT_COLLAPSED = "jqub.leftPaneCollapsed";
26
+ const LS_RIGHT_COLLAPSED = "jqub.rightPaneCollapsed";
27
 
28
  function loadWidth(key: string, def: number, min: number, max: number): number {
29
  if (typeof window === "undefined") return def;
 
38
  }
39
  }
40
 
41
+ function loadBool(key: string, def: boolean): boolean {
42
+ if (typeof window === "undefined") return def;
43
+ try {
44
+ const raw = window.localStorage.getItem(key);
45
+ if (raw == null) return def;
46
+ return raw === "1";
47
+ } catch {
48
+ return def;
49
+ }
50
+ }
51
+
52
  export default function App() {
53
  const setHealth = useApp((s) => s.setHealth);
54
+ const running = useApp((s) => s.running);
55
  const [ready, setReady] = useState(false);
56
  const [tourOpen, setTourOpen] = useFirstVisitTour();
57
 
 
61
  const [rightW, setRightW] = useState<number>(() =>
62
  loadWidth(LS_RIGHT, RIGHT_DEFAULT, RIGHT_MIN, RIGHT_MAX),
63
  );
64
+ const [leftCollapsed, setLeftCollapsed] = useState<boolean>(() =>
65
+ loadBool(LS_LEFT_COLLAPSED, false),
66
+ );
67
+ const [rightCollapsed, setRightCollapsed] = useState<boolean>(() =>
68
+ loadBool(LS_RIGHT_COLLAPSED, false),
69
+ );
70
 
71
  // Persist user's preferred widths.
72
  useEffect(() => {
 
83
  /* ignore quota errors */
84
  }
85
  }, [rightW]);
86
+ useEffect(() => {
87
+ try {
88
+ window.localStorage.setItem(LS_LEFT_COLLAPSED, leftCollapsed ? "1" : "0");
89
+ } catch {
90
+ /* ignore */
91
+ }
92
+ }, [leftCollapsed]);
93
+ useEffect(() => {
94
+ try {
95
+ window.localStorage.setItem(
96
+ LS_RIGHT_COLLAPSED,
97
+ rightCollapsed ? "1" : "0",
98
+ );
99
+ } catch {
100
+ /* ignore */
101
+ }
102
+ }, [rightCollapsed]);
103
+
104
+ // Auto-expand the right pane when a pipeline run kicks off, so the user
105
+ // sees the "executing…" indicator and doesn't think the app is frozen.
106
+ // We only expand (never auto-collapse) and only on the false->true edge,
107
+ // so repeat runs while already expanded are a no-op.
108
+ const prevRunningRef = useRef(running);
109
+ useEffect(() => {
110
+ if (running && !prevRunningRef.current && rightCollapsed) {
111
+ setRightCollapsed(false);
112
+ }
113
+ prevRunningRef.current = running;
114
+ }, [running, rightCollapsed]);
115
 
116
  useEffect(() => {
117
  api
 
123
  .catch(() => setReady(true));
124
  }, [setHealth]);
125
 
126
+ const leftWidth = leftCollapsed ? COLLAPSED_W : leftW;
127
+ const rightWidth = rightCollapsed ? COLLAPSED_W : rightW;
128
+
129
  return (
130
  <div className="h-screen w-screen flex flex-col overflow-hidden">
131
  <TopBar onOpenTour={() => setTourOpen(true)} />
132
  <div className="flex-1 flex min-h-0">
133
  <aside
134
+ style={{ width: leftWidth }}
135
+ className={`shrink-0 border-r border-edge flex flex-col min-h-0 transition-[width] duration-150 ${
136
+ leftCollapsed ? "overflow-hidden" : "overflow-y-auto"
137
+ }`}
138
  >
139
+ {leftCollapsed ? (
140
+ <CollapsedStrip
141
+ label="Pipeline input"
142
+ side="left"
143
+ onExpand={() => setLeftCollapsed(false)}
144
+ />
145
+ ) : (
146
+ <CircuitPicker onCollapse={() => setLeftCollapsed(true)} />
147
+ )}
148
  </aside>
149
+ {!leftCollapsed && (
150
+ <PaneResizer
151
+ onResize={(dx) =>
152
+ setLeftW((w) => Math.min(LEFT_MAX, Math.max(LEFT_MIN, w + dx)))
153
+ }
154
+ onDoubleClick={() => setLeftW(LEFT_DEFAULT)}
155
+ ariaLabel="Resize pipeline input pane"
156
+ />
157
+ )}
158
  <main className="flex-1 min-w-0 flex flex-col min-h-0">
159
  <NodePalette />
160
  <ReactFlowProvider>
161
  <FlowCanvas />
162
  </ReactFlowProvider>
163
  </main>
164
+ {!rightCollapsed && (
165
+ <PaneResizer
166
+ onResize={(dx) =>
167
+ setRightW((w) => Math.min(RIGHT_MAX, Math.max(RIGHT_MIN, w - dx)))
168
+ }
169
+ onDoubleClick={() => setRightW(RIGHT_DEFAULT)}
170
+ ariaLabel="Resize results pane"
171
+ />
172
+ )}
173
  <aside
174
+ style={{ width: rightWidth }}
175
+ className={`shrink-0 border-l border-edge flex flex-col min-h-0 transition-[width] duration-150 ${
176
+ rightCollapsed ? "overflow-hidden" : ""
177
+ }`}
178
  >
179
+ {rightCollapsed ? (
180
+ <CollapsedStrip
181
+ label="Results"
182
+ side="right"
183
+ onExpand={() => setRightCollapsed(false)}
184
+ />
185
+ ) : (
186
+ <ResultsPane onCollapse={() => setRightCollapsed(true)} />
187
+ )}
188
  </aside>
189
  </div>
190
  {!ready && (
 
197
  );
198
  }
199
 
200
+ /**
201
+ * Narrow vertical strip shown when an aside pane is collapsed.
202
+ *
203
+ * Clicking anywhere on it expands the pane. The chevron sits near the top
204
+ * and the label is rotated 90° to fill the strip. `side` controls which
205
+ * edge the chevron points towards — a left-side strip points right (come
206
+ * back out to the right) and a right-side strip points left.
207
+ */
208
+ function CollapsedStrip({
209
+ label,
210
+ side,
211
+ onExpand,
212
+ }: {
213
+ label: string;
214
+ side: "left" | "right";
215
+ onExpand: () => void;
216
+ }) {
217
+ const Chevron = side === "left" ? ChevronRight : ChevronLeft;
218
+ return (
219
+ <button
220
+ type="button"
221
+ onClick={onExpand}
222
+ title={`Expand ${label}`}
223
+ aria-label={`Expand ${label}`}
224
+ className="flex flex-col items-center gap-2 py-2 px-0 w-full h-full text-mute hover:text-ink hover:bg-surfaceAlt transition-colors"
225
+ >
226
+ <Chevron className="w-4 h-4 shrink-0" />
227
+ <span
228
+ className="text-[11px] uppercase tracking-wider whitespace-nowrap select-none"
229
+ style={{ writingMode: "vertical-rl" }}
230
+ >
231
+ {label}
232
+ </span>
233
+ </button>
234
+ );
235
+ }
236
+
237
  /**
238
  * 4-px wide vertical drag handle between two panes.
239
  *
frontend/src/components/CircuitPicker.tsx CHANGED
@@ -1,9 +1,9 @@
1
  import { useEffect, useRef, useState } from "react";
2
- import { Eye, EyeOff, FileUp, Loader2 } from "lucide-react";
3
  import { api, type CircuitInfo, type SampleCircuit } from "../lib/api";
4
  import { useApp } from "../lib/store";
5
 
6
- export function CircuitPicker() {
7
  const [samples, setSamples] = useState<SampleCircuit[]>([]);
8
  const [busy, setBusy] = useState<string | null>(null);
9
  const [err, setErr] = useState<string | null>(null);
@@ -47,12 +47,25 @@ export function CircuitPicker() {
47
 
48
  return (
49
  <div className="p-3 border-b border-edge">
50
- <div className="flex items-center justify-between mb-2">
51
- <h3 className="text-xs font-semibold uppercase tracking-wider text-mute">
52
- Pipeline input
53
- </h3>
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  <button
55
- className="btn-ghost"
56
  onClick={() => fileRef.current?.click()}
57
  title="Upload your own .qpy (Qiskit) or .qasm (OpenQASM 2/3) file"
58
  >
 
1
  import { useEffect, useRef, useState } from "react";
2
+ import { ChevronLeft, Eye, EyeOff, FileUp, Loader2 } from "lucide-react";
3
  import { api, type CircuitInfo, type SampleCircuit } from "../lib/api";
4
  import { useApp } from "../lib/store";
5
 
6
+ export function CircuitPicker({ onCollapse }: { onCollapse?: () => void } = {}) {
7
  const [samples, setSamples] = useState<SampleCircuit[]>([]);
8
  const [busy, setBusy] = useState<string | null>(null);
9
  const [err, setErr] = useState<string | null>(null);
 
47
 
48
  return (
49
  <div className="p-3 border-b border-edge">
50
+ <div className="flex items-center justify-between mb-2 gap-2">
51
+ <div className="flex items-center gap-1 min-w-0">
52
+ {onCollapse && (
53
+ <button
54
+ type="button"
55
+ onClick={onCollapse}
56
+ className="shrink-0 text-mute hover:text-ink rounded hover:bg-surfaceAlt p-0.5 -ml-0.5"
57
+ title="Collapse pipeline input pane"
58
+ aria-label="Collapse pipeline input pane"
59
+ >
60
+ <ChevronLeft className="w-3.5 h-3.5" />
61
+ </button>
62
+ )}
63
+ <h3 className="text-xs font-semibold uppercase tracking-wider text-mute truncate">
64
+ Pipeline input
65
+ </h3>
66
+ </div>
67
  <button
68
+ className="btn-ghost shrink-0"
69
  onClick={() => fileRef.current?.click()}
70
  title="Upload your own .qpy (Qiskit) or .qasm (OpenQASM 2/3) file"
71
  >
frontend/src/components/ResultsPane.tsx CHANGED
@@ -1,21 +1,34 @@
1
  import { useApp } from "../lib/store";
2
  import type { StepResult } from "../lib/api";
3
  import { NODE_BY_KIND, type NodeKind } from "../lib/nodeCatalog";
4
- import { AlertCircle, Check, CircleDot, Clock } from "lucide-react";
5
 
6
- export function ResultsPane() {
7
  const run = useApp((s) => s.run);
8
  const running = useApp((s) => s.running);
9
 
10
  return (
11
  <div className="flex-1 flex flex-col min-h-0">
12
- <div className="h-12 shrink-0 border-b border-edge px-4 flex items-center justify-between">
13
- <h3 className="text-sm font-semibold text-ink">Results</h3>
14
- {run && (
15
- <span className="chip">
16
- {run.steps.length} step{run.steps.length === 1 ? "" : "s"}
17
- </span>
18
- )}
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </div>
20
  <div className="flex-1 overflow-y-auto p-3 space-y-3 min-h-0">
21
  {!run && !running && <EmptyHint />}
 
1
  import { useApp } from "../lib/store";
2
  import type { StepResult } from "../lib/api";
3
  import { NODE_BY_KIND, type NodeKind } from "../lib/nodeCatalog";
4
+ import { AlertCircle, Check, ChevronRight, CircleDot, Clock } from "lucide-react";
5
 
6
+ export function ResultsPane({ onCollapse }: { onCollapse?: () => void } = {}) {
7
  const run = useApp((s) => s.run);
8
  const running = useApp((s) => s.running);
9
 
10
  return (
11
  <div className="flex-1 flex flex-col min-h-0">
12
+ <div className="h-12 shrink-0 border-b border-edge px-4 flex items-center justify-between gap-2">
13
+ <h3 className="text-sm font-semibold text-ink truncate">Results</h3>
14
+ <div className="flex items-center gap-1.5 shrink-0">
15
+ {run && (
16
+ <span className="chip">
17
+ {run.steps.length} step{run.steps.length === 1 ? "" : "s"}
18
+ </span>
19
+ )}
20
+ {onCollapse && (
21
+ <button
22
+ type="button"
23
+ onClick={onCollapse}
24
+ className="text-mute hover:text-ink rounded hover:bg-surfaceAlt p-0.5"
25
+ title="Collapse results pane"
26
+ aria-label="Collapse results pane"
27
+ >
28
+ <ChevronRight className="w-3.5 h-3.5" />
29
+ </button>
30
+ )}
31
+ </div>
32
  </div>
33
  <div className="flex-1 overflow-y-auto p-3 space-y-3 min-h-0">
34
  {!run && !running && <EmptyHint />}