mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 00:05:49 +02:00
## 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>
385 lines
13 KiB
TypeScript
385 lines
13 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act } from "react";
|
|
import type { ReactNode } from "react";
|
|
import { createRoot } from "react-dom/client";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { SidebarSection } from "./SidebarSection";
|
|
import { SidebarNavExpandedProvider } from "./SidebarNavItem";
|
|
import { Plus } from "lucide-react";
|
|
|
|
const sidebarState = vi.hoisted(() => ({
|
|
isMobile: false,
|
|
collapsed: false,
|
|
peeking: false,
|
|
}));
|
|
|
|
vi.mock("@/lib/router", () => ({
|
|
Link: ({ children, to, ...props }: { children: ReactNode; to: string }) => (
|
|
<a href={to} {...props}>{children}</a>
|
|
),
|
|
NavLink: ({ children, to, ...props }: { children: ReactNode; to: string }) => (
|
|
<a href={to} {...props}>{children}</a>
|
|
),
|
|
}));
|
|
|
|
vi.mock("../context/SidebarContext", () => ({
|
|
useSidebar: () => sidebarState,
|
|
}));
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
if (!globalThis.PointerEvent) {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(globalThis as any).PointerEvent = MouseEvent;
|
|
}
|
|
|
|
async function flushReact() {
|
|
await act(async () => {
|
|
await Promise.resolve();
|
|
await new Promise((resolve) => window.setTimeout(resolve, 0));
|
|
});
|
|
}
|
|
|
|
async function openSectionMenu(container: HTMLElement) {
|
|
const trigger = container.querySelector('button[aria-label="Projects section actions"]');
|
|
expect(trigger).not.toBeNull();
|
|
|
|
await act(async () => {
|
|
trigger?.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0 }));
|
|
trigger?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
await flushReact();
|
|
}
|
|
|
|
describe("SidebarSection", () => {
|
|
let container: HTMLDivElement;
|
|
let root: ReturnType<typeof createRoot> | null;
|
|
|
|
beforeEach(() => {
|
|
sidebarState.isMobile = false;
|
|
sidebarState.collapsed = false;
|
|
sidebarState.peeking = false;
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = null;
|
|
});
|
|
|
|
afterEach(async () => {
|
|
const currentRoot = root;
|
|
if (currentRoot) {
|
|
await act(async () => {
|
|
currentRoot.unmount();
|
|
});
|
|
}
|
|
container.remove();
|
|
document.body.innerHTML = "";
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("keeps static and collapsible section labels on the same text column", async () => {
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<div>
|
|
<SidebarSection label="Work">
|
|
<a href="/issues">Issues</a>
|
|
</SidebarSection>
|
|
<SidebarSection label="Projects" collapsible={{ open: true, onOpenChange: vi.fn() }}>
|
|
<a href="/projects">Projects</a>
|
|
</SidebarSection>
|
|
</div>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
const workLabel = Array.from(container.querySelectorAll("span"))
|
|
.find((element) => element.textContent === "Work");
|
|
const projectsLabel = Array.from(container.querySelectorAll("span"))
|
|
.find((element) => element.textContent === "Projects");
|
|
|
|
expect(workLabel?.parentElement?.textContent).toBe("Work");
|
|
expect(projectsLabel?.parentElement?.textContent).toBe("Projects");
|
|
expect(projectsLabel?.parentElement?.querySelector("svg")).toBeNull();
|
|
expect(container.querySelector('button[aria-label="Collapse Projects"] svg')).toBeTruthy();
|
|
});
|
|
|
|
it("keeps collapse on the caret and opens the menu from the heading", async () => {
|
|
const onOpenChange = vi.fn();
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarSection
|
|
label="Projects"
|
|
collapsible={{ open: true, onOpenChange }}
|
|
menu={{
|
|
ariaLabel: "Projects section actions",
|
|
actions: [{ type: "item", label: "Browse projects", href: "/projects" }],
|
|
}}
|
|
>
|
|
<a href="/projects">Projects</a>
|
|
</SidebarSection>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
await openSectionMenu(container);
|
|
|
|
expect(onOpenChange).not.toHaveBeenCalled();
|
|
expect(document.body.textContent).toContain("Browse projects");
|
|
|
|
const caret = container.querySelector('button[aria-label="Collapse Projects"]');
|
|
await act(async () => {
|
|
caret?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
|
|
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
});
|
|
|
|
it("does not apply hover background classes to static section labels", async () => {
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarSection label="Work">
|
|
<a href="/issues">Issues</a>
|
|
</SidebarSection>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
const workLabel = Array.from(container.querySelectorAll("span"))
|
|
.find((element) => element.textContent === "Work");
|
|
const staticLabelControl = workLabel?.parentElement;
|
|
|
|
expect(staticLabelControl?.tagName).toBe("DIV");
|
|
expect(staticLabelControl?.getAttribute("class")).not.toContain("hover:bg-accent/50");
|
|
expect(staticLabelControl?.getAttribute("class")).not.toContain("focus-visible:bg-accent/50");
|
|
});
|
|
|
|
it("keeps section labels visible inside an expanded contextual pane", async () => {
|
|
sidebarState.collapsed = true;
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarNavExpandedProvider>
|
|
<SidebarSection label="Settings">
|
|
<a href="/settings">General</a>
|
|
</SidebarSection>
|
|
</SidebarNavExpandedProvider>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
const settingsLabel = Array.from(container.querySelectorAll("span"))
|
|
.find((element) => element.textContent === "Settings");
|
|
|
|
expect(settingsLabel).toBeTruthy();
|
|
expect(settingsLabel?.getAttribute("class")).toContain("uppercase");
|
|
expect(container.querySelector(".bg-border\\/60")).toBeNull();
|
|
});
|
|
|
|
it("keeps the header action outside the label menu hit area", async () => {
|
|
const onAction = vi.fn();
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarSection
|
|
label="Projects"
|
|
menu={{
|
|
ariaLabel: "Projects section actions",
|
|
actions: [{ type: "item", label: "Browse projects", href: "/projects" }],
|
|
}}
|
|
headerAction={{
|
|
ariaLabel: "New project",
|
|
icon: Plus,
|
|
onClick: onAction,
|
|
}}
|
|
>
|
|
<a href="/projects">Projects</a>
|
|
</SidebarSection>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
const sectionMenuTrigger = container.querySelector('button[aria-label="Projects section actions"]');
|
|
const newProjectButton = container.querySelector('button[aria-label="New project"]');
|
|
|
|
expect(sectionMenuTrigger?.textContent).toContain("Projects");
|
|
expect(sectionMenuTrigger?.querySelector("svg")).toBeNull();
|
|
expect(sectionMenuTrigger?.getAttribute("class")).toContain("hover:bg-accent/50");
|
|
expect(newProjectButton).toBeTruthy();
|
|
|
|
await act(async () => {
|
|
newProjectButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
await flushReact();
|
|
|
|
expect(onAction).toHaveBeenCalledTimes(1);
|
|
expect(document.body.textContent).not.toContain("Browse projects");
|
|
|
|
await openSectionMenu(container);
|
|
expect(document.body.textContent).toContain("Browse projects");
|
|
});
|
|
|
|
it("renders configured menu actions and radio choices", async () => {
|
|
const onAction = vi.fn();
|
|
const onRadioValueChange = vi.fn();
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarSection
|
|
label="Projects"
|
|
menu={{
|
|
ariaLabel: "Projects section actions",
|
|
actions: [
|
|
{ type: "item", label: "New project", onSelect: onAction },
|
|
{ type: "item", label: "Browse projects", href: "/projects" },
|
|
{ type: "separator" },
|
|
],
|
|
radioChoices: [
|
|
{ value: "top", label: "Top" },
|
|
{ value: "alphabetical", label: "Alphabetical" },
|
|
],
|
|
radioValue: "top",
|
|
onRadioValueChange,
|
|
}}
|
|
>
|
|
<a href="/projects">Projects</a>
|
|
</SidebarSection>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
await openSectionMenu(container);
|
|
|
|
const newProjectItem = Array.from(document.body.querySelectorAll('[data-slot="dropdown-menu-item"]'))
|
|
.find((element) => element.textContent?.includes("New project"));
|
|
expect(newProjectItem).toBeTruthy();
|
|
const browseLink = Array.from(document.body.querySelectorAll("a"))
|
|
.find((element) => element.textContent?.includes("Browse projects"));
|
|
expect(browseLink?.getAttribute("href")).toBe("/projects");
|
|
|
|
const alphabeticalItem = Array.from(document.body.querySelectorAll('[data-slot="dropdown-menu-radio-item"]'))
|
|
.find((element) => element.textContent?.includes("Alphabetical"));
|
|
expect(alphabeticalItem).toBeTruthy();
|
|
|
|
await act(async () => {
|
|
alphabeticalItem?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
expect(onRadioValueChange).toHaveBeenCalledWith("alphabetical");
|
|
|
|
await openSectionMenu(container);
|
|
const reopenedNewProjectItem = Array.from(document.body.querySelectorAll('[data-slot="dropdown-menu-item"]'))
|
|
.find((element) => element.textContent?.includes("New project"));
|
|
|
|
await act(async () => {
|
|
reopenedNewProjectItem?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
expect(onAction).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("replaces the header with a divider and drops the caret in the collapsed rail", async () => {
|
|
sidebarState.collapsed = true;
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarSection
|
|
label="Projects"
|
|
collapsible={{ open: true, onOpenChange: vi.fn() }}
|
|
menu={{
|
|
ariaLabel: "Projects section actions",
|
|
actions: [{ type: "item", label: "Browse projects", href: "/projects" }],
|
|
}}
|
|
>
|
|
<a href="/projects">Projects</a>
|
|
</SidebarSection>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
// The clipped header text is gone; the caret/menu trigger is not rendered.
|
|
expect(container.querySelector('button[aria-label="Collapse Projects"]')).toBeNull();
|
|
expect(container.querySelector('button[aria-label="Projects section actions"]')).toBeNull();
|
|
|
|
// The label is preserved in the a11y tree (sr-only) and the items still render.
|
|
const label = Array.from(container.querySelectorAll("span"))
|
|
.find((element) => element.textContent === "Projects");
|
|
expect(label?.className).toContain("sr-only");
|
|
expect(container.querySelector('a[href="/projects"]')).toBeTruthy();
|
|
});
|
|
|
|
it("restores the full header while peeking even when collapsed", async () => {
|
|
sidebarState.collapsed = true;
|
|
sidebarState.peeking = true;
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarSection label="Projects" collapsible={{ open: true, onOpenChange: vi.fn() }}>
|
|
<a href="/projects">Projects</a>
|
|
</SidebarSection>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
const label = Array.from(container.querySelectorAll("span"))
|
|
.find((element) => element.textContent === "Projects");
|
|
expect(label?.className).not.toContain("sr-only");
|
|
expect(container.querySelector('button[aria-label="Collapse Projects"]')).toBeTruthy();
|
|
});
|
|
|
|
it("keeps section header controls visible on mobile", async () => {
|
|
sidebarState.isMobile = true;
|
|
const currentRoot = createRoot(container);
|
|
root = currentRoot;
|
|
|
|
await act(async () => {
|
|
currentRoot.render(
|
|
<SidebarSection
|
|
label="Projects"
|
|
collapsible={{ open: false, onOpenChange: vi.fn() }}
|
|
menu={{
|
|
ariaLabel: "Projects section actions",
|
|
actions: [{ type: "item", label: "New project" }],
|
|
}}
|
|
headerAction={{
|
|
ariaLabel: "New project",
|
|
icon: Plus,
|
|
onClick: vi.fn(),
|
|
}}
|
|
>
|
|
<a href="/projects">Projects</a>
|
|
</SidebarSection>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
|
|
const projectsLabel = Array.from(container.querySelectorAll("span"))
|
|
.find((element) => element.textContent === "Projects");
|
|
const caret = container.querySelector('button[aria-label="Expand Projects"] svg');
|
|
const action = container.querySelector('button[aria-label="New project"]');
|
|
|
|
expect(caret?.getAttribute("class")).toContain("opacity-100");
|
|
expect(caret?.getAttribute("class")).not.toContain("opacity-0");
|
|
expect(projectsLabel?.parentElement?.textContent).toBe("Projects");
|
|
expect(action?.getAttribute("class")).toContain("opacity-100");
|
|
expect(action?.getAttribute("class")).not.toContain("opacity-0");
|
|
});
|
|
});
|