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>
115 lines
3.8 KiB
TypeScript
115 lines
3.8 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 { SidebarProvider, useSidebar } from "../context/SidebarContext";
|
|
import { RequestCollapsedSidebar } from "./RequestCollapsedSidebar";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
const COLLAPSED_STORAGE_KEY = "paperclip.sidebar.collapsed";
|
|
|
|
let capturedValue: ReturnType<typeof useSidebar> | null = null;
|
|
|
|
function Capture() {
|
|
capturedValue = useSidebar();
|
|
return null;
|
|
}
|
|
|
|
// A tiny stand-in for "a route that brings its own sidebar". When `onRoute`
|
|
// is true it mounts <RequestCollapsedSidebar/>; flipping it to false models
|
|
// navigating away to a route that does not request a collapse.
|
|
function Harness({ onRoute }: { onRoute: boolean }) {
|
|
return (
|
|
<SidebarProvider>
|
|
<Capture />
|
|
{onRoute ? <RequestCollapsedSidebar /> : null}
|
|
</SidebarProvider>
|
|
);
|
|
}
|
|
|
|
function render(onRoute: boolean): { root: Root; host: HTMLDivElement } {
|
|
const host = document.createElement("div");
|
|
document.body.appendChild(host);
|
|
const root = createRoot(host);
|
|
act(() => root.render(<Harness onRoute={onRoute} />));
|
|
return { root, host };
|
|
}
|
|
|
|
describe("RequestCollapsedSidebar", () => {
|
|
let active: { root: Root; host: HTMLDivElement } | null = null;
|
|
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
capturedValue = null;
|
|
Object.defineProperty(window, "innerWidth", {
|
|
configurable: true,
|
|
writable: true,
|
|
value: 1280, // desktop: collapsed/peek are meaningful
|
|
});
|
|
Object.defineProperty(window, "matchMedia", {
|
|
configurable: true,
|
|
writable: true,
|
|
value: vi.fn().mockImplementation((query: string) => ({
|
|
// Desktop, hover-capable pointer.
|
|
matches: query.includes("(hover: hover)"),
|
|
media: query,
|
|
onchange: null,
|
|
addEventListener: vi.fn(),
|
|
removeEventListener: vi.fn(),
|
|
addListener: vi.fn(),
|
|
removeListener: vi.fn(),
|
|
dispatchEvent: vi.fn(),
|
|
})),
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (active) {
|
|
act(() => active!.root.unmount());
|
|
active.host.remove();
|
|
active = null;
|
|
}
|
|
localStorage.clear();
|
|
});
|
|
|
|
it("requests collapsed while mounted when there is no user pin", () => {
|
|
active = render(true);
|
|
expect(capturedValue?.routeRequestsCollapsed).toBe(true);
|
|
expect(capturedValue?.collapsed).toBe(true);
|
|
});
|
|
|
|
it("lets an explicit user pin override the route request", () => {
|
|
active = render(true);
|
|
expect(capturedValue?.collapsed).toBe(true);
|
|
|
|
// User explicitly pins expanded — must win over the route's request.
|
|
act(() => capturedValue?.setCollapsed(false));
|
|
expect(capturedValue?.routeRequestsCollapsed).toBe(true);
|
|
expect(capturedValue?.collapsed).toBe(false);
|
|
});
|
|
|
|
it("clears the request on unmount, restoring the global default", () => {
|
|
active = render(true);
|
|
expect(capturedValue?.collapsed).toBe(true);
|
|
|
|
// Navigate away: the route (and its <RequestCollapsedSidebar/>) unmounts.
|
|
act(() => active!.root.render(<Harness onRoute={false} />));
|
|
expect(capturedValue?.routeRequestsCollapsed).toBe(false);
|
|
expect(capturedValue?.collapsed).toBe(false);
|
|
});
|
|
|
|
it("keeps a user pin after navigating away (pin persists, request cleared)", () => {
|
|
active = render(true);
|
|
act(() => capturedValue?.setCollapsed(true));
|
|
expect(localStorage.getItem(COLLAPSED_STORAGE_KEY)).toBe("1");
|
|
|
|
act(() => active!.root.render(<Harness onRoute={false} />));
|
|
// Route request gone, but the explicit collapsed pin still applies.
|
|
expect(capturedValue?.routeRequestsCollapsed).toBe(false);
|
|
expect(capturedValue?.collapsed).toBe(true);
|
|
});
|
|
});
|