From f80e7fe617d019d6892bd6e6c8a206b107b23d03 Mon Sep 17 00:00:00 2001 From: Shawn Hwang Date: Fri, 27 Nov 2026 16:44:50 -0800 Subject: [PATCH] egocap: the side panel opens and closes, and the cameras take the room it leaves The side panel (hand view, 3D view, details) was always shown. One button on the boundary between the cameras and the panel now closes it and opens it again; closed, the cameras, the status bar and the controls take the full width. The choice is this browser's and is remembered; the panel's width is kept while it is closed. Settings, Display has the same switch. - Closed, the panel's content is not mounted, so the 3D view holds no connection it does not show; it starts from its default camera when the panel is opened again. - No keyboard shortcut is bound: the recording shortcuts are bare keys that are live during a take, and one more would rearrange the screen on a slip. The button is in the tab order. - Cameras that arrive over LiveKit choose the large tile by the same rule as the others: the camera assigned the ego role, else one named head, else the first. - The status bar puts the counts on a row of their own by the width of the main column, not the window's, so a closed panel gives the row back. A tile's caption wraps inside its tile. The stacked layout of a narrow window keeps the main column's height. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Shawn Hwang --- examples/egocap/frontend/README.md | 42 +++- .../frontend/src/App.operatorLayout.test.tsx | 229 +++++++++++++++++- examples/egocap/frontend/src/App.tsx | 120 ++++++--- .../frontend/src/CameraGrid.livekit.test.tsx | 45 ++++ .../egocap/frontend/src/CameraGrid.test.tsx | 14 ++ examples/egocap/frontend/src/CameraGrid.tsx | 10 +- .../frontend/src/SettingsPanel.test.tsx | 33 +++ .../egocap/frontend/src/SettingsPanel.tsx | 26 +- .../frontend/src/SidebarToggle.test.tsx | 45 ++++ .../egocap/frontend/src/SidebarToggle.tsx | 35 +++ .../egocap/frontend/src/sidebarOpen.test.ts | 50 ++++ examples/egocap/frontend/src/sidebarOpen.ts | 34 +++ examples/egocap/frontend/src/styles.css | 147 +++++++++-- 13 files changed, 755 insertions(+), 75 deletions(-) create mode 100644 examples/egocap/frontend/src/SidebarToggle.test.tsx create mode 100644 examples/egocap/frontend/src/SidebarToggle.tsx create mode 100644 examples/egocap/frontend/src/sidebarOpen.test.ts create mode 100644 examples/egocap/frontend/src/sidebarOpen.ts diff --git a/examples/egocap/frontend/README.md b/examples/egocap/frontend/README.md index 8536518e78..5163da0d35 100644 --- a/examples/egocap/frontend/README.md +++ b/examples/egocap/frontend/README.md @@ -178,8 +178,8 @@ The page is built for an operator mid-take: the cameras fill it, and everything calibration files are an advisory item and takes are allowed; on, they fail and hold recording. A change is followed by an immediate read of the checklist. The calibration tools are listed beneath it, each opening its own dialog (see "Calibration tools" below). - - *Display* holds this browser's own choices: *Show the hand view* (see [Hand view](#hand-view)) and the side - panel's width, then the keyboard shortcuts. Nothing on it needs the control token. + - *Display* holds this browser's own choices: *Show the hand view* (see [Hand view](#hand-view)), then *Show the + side panel* and the side panel's width, then the keyboard shortcuts. Nothing on it needs the control token. - *Advanced* shows what the deployment runs with, read-only. Its *Capture checks* card names the thresholds takes are judged by: whether a take marked bad is quarantined or flagged, the camera minimum rate, the frozen-stream limit, the defaults file's name and SHA-256, and what the station file changed. They are set in files, never from the page. @@ -372,22 +372,42 @@ The page is built for an operator mid-take: the cameras fill it, and everything the number of takes of the batch changes, so it does not lag the bar above. It is read without the control token, so it never carries the day's notes, and after a change of the station in use it shows nothing until that station's own uptime has arrived. -- **Camera stage (middle).** It takes every pixel the bar above and the dock below leave. The head camera (the one named - `head*`, otherwise the first) takes the left two-thirds and the others stack on the right; each tile carries its name and - measured / advertised Hz and latency on the picture. A live take puts a red frame around the stage. +- **Camera stage (middle).** It takes every pixel the bar above and the dock below leave. The main camera (the one + assigned the ego role, otherwise the one named `head*`, otherwise the first) takes the left two-thirds and the others + stack on the right, in the order the session lists them; each tile carries its name and measured / advertised Hz and + latency on the picture, and in a small tile that caption wraps onto further lines inside the tile. A picture is + never cropped, so a tile shows black beside or above it where the tile's shape differs from the camera's. With + three 16:9 cameras the stage is filled when it is about 2.7 times as wide as it is tall; a narrower main column (a + wide side panel) leaves black above and below the pictures, a wider one beside them. A live take puts a red frame + around the stage. - **Control dock (bottom).** Record / Stop-Save / Discard are large; an unset operator or control-token field leads the dock, and once set shrinks to a quiet line. The dock hides the recording panel's own header and status line, since the bar above shows them, and the panel draws the last take's outcome above the cameras, not here. -- **Side panel (right).** Always showing: the hand view on top while it is switched on, then the 3D tracking view, then - the raw tracking tables and session details (Details scrolls inside itself, so it and the 3D view are never pushed - off the screen; with the hand view above them a short window has no room for all three, and the side panel scrolls - to Details instead). **Drag the divider** between it and the main column +- **Side panel (right).** Open until the operator closes it: the hand view on top while it is switched on, then the 3D + tracking view, then the raw tracking tables and session details (Details scrolls inside itself, so it and the 3D + view are never pushed off the screen; with the hand view above them a short window has no room for all three, and + the side panel scrolls to Details instead). +- **Closing the side panel.** The button at the top of the divider, *Close side panel*, takes the panel and the + divider out of the page, and the cameras, the status bar and the controls take the full width. The same button + stays as a slim tab down the right edge of the page, now *Open side panel* (`SidebarToggle.tsx`); focus stays on + it, and a status line tells a screen reader what happened. *Show the side panel* in Settings, Display, is the same + switch. The choice is remembered in this browser (`sidebarOpen.ts`, `localStorage`, open if storage is blocked), and + so is the width while the panel is closed. The hand view's own setting is separate and is not changed by it. + - The panel's content is in the page only while it is open, so a closed panel draws nothing and the 3D view holds + no connection. The cost is that the 3D view starts again on opening, at its default camera position, and the + disclosures under Details are collapsed again. + - There is no keyboard shortcut for it. The recording shortcuts are single unmodified keys that act whenever no + text field has focus, a take in progress included, so a further key would rearrange the screen on a slip of the + finger; the button is reached with Tab and pressed with Enter or Space. +- **Resizing the side panel.** **Drag the divider** between it and the main column to choose its width -- pulling left widens the panel and narrows the cameras, status bar and controls, and the other way round. The divider also works from the keyboard (focus it, then Left / Right arrows, Shift for bigger steps, Home / End for the limits) and double-click resets it. The width is clamped between 400 px and 1000 px and never leaves the main column under 560 px; it is remembered in this browser (`localStorage`, silently the default if storage is blocked). The status - bar rearranges itself by the main column's width (chips drop to their own row when it is narrow). On a window under 900 px - there is no room for two columns, so the panel goes below the page and the divider is hidden. + bar rearranges itself by the main column's width, not the window's: the chips drop to their own row when it is narrow, + and the saved count and last take to a row under the task when it is narrower still. On a window under 900 px + there is no room for two columns, so the panel goes below the page and the divider is hidden; the open/close button + is then a bar across the page above the panel. - The 3D view's iframe is never narrower than 640 px: Viser switches to a layout that hides its scene at 576 px and below, and crashes its own page when resized across that breakpoint. diff --git a/examples/egocap/frontend/src/App.operatorLayout.test.tsx b/examples/egocap/frontend/src/App.operatorLayout.test.tsx index 733e1f0ea2..a55a6c29a8 100644 --- a/examples/egocap/frontend/src/App.operatorLayout.test.tsx +++ b/examples/egocap/frontend/src/App.operatorLayout.test.tsx @@ -124,7 +124,7 @@ describe("operator page layout", () => { expect(screen.getByRole("separator", { name: "Resize side panel" })).not.toBeNull(); }); - it("always shows the side panel, the 3D view above the details under the hand view, with no drawer to open", () => { + it("shows the side panel until it is closed, the 3D view above the details under the hand view, with no drawer over the page", () => { const { container } = mount({ snapshot: snapshot({ visualization: { status: "ready", url: "http://lab:8085/", diagnostic: null } }) }); const panels = Array.from(container.querySelectorAll(".op-sidebar .op-panel")).map((p) => p.getAttribute("aria-label")); expect(panels).toEqual(["Hand view", "3D view", "Details"]); @@ -140,6 +140,14 @@ describe("operator page layout", () => { expect(screen.queryByRole("separator")).toBeNull(); }); + it("offers no button for a side panel that is not there while the feed is unavailable", () => { + window.localStorage.setItem("egocap.sidebar", "closed"); + const { container } = mount({ phase: "unavailable", snapshot: null, recordingSnapshot: null }); + expect(screen.queryByRole("button", { name: /side panel/ })).toBeNull(); + expect(container.querySelector(".op-rail")).toBeNull(); + expect(container.querySelector(".op-body")?.className).not.toContain("op-body--sidebar-closed"); + }); + it("frames the cameras in red only for a live take", () => { const live = mount({ recordingSnapshot: recording({ episodePhase: "RECORDING", currentEpisodeElapsedMs: 5000 }) }); expect(live.container.querySelector(".op-stage")?.className).toContain("op-stage--recording"); @@ -244,6 +252,225 @@ describe("hand view on the recording screen", () => { }); }); +describe("opening and closing the side panel", () => { + const ready = () => snapshot({ visualization: { status: "ready", url: "http://lab:8085/", diagnostic: null } }); + const closeButton = () => screen.getByRole("button", { name: "Close side panel" }); + const openButton = () => screen.getByRole("button", { name: "Open side panel" }); + const said = (container: HTMLElement) => container.querySelector(".op-rail [role='status']")?.textContent; + const widthOf = (container: HTMLElement) => (container.querySelector(".op-body") as HTMLElement).style.getPropertyValue("--op-sidebar-width"); + + function windowWidth(width: number) { + Object.defineProperty(window, "innerWidth", { configurable: true, value: width }); + } + + it("is open by default, with a button on its edge that names the panel it closes", () => { + const { container } = mount({ snapshot: ready() }); + expect(container.querySelector(".op-body")?.className).not.toContain("op-body--sidebar-closed"); + expect(screen.queryByRole("button", { name: "Open side panel" })).toBeNull(); + expect(closeButton().getAttribute("aria-expanded")).toBe("true"); + expect(document.getElementById(closeButton().getAttribute("aria-controls") ?? "")).toBe(container.querySelector(".op-sidebar")); + // The button sits on the boundary, ahead of the divider and the panel it closes. + expect(container.querySelector(".op-body > .op-main + .op-rail + .op-sidebar")).not.toBeNull(); + expect(container.querySelector(".op-rail > .op-sidebar-toggle")).toBe(closeButton()); + // The arrow is decoration: the button is named by its words alone. + expect(closeButton().querySelector("[aria-hidden='true']")?.textContent).toBe("»"); + }); + + it("closes from its button: the panel, its divider and the 3D view leave the page, and the main column is marked full width", () => { + const { container } = mount({ snapshot: ready(), trackingSample: handSample(handDisplay(syntheticHand("left")), handDisplay(syntheticHand("right"))) }); + expect(container.querySelector(".op-sidebar iframe")).not.toBeNull(); + fireEvent.click(closeButton()); + expect(container.querySelector(".op-body")?.className).toContain("op-body--sidebar-closed"); + // Gone for a screen reader too: no landmark, no divider, nothing left inside the hidden element. + expect(screen.queryByRole("complementary")).toBeNull(); + expect(screen.queryByRole("separator")).toBeNull(); + const panel = container.querySelector(".op-sidebar") as HTMLElement; + expect(panel.hidden).toBe(true); + expect(panel.childElementCount).toBe(0); + // The 3D view is not kept alive behind a closed panel. + expect(container.querySelector("iframe")).toBeNull(); + expect(container.querySelector(".hand-view")).toBeNull(); + // The rest of the page is as it was. + expect(container.querySelector(".op-stage .camera-grid")).not.toBeNull(); + expect(container.querySelector(".op-dock .recording-panel")).not.toBeNull(); + expect(screen.getByRole("region", { name: "Operator status" })).not.toBeNull(); + // The same button now opens it, and still names an element that exists. + expect(screen.queryByRole("button", { name: "Close side panel" })).toBeNull(); + expect(openButton().getAttribute("aria-expanded")).toBe("false"); + expect(document.getElementById(openButton().getAttribute("aria-controls") ?? "")).toBe(panel); + expect(openButton().querySelector("[aria-hidden='true']")?.textContent).toBe("«"); + }); + + it("opens again from the same place, with the hand view, the 3D view and the details back in order", () => { + const { container } = mount({ snapshot: ready() }); + fireEvent.click(closeButton()); + fireEvent.click(openButton()); + expect(container.querySelector(".op-body")?.className).not.toContain("op-body--sidebar-closed"); + expect((container.querySelector(".op-sidebar") as HTMLElement).hidden).toBe(false); + expect(sidePanels(container)).toEqual(["Hand view", "3D view", "Details"]); + expect(container.querySelector(".op-sidebar iframe")).not.toBeNull(); + expect(screen.getByRole("complementary", { name: "Hand view, 3D view and details" })).not.toBeNull(); + expect(screen.getByRole("separator", { name: "Resize side panel" })).not.toBeNull(); + expect(closeButton().getAttribute("aria-expanded")).toBe("true"); + }); + + it("moves focus to the button that undoes the change, when closing and when opening", () => { + mount(); + const settings = screen.getByRole("button", { name: "Settings" }); + settings.focus(); + fireEvent.click(closeButton()); + expect(document.activeElement).toBe(openButton()); + settings.focus(); + fireEvent.click(openButton()); + expect(document.activeElement).toBe(closeButton()); + }); + + it("says what happened in a polite status line, and nothing before the operator acts", () => { + const { container } = mount(); + expect(container.querySelector(".op-rail [role='status']")).not.toBeNull(); + expect(said(container)).toBe(""); + fireEvent.click(closeButton()); + expect(said(container)).toBe("The side panel is closed. The cameras take the full width."); + fireEvent.click(openButton()); + expect(said(container)).toBe("The side panel is open."); + }); + + it("remembers the choice in this browser and starts closed on the next load, without announcing it", () => { + const first = mount(); + fireEvent.click(closeButton()); + expect(window.localStorage.getItem("egocap.sidebar")).toBe("closed"); + first.unmount(); + const { container } = mount({ snapshot: ready() }); + expect(container.querySelector(".op-body")?.className).toContain("op-body--sidebar-closed"); + expect(screen.queryByRole("complementary")).toBeNull(); + expect(container.querySelector("iframe")).toBeNull(); + expect(said(container)).toBe(""); + fireEvent.click(openButton()); + expect(window.localStorage.getItem("egocap.sidebar")).toBe("open"); + }); + + it("still opens and closes when the browser blocks storage, starting open", () => { + const blocked = () => { + throw new Error("blocked"); + }; + const getItem = vi.spyOn(Storage.prototype, "getItem").mockImplementation(blocked); + const setItem = vi.spyOn(Storage.prototype, "setItem").mockImplementation(blocked); + try { + const { container } = mount(); + expect(container.querySelector(".op-body")?.className).not.toContain("op-body--sidebar-closed"); + fireEvent.click(closeButton()); + expect(container.querySelector(".op-body")?.className).toContain("op-body--sidebar-closed"); + fireEvent.click(openButton()); + expect(screen.getByRole("complementary", { name: "Hand view, 3D view and details" })).not.toBeNull(); + } finally { + getItem.mockRestore(); + setItem.mockRestore(); + } + }); + + it("keeps the chosen width while closed and gives it back on opening", () => { + windowWidth(1600); + const { container } = mount(); + fireEvent.keyDown(screen.getByRole("separator", { name: "Resize side panel" }), { key: "ArrowLeft", shiftKey: true }); + expect(widthOf(container)).toBe("556px"); + fireEvent.click(closeButton()); + expect(window.localStorage.getItem("egocap.sidebarWidth")).toBe("556"); + fireEvent.click(openButton()); + expect(widthOf(container)).toBe("556px"); + expect(screen.getByRole("separator", { name: "Resize side panel" }).getAttribute("aria-valuenow")).toBe("556"); + windowWidth(1024); + }); + + it("opens at the remembered width when it was closed on the last load", () => { + windowWidth(1600); + window.localStorage.setItem("egocap.sidebarWidth", "620"); + window.localStorage.setItem("egocap.sidebar", "closed"); + const { container } = mount(); + fireEvent.click(openButton()); + expect(widthOf(container)).toBe("620px"); + windowWidth(1024); + }); + + it("refits a closed panel's width to a smaller window, so it opens leaving the main column its room", () => { + windowWidth(1600); + const { container } = mount(); + fireEvent.keyDown(screen.getByRole("separator", { name: "Resize side panel" }), { key: "End" }); + fireEvent.click(closeButton()); + windowWidth(1200); + fireEvent(window, new Event("resize")); + fireEvent.click(openButton()); + expect(widthOf(container)).toBe("640px"); // 1200 - 560 + // The refit is the window's doing, not the operator's choice. + expect(window.localStorage.getItem("egocap.sidebarWidth")).toBe("1000"); + windowWidth(1024); + }); + + it("leaves the hand view's own setting alone: shown stays shown and hidden stays hidden across a close and open", () => { + const { container } = mount(); + fireEvent.click(closeButton()); + expect(window.localStorage.getItem("egocap.handView")).toBeNull(); + fireEvent.click(openButton()); + expect(sidePanels(container)).toEqual(["Hand view", "3D view", "Details"]); + fireEvent.click(screen.getByRole("button", { name: "Hide the hand view" })); + fireEvent.click(closeButton()); + expect(window.localStorage.getItem("egocap.handView")).toBe("off"); + fireEvent.click(openButton()); + expect(sidePanels(container)).toEqual(["3D view", "Details"]); + expect(window.localStorage.getItem("egocap.handView")).toBe("off"); + expect(screen.getByRole("complementary", { name: "3D view and details" })).not.toBeNull(); + }); + + it("opens and closes from Settings, Display, with the page behind following at once and focus staying in the dialog", () => { + const { container } = mount(); + fireEvent.click(screen.getByRole("button", { name: "Settings" })); + const dialog = screen.getByRole("dialog", { name: "Settings" }); + fireEvent.click(within(dialog).getByRole("button", { name: "Display" })); + const setting = within(dialog).getByRole("checkbox", { name: "Show the side panel" }) as HTMLInputElement; + expect(setting.checked).toBe(true); + setting.focus(); + fireEvent.click(setting); + expect(setting.checked).toBe(false); + expect(container.querySelector(".op-body")?.className).toContain("op-body--sidebar-closed"); + expect((container.querySelector(".op-sidebar") as HTMLElement).hidden).toBe(true); + expect(window.localStorage.getItem("egocap.sidebar")).toBe("closed"); + expect(said(container)).toBe("The side panel is closed. The cameras take the full width."); + // The dialog owns focus: the page's button does not take it. + expect(dialog.contains(document.activeElement)).toBe(true); + fireEvent.click(setting); + expect(setting.checked).toBe(true); + expect(container.querySelector(".op-body")?.className).not.toContain("op-body--sidebar-closed"); + expect(window.localStorage.getItem("egocap.sidebar")).toBe("open"); + // The hand view's switch beside it is a separate setting. + expect((within(dialog).getByRole("checkbox", { name: "Show the hand view" }) as HTMLInputElement).checked).toBe(true); + }); + + it("shows the setting switched off after the panel was closed from its button", () => { + mount(); + fireEvent.click(closeButton()); + fireEvent.click(screen.getByRole("button", { name: "Settings" })); + fireEvent.click(within(screen.getByRole("dialog", { name: "Settings" })).getByRole("button", { name: "Display" })); + expect((screen.getByRole("checkbox", { name: "Show the side panel" }) as HTMLInputElement).checked).toBe(false); + }); + + it("leaves the recording shortcuts working while the panel is closed and its button has focus", () => { + const send = vi.fn().mockResolvedValue({ outcome: "ok", reason: null }); + mount({ sendRecordingCommand: send, recordingSnapshot: recording({ episodePhase: "RECORDING", currentEpisodeId: "e1", currentEpisodeElapsedMs: 0 }) }); + fireEvent.click(closeButton()); + expect(document.activeElement).toBe(openButton()); + fireEvent.keyDown(window, { key: "w" }); + expect(send).toHaveBeenCalledTimes(1); + // Closing and opening are layout only: neither sends a command. + fireEvent.click(openButton()); + expect(send).toHaveBeenCalledTimes(1); + }); + + it("keeps the red frame of a live take around the cameras while closed", () => { + const { container } = mount({ recordingSnapshot: recording({ episodePhase: "RECORDING", currentEpisodeElapsedMs: 5000 }) }); + fireEvent.click(closeButton()); + expect(container.querySelector(".op-stage")?.className).toContain("op-stage--recording"); + }); +}); + /** Answer the routes a test names and leave every other request unanswered, as a backend that is still starting would. */ function stubRoutes(routes: Record) { const fetched = vi.fn(async (url: string, _init?: RequestInit) => (url in routes ? new Response(JSON.stringify(routes[url]), { status: 200 }) : new Response("{}", { status: 503 }))); diff --git a/examples/egocap/frontend/src/App.tsx b/examples/egocap/frontend/src/App.tsx index a2c5632d7d..d7d526b0c6 100644 --- a/examples/egocap/frontend/src/App.tsx +++ b/examples/egocap/frontend/src/App.tsx @@ -27,6 +27,8 @@ import { GloveOffsetDialog } from "./GloveOffsetDialog"; import { HeadsetCalibrationDialog } from "./HeadsetCalibrationDialog"; import { OperatorBar } from "./OperatorBar"; import { SidebarResizer } from "./SidebarResizer"; +import { SidebarToggle } from "./SidebarToggle"; +import { loadSidebarOpen, saveSidebarOpen } from "./sidebarOpen"; import { SIDEBAR_DEFAULT_PX, SIDEBAR_MIN_PX, @@ -442,6 +444,9 @@ function SessionDetails({ ); } +/** The side panel's element id, which its open/close button names as the thing it controls. */ +const SIDEBAR_ID = "op-sidebar"; + const FEED_HEALTH_LABEL: Record = { connecting: "connecting", ok: "current", @@ -478,9 +483,9 @@ export default function App() { // A live take frames the cameras in red, so the state reads from across the room; never from a stale feed. const recording = presentation.live && recordingSnapshot?.episodePhase === "RECORDING"; const [panelPhase, setPanelPhase] = useState("idle"); - // The side panel is always showing: the hand view while it is on, then the 3D view above the raw data. Its width - // is the operator's to choose by dragging the divider; the cameras, status bar and controls take whatever it - // leaves. The choice is remembered. + // The side panel holds the hand view while it is on, then the 3D view above the raw data. Its width is the + // operator's to choose by dragging the divider; the cameras, status bar and controls take whatever it leaves. + // The choice is remembered, and is kept while the panel is closed. const [sidebarWidth, setSidebarWidth] = useState(() => clampSidebarWidth(loadSidebarWidth(), window.innerWidth)); const [resizing, setResizing] = useState(false); // The latest clamped width, readable from event handlers without a stale closure (a drag end must save the final value). @@ -498,7 +503,25 @@ export default function App() { window.addEventListener("resize", refit); return () => window.removeEventListener("resize", refit); }, []); + // Open or closed is this browser's choice too, flipped by the button on the panel's edge and by Settings. + const [sidebarOpen, setSidebarOpen] = useState(loadSidebarOpen); + // What the last open or close did, for a screen reader. Empty until the operator does either. + const [sidebarNotice, setSidebarNotice] = useState(""); + const sidebarToggleRef = useRef(null); + /** Open or close the side panel, remember the choice and say what happened. */ + const showSidebar = useCallback((open: boolean) => { + setSidebarOpen(open); + saveSidebarOpen(open); + setSidebarNotice(open ? "The side panel is open." : "The side panel is closed. The cameras take the full width."); + }, []); + /** Open or close from the panel's own button. Focus is put on the button, since not every browser focuses a + * button that is clicked, and it is the one control that undoes what was just done. */ + const toggleSidebar = () => { + showSidebar(!sidebarOpen); + sidebarToggleRef.current?.focus(); + }; // The hand view is this browser's choice, flipped by the setting in Settings and by the panel's own Hide button. + // It is independent of the side panel being open: closing the panel leaves it as it was. const [handViewShown, setHandViewShown] = useState(loadHandViewShown); const sidebarRef = useRef(null); /** Show or hide the hand view and remember the choice. */ @@ -628,6 +651,8 @@ export default function App() { sidebarWidth={sidebarWidth} sidebarDefault={SIDEBAR_DEFAULT_PX} onResetSidebar={() => applyWidth(SIDEBAR_DEFAULT_PX, true)} + sidebarOpen={sidebarOpen} + onSidebarOpen={showSidebar} handViewShown={handViewShown} onHandViewShown={showHandView} controlToken={controlToken} @@ -637,7 +662,7 @@ export default function App() { />
@@ -695,41 +720,64 @@ export default function App() {
{!unavailable && ( <> - applyWidth(width, !resizing)} - onReset={() => applyWidth(SIDEBAR_DEFAULT_PX, true)} - onDragChange={(dragging) => { - setResizing(dragging); - if (!dragging) saveSidebarWidth(sidebarWidthRef.current); - }} - /> -
diff --git a/examples/egocap/frontend/src/SettingsPanel.test.tsx b/examples/egocap/frontend/src/SettingsPanel.test.tsx index a9e83ba71e..ed7514984e 100644 --- a/examples/egocap/frontend/src/SettingsPanel.test.tsx +++ b/examples/egocap/frontend/src/SettingsPanel.test.tsx @@ -76,6 +76,8 @@ function renderPanel(overrides: Partial[0]> = { sidebarWidth: 460, sidebarDefault: 460, onResetSidebar: vi.fn(), + sidebarOpen: true, + onSidebarOpen: vi.fn(), handViewShown: true, onHandViewShown: vi.fn(), controlToken: "tok" as string | null, @@ -542,6 +544,37 @@ describe("Display tab's hand view setting", () => { }); }); +describe("Display tab's side panel setting", () => { + it("shows whether the side panel is open, beside its width, and asks the page to flip it", () => { + const { props, unmount } = renderPanel({ initialTab: "display", sidebarOpen: true, sidebarWidth: 600 }); + const card = screen.getByRole("region", { name: "Layout" }); + expect(within(card).getByText("Remembered in this browser only.")).toBeTruthy(); + expect(within(card).getByText("600 px")).toBeTruthy(); + const setting = within(card).getByRole("checkbox", { name: "Show the side panel" }) as HTMLInputElement; + expect(setting.checked).toBe(true); + // The box is described by what the panel holds, what closing it does and how to bring it back. + expect(document.getElementById(setting.getAttribute("aria-describedby") ?? "")?.textContent).toBe( + "The hand view, the 3D view and the details, beside the cameras. Closed, the cameras, the status bar and the controls take the full width, and the Open side panel button brings it back. Its width is kept.", + ); + fireEvent.click(setting); + expect(props.onSidebarOpen).toHaveBeenCalledExactlyOnceWith(false); + expect(props.onHandViewShown).not.toHaveBeenCalled(); + unmount(); + const closed = renderPanel({ initialTab: "display", sidebarOpen: false }); + const box = screen.getByRole("checkbox", { name: "Show the side panel" }) as HTMLInputElement; + expect(box.checked).toBe(false); + fireEvent.click(box); + expect(closed.props.onSidebarOpen).toHaveBeenCalledExactlyOnceWith(true); + }); + + it("needs no control token, and leaves the width reset usable while the panel is closed", () => { + const { props } = renderPanel({ initialTab: "display", controlToken: null, sidebarOpen: false, sidebarWidth: 600 }); + expect((screen.getByRole("checkbox", { name: "Show the side panel" }) as HTMLInputElement).disabled).toBe(false); + fireEvent.click(screen.getByRole("button", { name: "Reset side panel width" })); + expect(props.onResetSidebar).toHaveBeenCalledTimes(1); + }); +}); + describe("Advanced tab", () => { it("shows the deployment settings grouped, with the variables they come from", async () => { renderPanel({ initialTab: "advanced" }); diff --git a/examples/egocap/frontend/src/SettingsPanel.tsx b/examples/egocap/frontend/src/SettingsPanel.tsx index a6826aa59f..4389f391a6 100644 --- a/examples/egocap/frontend/src/SettingsPanel.tsx +++ b/examples/egocap/frontend/src/SettingsPanel.tsx @@ -8,8 +8,8 @@ * Tabs, in the order an operator sets up a station: Station (the stations, the one in use, and each station's * cameras; the camera setup itself while there are no stations), Devices (the live checklist of what the station * in use needs, whether calibration files are required, and the calibration tools), Tasks (the catalogs the task - * picker offers, imports, and the preselected task), Display (this browser's choices, the hand view among them, - * and the keyboard shortcuts), Advanced (what the deployment is running with, read-only). Station, Tasks and the calibration + * picker offers, imports, and the preselected task), Display (this browser's choices, the hand view and the side + * panel among them, and the keyboard shortcuts), Advanced (what the deployment is running with, read-only). Station, Tasks and the calibration * requirement are saved by the backend for every browser and need the run's control token to change, as * recording commands do; the rest of Devices only reports; Display is this browser's only; Advanced values are * set where the backend is launched. @@ -104,6 +104,10 @@ export interface SettingsPanelProps { sidebarWidth: number; sidebarDefault: number; onResetSidebar: () => void; + /** Whether the side panel is open on the recording screen, for the Display tab. */ + sidebarOpen: boolean; + /** Opens or closes the side panel and remembers the choice in this browser. */ + onSidebarOpen: (open: boolean) => void; /** Whether the hand view is shown on the recording screen, for the Display tab. */ handViewShown: boolean; /** Shows or hides the hand view and remembers the choice in this browser. */ @@ -465,14 +469,17 @@ const SHORTCUTS: ReadonlyArray<[string, string]> = [ ["Enter / Esc", "Save / cancel the task editor"], ]; -/** This browser's choices: whether the hand view is shown and how wide the side panel is; then the shortcuts. */ +/** This browser's choices: whether the hand view is shown, whether the side panel is open and how wide it is; then + * the shortcuts. */ function DisplayTab({ sidebarWidth, sidebarDefault, onResetSidebar, + sidebarOpen, + onSidebarOpen, handViewShown, onHandViewShown, -}: Pick) { +}: Pick) { return ( <> @@ -485,6 +492,13 @@ function DisplayTab({

+ +

+ The hand view, the 3D view and the details, beside the cameras. Closed, the cameras, the status bar and the controls take the full width, and the Open side panel button brings it back. Its width is kept. +

@@ -644,6 +658,8 @@ export function SettingsPanel({ sidebarWidth, sidebarDefault, onResetSidebar, + sidebarOpen, + onSidebarOpen, handViewShown, onHandViewShown, controlToken, @@ -745,7 +761,7 @@ export function SettingsPanel({ {tab === "station" && } {tab === "devices" && } {tab === "tasks" && } - {tab === "display" && } + {tab === "display" && } {tab === "advanced" && (controlToken === null ?

Enter the control token in the recording panel to view deployment settings.

: )} diff --git a/examples/egocap/frontend/src/SidebarToggle.test.tsx b/examples/egocap/frontend/src/SidebarToggle.test.tsx new file mode 100644 index 0000000000..5c67d7e0a0 --- /dev/null +++ b/examples/egocap/frontend/src/SidebarToggle.test.tsx @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +/** The side panel's open/close button on its own: its name, what it tells assistive tech, and its one action. */ +import { createRef } from "react"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { cleanup, fireEvent, render, screen } from "@testing-library/react"; +import { SidebarToggle } from "./SidebarToggle"; + +afterEach(cleanup); + +describe("SidebarToggle", () => { + it("is named Close side panel while the panel is open and reports it expanded", () => { + render(); + const button = screen.getByRole("button", { name: "Close side panel" }); + expect(button.getAttribute("type")).toBe("button"); + expect(button.getAttribute("aria-expanded")).toBe("true"); + expect(button.getAttribute("aria-controls")).toBe("panel"); + expect(button.textContent).toBe("»Close side panel"); + }); + + it("is named Open side panel while the panel is closed and reports it collapsed", () => { + render(); + const button = screen.getByRole("button", { name: "Open side panel" }); + expect(button.getAttribute("aria-expanded")).toBe("false"); + expect(button.getAttribute("aria-controls")).toBe("panel"); + expect(button.textContent).toBe("«Open side panel"); + }); + + it("keeps its arrow out of its name, so the state is told in words", () => { + const { container } = render(); + expect(container.querySelector(".op-sidebar-toggle-arrow")?.getAttribute("aria-hidden")).toBe("true"); + expect(container.querySelector(".op-sidebar-toggle-label")?.textContent).toBe("Close side panel"); + }); + + it("reports one press per click and hands its element to the caller", () => { + const onToggle = vi.fn(); + const ref = createRef(); + render(); + fireEvent.click(screen.getByRole("button", { name: "Close side panel" })); + expect(onToggle).toHaveBeenCalledTimes(1); + expect(ref.current).toBe(screen.getByRole("button", { name: "Close side panel" })); + }); +}); diff --git a/examples/egocap/frontend/src/SidebarToggle.tsx b/examples/egocap/frontend/src/SidebarToggle.tsx new file mode 100644 index 0000000000..a9b604c795 --- /dev/null +++ b/examples/egocap/frontend/src/SidebarToggle.tsx @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +/** + * The button that closes the side panel and opens it again. It is one control in one place, on the boundary between + * the main column and the panel, so it is where the operator last pressed it and it keeps focus through the change. + * Its words say what it will do; the arrow beside them only repeats that. + */ + +import type { Ref } from "react"; + +export interface SidebarToggleProps { + /** Whether the side panel is open now. */ + open: boolean; + /** The id of the side panel's element, which this button shows and hides. */ + controls: string; + /** The button was pressed: the caller opens or closes the panel. */ + onToggle: () => void; + /** The button's element, so the caller can put focus on it after the change. */ + ref?: Ref; +} + +/** The side panel's open/close button: "Close side panel" while it is open, "Open side panel" while it is closed. */ +export function SidebarToggle({ open, controls, onToggle, ref }: SidebarToggleProps) { + return ( + + ); +} diff --git a/examples/egocap/frontend/src/sidebarOpen.test.ts b/examples/egocap/frontend/src/sidebarOpen.test.ts new file mode 100644 index 0000000000..788e39d254 --- /dev/null +++ b/examples/egocap/frontend/src/sidebarOpen.test.ts @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +/** The side panel's open/closed choice: open by default, and remembered safely in this browser. */ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { SIDEBAR_OPEN_DEFAULT, loadSidebarOpen, saveSidebarOpen } from "./sidebarOpen"; + +afterEach(() => { + window.localStorage.clear(); + vi.restoreAllMocks(); +}); + +describe("remembering whether the side panel is open", () => { + it("is open until someone closes it", () => { + expect(SIDEBAR_OPEN_DEFAULT).toBe(true); + expect(loadSidebarOpen()).toBe(true); + }); + + it("round-trips both choices", () => { + saveSidebarOpen(false); + expect(loadSidebarOpen()).toBe(false); + expect(window.localStorage.getItem("egocap.sidebar")).toBe("closed"); + saveSidebarOpen(true); + expect(loadSidebarOpen()).toBe(true); + expect(window.localStorage.getItem("egocap.sidebar")).toBe("open"); + }); + + it("is the default with junk stored or when storage throws", () => { + window.localStorage.setItem("egocap.sidebar", "ajar"); + expect(loadSidebarOpen()).toBe(SIDEBAR_OPEN_DEFAULT); + vi.spyOn(Storage.prototype, "getItem").mockImplementation(() => { + throw new Error("blocked"); + }); + expect(loadSidebarOpen()).toBe(SIDEBAR_OPEN_DEFAULT); + }); + + it("keeps the width's own entry out of it", () => { + window.localStorage.setItem("egocap.sidebarWidth", "612"); + saveSidebarOpen(false); + expect(window.localStorage.getItem("egocap.sidebarWidth")).toBe("612"); + }); + + it("does not throw when the choice cannot be stored", () => { + vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => { + throw new Error("blocked"); + }); + expect(() => saveSidebarOpen(false)).not.toThrow(); + }); +}); diff --git a/examples/egocap/frontend/src/sidebarOpen.ts b/examples/egocap/frontend/src/sidebarOpen.ts new file mode 100644 index 0000000000..18853c147a --- /dev/null +++ b/examples/egocap/frontend/src/sidebarOpen.ts @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +/** + * Whether the side panel is open, remembered in this browser. Like its width it is a choice about one screen, so it + * lives with the screen and not with the station's settings on the backend. Pure and independent of React. + */ + +/** The side panel is open until an operator closes it. */ +export const SIDEBAR_OPEN_DEFAULT = true; + +const STORAGE_KEY = "egocap.sidebar"; + +/** The choice remembered in this browser, or the default. Storage can be blocked or hold junk; neither is an error. */ +export function loadSidebarOpen(): boolean { + try { + const stored = window.localStorage.getItem(STORAGE_KEY); + if (stored === "open") return true; + if (stored === "closed") return false; + } catch { + // storage blocked: use the default + } + return SIDEBAR_OPEN_DEFAULT; +} + +/** Remember the choice in this browser. */ +export function saveSidebarOpen(open: boolean): void { + try { + window.localStorage.setItem(STORAGE_KEY, open ? "open" : "closed"); + } catch { + // storage blocked: the choice just is not remembered + } +} diff --git a/examples/egocap/frontend/src/styles.css b/examples/egocap/frontend/src/styles.css index d27aaa5a37..0d0ff9e0f6 100644 --- a/examples/egocap/frontend/src/styles.css +++ b/examples/egocap/frontend/src/styles.css @@ -3046,14 +3046,21 @@ below for the narrow/stacked layout). */ font-size: 14px; } -/* The name and live rate sit on the picture, so the camera and its health read as one thing. */ +/* The name and live rate sit on the picture, so the camera and its health read as one thing. A small tile cannot + hold the name, the role and the rate on one line: they wrap as whole parts and stay inside the tile, and a tile + too short for them all keeps the name and drops what comes last. */ .op-stage .camera-tile figcaption { position: absolute; left: var(--space-2); bottom: var(--space-2); + max-width: calc(100% - 2 * var(--space-2)); + max-height: calc(100% - 2 * var(--space-2)); + overflow: hidden; display: flex; + flex-wrap: wrap; align-items: baseline; - gap: var(--space-2); + gap: 2px var(--space-2); + overflow-wrap: anywhere; padding: 4px 10px; border-radius: var(--radius-chip); background: rgb(0 0 0 / 62%); @@ -3070,6 +3077,13 @@ below for the narrow/stacked layout). */ margin-top: 0; color: #cbd5e1; font-weight: 400; + white-space: nowrap; +} + +/* The caption's own gap spaces the role from the name, on one line or two. */ +.op-stage .camera-tile figcaption .camera-role { + margin-left: 0; + white-space: nowrap; } .op-stage .camera-tile.tone-warning { @@ -3161,18 +3175,6 @@ below for the narrow/stacked layout). */ margin: 0; } -/* The drawer is narrow: let the recorded tracking tables scroll instead of overflowing it. */ -@media (max-width: 1100px) { - .op-bar { - grid-template-columns: auto minmax(0, 1fr); - } - - .op-counts, - .op-health { - grid-column: 1 / -1; - } -} - @media (max-width: 760px) { .op-dock { flex-direction: column; @@ -3280,7 +3282,7 @@ below for the narrow/stacked layout). */ padding-right: var(--space-1); } -/* --- Side panel: always showing, hand view (when on) then 3D view above Details, width chosen by the divider --- */ +/* --- Side panel: hand view (when on) then 3D view above Details, width chosen by the divider, closed from its edge --- */ .op-body { flex: 1 1 auto; @@ -3299,22 +3301,86 @@ below for the narrow/stacked layout). */ background: var(--canvas); } +/* Closed, the panel's element stays in the page for its button to name; it must take no room. */ +.op-sidebar[hidden] { + display: none; +} + +/* The boundary between the main column and the side panel: the open/close button over the divider. It stands partly + in the main column's own right padding, so while the panel is open it takes no width from the cameras. */ +.op-rail { + flex: none; + display: flex; + flex-direction: column; + width: 24px; + margin-left: calc(-1 * var(--space-3)); +} + +/* The words run down the rail, so the button is as slim as the divider it sits on. */ +.op-sidebar-toggle { + flex: none; + display: flex; + flex-direction: column; + align-items: center; + gap: var(--space-2); + width: 100%; + margin-top: var(--space-3); + padding: var(--space-2) 0; + border: 1px solid var(--border); + border-radius: var(--radius-chip); + background: var(--surface); + color: var(--text-secondary); + font: inherit; + font-size: 12px; + line-height: 1; + cursor: pointer; +} + +.op-sidebar-toggle:hover { + background: var(--surface-raised); + border-color: var(--accent); + color: var(--text-main); +} + +.op-sidebar-toggle:focus-visible { + outline: 2px solid var(--accent); + outline-offset: -2px; + color: var(--text-main); +} + +.op-sidebar-toggle-arrow { + font-size: 14px; +} + +.op-sidebar-toggle-label { + writing-mode: vertical-rl; + white-space: nowrap; +} + +/* Closed: the whole rail is the button, a tab down the page's right edge beside the full-width main column. */ +.op-body--sidebar-closed .op-sidebar-toggle { + flex: 1 1 auto; + margin-bottom: var(--space-4); + border-right: 0; + border-radius: var(--radius-chip) 0 0 var(--radius-chip); +} + /* The divider: a wide, easy-to-grab strip with a thin line that lights up on hover, focus and while dragging. */ .op-resizer { position: relative; - flex: none; - width: 12px; + flex: 1 1 auto; cursor: col-resize; touch-action: none; outline: none; } +/* The line keeps its distance from the side panel, whatever the rail's width. */ .op-resizer::before { content: ""; position: absolute; top: 0; bottom: 0; - left: 5px; + right: 5px; width: 2px; border-radius: 1px; background: var(--border); @@ -3379,7 +3445,8 @@ below for the narrow/stacked layout). */ padding-right: var(--space-1); } -/* A narrow window cannot share a row: the panel goes below the main column and the divider goes away. */ +/* A narrow window cannot share a row: the panel goes below the main column and the divider goes away. The + open/close button stays, as a bar across the page between the two. */ @media (max-width: 900px) { .app-shell--operator { height: auto; @@ -3389,10 +3456,40 @@ below for the narrow/stacked layout). */ flex-direction: column; } + /* Stacked, the main column is as tall as its content: left to shrink, the panel below would be drawn over it. */ + .op-main { + flex: none; + } + .op-resizer { display: none; } + .op-rail { + width: auto; + margin: 0 var(--space-4) var(--space-3); + } + + .op-sidebar-toggle, + .op-body--sidebar-closed .op-sidebar-toggle { + flex: none; + flex-direction: row; + justify-content: center; + margin: 0; + padding: var(--space-2) var(--space-3); + border: 1px solid var(--border); + border-radius: var(--radius-chip); + } + + .op-sidebar-toggle-label { + writing-mode: horizontal-tb; + } + + /* The panel is below the bar here, so the arrow turns to point down the page to open and up it to close. */ + .op-sidebar-toggle-arrow { + transform: rotate(-90deg); + } + .op-sidebar { width: auto; overflow-y: visible; @@ -3426,6 +3523,18 @@ below for the narrow/stacked layout). */ } } +/* Narrower still, the task would be squeezed between the state and the counts: the counts take a row of their own. + Also by the column's width, so a window that is small but has its side panel closed keeps them on the first row. */ +@container op-main (max-width: 720px) { + .op-bar { + grid-template-columns: auto minmax(0, 1fr); + } + + .op-counts { + grid-column: 1 / -1; + } +} + /* Direct LiveKit preview tiles: a