50bff3b274
## Thinking Path > - Paperclip is the open source control plane people use to manage AI agents, work, and company context. > - The board UI sidebar is the main way operators keep orientation across companies, projects, agents, issues, and settings. > - The existing fixed expanded sidebar competes with route-specific navigation, especially company settings and plugin routes that bring their own contextual sidebar. > - A collapsible primary rail preserves global navigation while giving contextual pages more horizontal room. > - This pull request adds a persisted collapsed rail, hover/focus peek, keyboard toggle, and a secondary sidebar takeover model for settings and plugin `routeSidebar` surfaces. > - The benefit is a denser board shell that keeps the app rail available without replacing it when a route needs its own navigation. ## Linked Issues or Issue Description Paperclip issue: PAP-10638 Create collapsible sidebar branch. Related GitHub PR found during duplicate search: #3838 (`feat/collapsible-sidebar`) covers a similar sidebar area but is a different head branch and implementation. This PR intentionally packages the work from `PAP-10638-collapsable-sidebar` into one reviewable branch. Problem description: The board shell needs a first-class collapsed sidebar mode. Contextual surfaces such as company settings and plugin route sidebars should not replace the global app sidebar; they should collapse the app sidebar to a rail and render their contextual navigation beside it. ## What Changed - Added desktop collapsed/sidebar-peek state to `SidebarContext`, including persisted user pins, route collapse requests, and forced collapse for secondary-sidebar routes. - Replaced the old resizable sidebar pane with `SidebarShell`, which supports a fixed 64px rail, persisted expanded width, keyboard/pointer resizing, and hover/focus peek overlay behavior. - Updated `Sidebar`, sidebar nav items, project/agent sections, badges, and account/company menu presentation for expanded, collapsed, and peeking states. - Added `RequestCollapsedSidebar` and `SecondarySidebar` so routes and plugin `routeSidebar` slots can request contextual sidebar layouts without replacing the primary app sidebar. - Wired company settings and plugin route sidebars into the secondary-pane takeover model. - Added focused Vitest coverage for sidebar state precedence, shell sizing, nav item rail rendering, keyboard shortcuts, layout takeover behavior, and route collapse requests. - Updated plugin authoring docs/spec references for route sidebar behavior. ## Verification Targeted local verification passed: ```sh NODE_ENV=test pnpm run preflight:workspace-links && NODE_ENV=test pnpm exec vitest run ui/src/context/SidebarContext.test.tsx ui/src/components/SidebarShell.test.tsx ui/src/components/Sidebar.test.tsx ui/src/components/Layout.test.tsx ui/src/components/RequestCollapsedSidebar.test.tsx ui/src/components/SidebarNavItem.test.tsx ui/src/components/SidebarAgents.test.tsx ui/src/components/SidebarProjects.test.tsx ui/src/components/KeyboardShortcutsCheatsheet.test.tsx ui/src/hooks/useKeyboardShortcuts.test.tsx ``` Result: 10 test files passed, 88 tests passed. Additional follow-up verification passed after review fixes: ```sh NODE_ENV=test pnpm run preflight:workspace-links && NODE_ENV=test pnpm exec vitest run ui/src/components/Layout.test.tsx ui/src/context/SidebarContext.test.tsx && pnpm --filter /ui typecheck ``` Result: 2 test files passed, 28 tests passed, and UI typecheck passed. Latest PR-head remote checks: Paperclip PR workflow, Snyk, Socket, and Greptile are green; commitperclip `review` is cancelled in its security-gate step after filing a non-blocking neutral `security-review` check. Notes: - A direct run without `NODE_ENV=test` loads React's production build in this workspace, where `act` is unavailable; the command above matches the repo stable runner's test environment. - I did not run Playwright/browser e2e or full workspace build/typecheck in this PR-creation heartbeat. - QA screenshots are attached in https://github.com/paperclipai/paperclip/pull/7824#issuecomment-4661968387 for expanded, collapsed rail, hover peek, and settings secondary-sidebar states. ## Risks - Medium UI layout risk: this changes the board shell and primary sidebar composition across many routes. - Local storage migration risk is low: new collapsed state uses a new key and existing width storage remains scoped to the sidebar width. - Plugin route risk: plugin `routeSidebar` slots now render as secondary panes on desktop, so plugin authors should confirm their route sidebar content fits a 240px contextual pane. - Mobile risk appears low because mobile keeps the drawer model and gates collapsed/peek behavior to desktop. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used OpenAI Codex coding agent based on GPT-5, with local shell/git/GitHub CLI tool use. Exact service-side model identifier and context window were not exposed in this runtime. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
202 lines
6.3 KiB
TypeScript
202 lines
6.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { SidebarShell, SIDEBAR_RAIL_WIDTH } from "./SidebarShell";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
function pointerEvent(type: string, clientX: number) {
|
|
const event = new MouseEvent(type, { bubbles: true, clientX });
|
|
Object.defineProperty(event, "pointerId", { value: 1 });
|
|
return event;
|
|
}
|
|
|
|
describe("SidebarShell", () => {
|
|
let container: HTMLDivElement;
|
|
let root: Root;
|
|
|
|
beforeEach(() => {
|
|
window.localStorage.clear();
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
});
|
|
|
|
afterEach(() => {
|
|
act(() => {
|
|
root.unmount();
|
|
});
|
|
container.remove();
|
|
window.localStorage.clear();
|
|
});
|
|
|
|
// The in-flow spacer that reserves layout width.
|
|
function spacer() {
|
|
return container.firstElementChild as HTMLDivElement;
|
|
}
|
|
|
|
// The absolutely-positioned overlay panel that holds the sidebar content.
|
|
function panel() {
|
|
return spacer().firstElementChild as HTMLDivElement;
|
|
}
|
|
|
|
function handle() {
|
|
return container.querySelector('[role="separator"]') as HTMLDivElement | null;
|
|
}
|
|
|
|
it("uses a persisted width when expanded", () => {
|
|
window.localStorage.setItem("test.sidebar.width", "320");
|
|
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open resizable storageKey="test.sidebar.width">
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
// Both the reserved spacer and the panel match the expanded width; no overlay.
|
|
expect(spacer().style.width).toBe("320px");
|
|
expect(panel().style.width).toBe("320px");
|
|
expect(panel().getAttribute("data-sidebar-overlay")).toBeNull();
|
|
expect(handle()?.getAttribute("aria-valuenow")).toBe("320");
|
|
});
|
|
|
|
it("resizes by dragging and persists the new width", () => {
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open resizable storageKey="test.sidebar.width">
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
const separator = handle();
|
|
expect(separator).not.toBeNull();
|
|
separator!.setPointerCapture = vi.fn();
|
|
|
|
act(() => {
|
|
separator!.dispatchEvent(pointerEvent("pointerdown", 240));
|
|
separator!.dispatchEvent(pointerEvent("pointermove", 320));
|
|
separator!.dispatchEvent(pointerEvent("pointerup", 320));
|
|
});
|
|
|
|
expect(panel().style.width).toBe("320px");
|
|
expect(window.localStorage.getItem("test.sidebar.width")).toBe("320");
|
|
});
|
|
|
|
it("supports keyboard resizing and clamps to the configured bounds", () => {
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open resizable storageKey="test.sidebar.width">
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
const separator = handle();
|
|
act(() => {
|
|
separator?.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true }));
|
|
});
|
|
expect(panel().style.width).toBe("256px");
|
|
expect(window.localStorage.getItem("test.sidebar.width")).toBe("256");
|
|
|
|
act(() => {
|
|
separator?.dispatchEvent(new KeyboardEvent("keydown", { key: "Home", bubbles: true }));
|
|
});
|
|
expect(panel().style.width).toBe("208px");
|
|
|
|
act(() => {
|
|
separator?.dispatchEvent(new KeyboardEvent("keydown", { key: "End", bubbles: true }));
|
|
});
|
|
expect(panel().style.width).toBe("420px");
|
|
});
|
|
|
|
it("can render without a resize handle", () => {
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open resizable={false}>
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
expect(handle()).toBeNull();
|
|
expect(panel().style.width).toBe("240px");
|
|
});
|
|
|
|
it("reserves only the rail width when collapsed and hides the resize handle", () => {
|
|
window.localStorage.setItem("test.sidebar.width", "320");
|
|
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open collapsed resizable storageKey="test.sidebar.width">
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
// Reserved spacer and panel both collapse to the rail; content never reflows
|
|
// beyond the rail, and the rail is not user-resizable.
|
|
expect(spacer().style.width).toBe(`${SIDEBAR_RAIL_WIDTH}px`);
|
|
expect(panel().style.width).toBe(`${SIDEBAR_RAIL_WIDTH}px`);
|
|
expect(panel().getAttribute("data-sidebar-overlay")).toBeNull();
|
|
expect(handle()).toBeNull();
|
|
});
|
|
|
|
it("hides all sidebar width when closed, even if pinned collapsed", () => {
|
|
window.localStorage.setItem("test.sidebar.width", "320");
|
|
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open={false} collapsed resizable storageKey="test.sidebar.width">
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
expect(spacer().style.width).toBe("0px");
|
|
expect(panel().style.width).toBe("0px");
|
|
expect(panel().getAttribute("data-sidebar-overlay")).toBeNull();
|
|
expect(handle()).toBeNull();
|
|
});
|
|
|
|
it("overlays content while peeking without expanding the reserved spacer", () => {
|
|
window.localStorage.setItem("test.sidebar.width", "300");
|
|
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open collapsed peeking storageKey="test.sidebar.width">
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
// The reserved spacer stays at the rail (no page reflow) while the panel
|
|
// grows to the expanded width and gets overlay styling.
|
|
expect(spacer().style.width).toBe(`${SIDEBAR_RAIL_WIDTH}px`);
|
|
expect(panel().style.width).toBe("300px");
|
|
expect(panel().getAttribute("data-sidebar-overlay")).toBe("");
|
|
expect(panel().className).toContain("shadow-lg");
|
|
expect(panel().className).toContain("z-30");
|
|
});
|
|
|
|
it("opens and closes instantly with no width transition (PAP-10676)", () => {
|
|
act(() => {
|
|
root.render(
|
|
<SidebarShell open>
|
|
<div>Sidebar</div>
|
|
</SidebarShell>,
|
|
);
|
|
});
|
|
|
|
// Open/close must be instant: the panel never animates its width, so neither
|
|
// the transition nor its reduced-motion fallback should be present.
|
|
expect(panel().className).not.toContain("transition-[width]");
|
|
expect(panel().className).not.toContain("motion-reduce:transition-none");
|
|
});
|
|
});
|