mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 11:40:00 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agent Chat lets people discuss work and review the plans and documents it produces. > - A document link in Chat promises to open the sidebar. It currently moves the reader to Tasks. > - Readers need to see the document and the conversation together, even when the window is narrow. > - This pull request opens the document in Chat, frees space for reading, and gives readers a link to the source task. > - Readers can review the saved revision in context and open the task when they need its details. ## Linked Issues or Issue Description Refs #11226 for the document sidebar that this change builds on. **What happened?** Opening a saved plan from Agent Chat changed the route to Tasks. The document could show the same title twice. At narrow desktop widths, the chat list left too little space for the conversation beside the document. A task opened by UUID could still show a Chat header. **Expected behavior** The sidebar shows the saved revision beside the current conversation. It shows a matching title once. The chat list collapses when space is tight. The source link opens the standard task header with status, name, and ID. **Steps to reproduce** 1. Open an Agent Chat with a saved plan and select its sidebar link. 2. Use a narrow desktop window and inspect the conversation and plan. 3. Open the task that owns the plan and inspect the breadcrumb. **Paperclip version or commit** Reproduced on source commit `8285a81280`. **Deployment mode** Local trusted development instance with synthetic data. ## What Changed - Open sidebar document links on the current Chat route. Keep the requested revision and document owner, including links inside another task’s preview. Provide an **Open source task** link. - Show one title when the document title matches the opening Markdown heading. - Collapse the desktop chat list when an artifact tab would leave less than 420 px for the conversation. Keep **Browse chats** in the header with access to saved chat history. Restore the list when there is room. - Use the task breadcrumb on task URLs, with the short UUID for a conversation-backed task without a number. ## Verification - Ran 618 focused Vitest tests across 18 UI files on the published revision `2ff6c9e931`. All passed. - Ran `pnpm --filter @paperclipai/ui typecheck`. It passed. - Checked the synthetic demo in Chromium. Opened the plan in Chat, checked the title, resized the window, and followed **Open source task** to check its breadcrumb. Also verified a link inside a preview owned by another task. - Reproduced the chat navigation failure from the CI trace. The same Playwright test passed locally after limiting collapse to artifact tabs. - GitHub CI passed on `2ff6c9e931`, including build, typecheck, and all browser shards. The remaining jobs passed on a retry after runner shutdowns and a server handover test failure. The handover suite also passed locally (19 tests). [GitHub CI](https://github.com/paperclipai/paperclip/actions/runs/44423540581/attempts/2) - `pnpm verify` selected broader CI coverage because `doc/PRODUCT.md` changed. The full local suite was not run. ## Risks The chat list changes visibility when an artifact tab is active and the available width crosses the threshold. The list stays mounted to keep its search text. Document tabs use the existing read API and check the owning company. This change adds no database migration or API contract change. ## Model Used OpenAI Codex (GPT-6), with repository tools, shell execution, and Chromium. ## 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 linked existing issues or described the issue in-PR following the relevant issue template - [x] I have used public GitHub references for linked work - [x] My branch name describes the change and contains no internal Paperclip ticket ID - [x] I have run focused tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] 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: Scott Tong <1504818+scotttong@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
272 lines
11 KiB
TypeScript
272 lines
11 KiB
TypeScript
import { Link } from "@/lib/router";
|
|
import { Menu, PanelRightClose, PanelRightOpen } from "lucide-react";
|
|
import { useBreadcrumbs } from "../context/BreadcrumbContext";
|
|
import { useSidebar } from "../context/SidebarContext";
|
|
import { useCompany } from "../context/CompanyContext";
|
|
import { usePanel } from "../context/PanelContext";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Breadcrumb,
|
|
BreadcrumbItem,
|
|
BreadcrumbLink,
|
|
BreadcrumbList,
|
|
BreadcrumbPage,
|
|
BreadcrumbSeparator,
|
|
} from "@/components/ui/breadcrumb";
|
|
import { Fragment, useMemo, type ReactNode } from "react";
|
|
import { PluginSlotOutlet, usePluginSlots } from "@/plugins/slots";
|
|
import { PluginLauncherOutlet, usePluginLaunchers } from "@/plugins/launchers";
|
|
import { cn } from "../lib/utils";
|
|
import { useCoordinatorPresentation } from "./coordinator/CoordinatorPresentation";
|
|
|
|
type GlobalToolbarContext = { companyId: string | null; companyPrefix: string | null };
|
|
|
|
const MAX_TASK_TITLE_CHARACTERS = 48;
|
|
function taskTitleLabel(title: string) {
|
|
const characters = Array.from(title);
|
|
return characters.length > MAX_TASK_TITLE_CHARACTERS
|
|
? `${characters.slice(0, MAX_TASK_TITLE_CHARACTERS - 1).join("")}…`
|
|
: title;
|
|
}
|
|
|
|
/** Task identifier rendered in gray monospace beside its breadcrumb label. */
|
|
function CrumbIdentifier({ identifier }: { identifier?: string }) {
|
|
if (!identifier) return null;
|
|
return (
|
|
<span data-slot="task-title-identifier" className="shrink-0 font-mono text-(length:--text-micro) text-muted-foreground">
|
|
{identifier}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function GlobalToolbar({
|
|
context,
|
|
pageToolbar,
|
|
}: {
|
|
context: GlobalToolbarContext;
|
|
pageToolbar?: ReactNode;
|
|
}) {
|
|
const { slots } = usePluginSlots({ slotTypes: ["globalToolbarButton"], companyId: context.companyId });
|
|
const { launchers } = usePluginLaunchers({ placementZones: ["globalToolbarButton"], companyId: context.companyId, enabled: !!context.companyId });
|
|
return (
|
|
<div className="ml-auto flex shrink-0 items-center gap-1 pl-2 empty:hidden">
|
|
{pageToolbar}
|
|
{slots.length > 0 ? (
|
|
<PluginSlotOutlet slotTypes={["globalToolbarButton"]} context={context} className="flex items-center gap-1" />
|
|
) : null}
|
|
{launchers.length > 0 ? (
|
|
<PluginLauncherOutlet placementZones={["globalToolbarButton"]} context={context} className="flex items-center gap-1" />
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function BreadcrumbBar({ taskDetailLayout = false, showPropertiesToggle = taskDetailLayout, toolbarAction }: {
|
|
taskDetailLayout?: boolean;
|
|
showPropertiesToggle?: boolean;
|
|
toolbarAction?: ReactNode;
|
|
}) {
|
|
const coordinatorEnabled = useCoordinatorPresentation();
|
|
const {
|
|
breadcrumbs,
|
|
breadcrumbToolbar,
|
|
breadcrumbPanelControl,
|
|
mobileToolbar,
|
|
} = useBreadcrumbs();
|
|
const { toggleSidebar, isMobile } = useSidebar();
|
|
const { panelVisible, togglePanelVisible } = usePanel();
|
|
const { selectedCompanyId, selectedCompany } = useCompany();
|
|
const taskPanelOpen = breadcrumbPanelControl?.open ?? panelVisible;
|
|
const toggleTaskPanel = breadcrumbPanelControl?.onToggle ?? togglePanelVisible;
|
|
const propertiesToggle = showPropertiesToggle ? (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="ml-5 size-9 shrink-0 text-muted-foreground"
|
|
onClick={toggleTaskPanel}
|
|
aria-label={taskPanelOpen ? "Hide properties" : "Show properties"}
|
|
title={taskPanelOpen ? "Hide properties" : "Show properties"}
|
|
>
|
|
{taskPanelOpen ? <PanelRightClose className="h-4 w-4" /> : <PanelRightOpen className="h-4 w-4" />}
|
|
</Button>
|
|
) : null;
|
|
|
|
const globalToolbarSlotContext = useMemo(
|
|
() => ({
|
|
companyId: selectedCompanyId ?? null,
|
|
companyPrefix: selectedCompany?.issuePrefix ?? null,
|
|
}),
|
|
[selectedCompanyId, selectedCompany?.issuePrefix],
|
|
);
|
|
|
|
const globalToolbarSlots = (
|
|
<GlobalToolbar
|
|
context={globalToolbarSlotContext}
|
|
pageToolbar={isMobile ? null : <>{breadcrumbToolbar}{toolbarAction}</>}
|
|
/>
|
|
);
|
|
|
|
if (isMobile && mobileToolbar) {
|
|
return (
|
|
<div className="h-(--sz-60px) shrink-0 flex items-center border-b border-border px-2">
|
|
{mobileToolbar}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (breadcrumbs.length === 0) {
|
|
return (
|
|
<div className="h-(--sz-60px) shrink-0 flex items-center justify-end border-b border-border px-4 md:px-6">
|
|
{globalToolbarSlots}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const menuButton = isMobile && (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="mr-2 shrink-0"
|
|
onClick={toggleSidebar}
|
|
aria-label="Open sidebar"
|
|
>
|
|
<Menu className="h-5 w-5" />
|
|
</Button>
|
|
);
|
|
|
|
const currentCrumb = breadcrumbs[breadcrumbs.length - 1];
|
|
const isTaskTrail = Boolean(currentCrumb.identifier);
|
|
const visibleBreadcrumbs = isMobile && isTaskTrail && breadcrumbs.length > 1 ? breadcrumbs.slice(1) : breadcrumbs;
|
|
if (isMobile && isTaskTrail && visibleBreadcrumbs.length === 1) {
|
|
return (
|
|
<div className="h-(--sz-60px) shrink-0 flex items-center border-b border-border px-4">
|
|
{menuButton}
|
|
<h1 className="flex min-w-0 flex-1 items-baseline gap-1.5 text-sm">
|
|
{currentCrumb.leading ? (
|
|
<span className="flex shrink-0 items-center self-center">{currentCrumb.leading}</span>
|
|
) : null}
|
|
<span className="min-w-0 flex-1 truncate" title={currentCrumb.label} aria-label={currentCrumb.label}>{taskTitleLabel(currentCrumb.label)}</span>
|
|
<CrumbIdentifier identifier={currentCrumb.identifier} />
|
|
</h1>
|
|
{globalToolbarSlots}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const breadcrumbTrail = (
|
|
<div className="min-w-0 overflow-hidden flex-1">
|
|
<Breadcrumb className="min-w-0 overflow-hidden">
|
|
<BreadcrumbList className="flex-nowrap">
|
|
{visibleBreadcrumbs.map((crumb, i) => {
|
|
const isLast = i === visibleBreadcrumbs.length - 1;
|
|
const isTask = isTaskTrail && (isMobile || i > 0 || visibleBreadcrumbs.length === 1);
|
|
const pinnedIdentifier = (taskDetailLayout || isMobile) && isLast && Boolean(crumb.identifier);
|
|
const label = isTask ? taskTitleLabel(crumb.label) : crumb.label;
|
|
const accessibleLabel = [crumb.label, crumb.identifier].filter(Boolean).join(" ");
|
|
return (
|
|
<Fragment key={i}>
|
|
{i > 0 && <BreadcrumbSeparator />}
|
|
<BreadcrumbItem className={cn(isLast || isTask ? "min-w-0" : "shrink-0", isTask && !isLast && "max-w-(--breadcrumb-parent-max-width)", pinnedIdentifier && "flex-1")}>
|
|
{crumb.control ?? (isLast || !crumb.href ? (
|
|
crumb.leading || crumb.identifier ? (
|
|
<BreadcrumbPage aria-current={isLast ? "page" : undefined} aria-label={accessibleLabel} className={cn("flex min-w-0 gap-1.5", crumb.trailing ? "items-center" : "items-baseline", (isTask || pinnedIdentifier) && "flex-1")}>
|
|
{crumb.leading && (
|
|
<span className="flex shrink-0 items-center self-center">{crumb.leading}</span>
|
|
)}
|
|
{!taskDetailLayout && !isMobile ? <CrumbIdentifier identifier={crumb.identifier} /> : null}
|
|
<span title={crumb.label} className={cn("min-w-0 truncate", pinnedIdentifier && "flex-1")}>{label}</span>
|
|
{(taskDetailLayout || isMobile) && isLast ? <CrumbIdentifier identifier={crumb.identifier} /> : null}
|
|
</BreadcrumbPage>
|
|
) : (
|
|
<BreadcrumbPage aria-current={isLast ? "page" : undefined} aria-label={accessibleLabel} title={crumb.label} className="truncate">{label}</BreadcrumbPage>
|
|
)
|
|
) : (
|
|
<BreadcrumbLink asChild>
|
|
{crumb.leading || crumb.identifier ? (
|
|
<Link
|
|
to={crumb.href} onClick={crumb.onClick}
|
|
title={crumb.label} aria-label={accessibleLabel}
|
|
className={cn(
|
|
"flex min-w-0 items-baseline gap-1.5",
|
|
isTask && "flex-1",
|
|
i === 0 && !isTask && "font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",
|
|
)}
|
|
>
|
|
{crumb.leading && (
|
|
<span className="flex shrink-0 items-center self-center">{crumb.leading}</span>
|
|
)}
|
|
{!isMobile ? <CrumbIdentifier identifier={crumb.identifier} /> : null}
|
|
<span className="min-w-0 truncate">{label}</span>
|
|
</Link>
|
|
) : (
|
|
<Link
|
|
to={crumb.href} onClick={crumb.onClick}
|
|
title={crumb.label} aria-label={accessibleLabel}
|
|
className={cn(
|
|
"min-w-0 truncate",
|
|
i === 0 && !isTask && "font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",
|
|
)}
|
|
>
|
|
{label}
|
|
</Link>
|
|
)}
|
|
</BreadcrumbLink>
|
|
))}
|
|
{!crumb.control && crumb.trailing && <span className="flex shrink-0 items-center">{crumb.trailing}</span>}
|
|
</BreadcrumbItem>
|
|
</Fragment>
|
|
);
|
|
})}
|
|
</BreadcrumbList>
|
|
</Breadcrumb>
|
|
</div>
|
|
);
|
|
|
|
// Task details use the same breadcrumb typography even with one item.
|
|
// Other single-crumb pages keep their existing page-title presentation.
|
|
if (breadcrumbs.length === 1 && !taskDetailLayout) {
|
|
return (
|
|
<div className="h-(--sz-60px) shrink-0 flex items-center border-b border-border px-4 md:px-6">
|
|
{menuButton}
|
|
<div className="min-w-0 overflow-hidden flex-1">
|
|
{breadcrumbs[0].control ? (
|
|
<h1 className="min-w-0 text-sm font-semibold uppercase tracking-wider">{breadcrumbs[0].control}</h1>
|
|
) : breadcrumbs[0].leading || breadcrumbs[0].identifier ? (
|
|
<h1 className="flex items-baseline gap-1.5 text-sm font-semibold uppercase tracking-wider">
|
|
{breadcrumbs[0].leading && (
|
|
<span className="flex shrink-0 items-center self-center">{breadcrumbs[0].leading}</span>
|
|
)}
|
|
<CrumbIdentifier identifier={breadcrumbs[0].identifier} />
|
|
<span className="truncate" title={breadcrumbs[0].label}>{isTaskTrail ? taskTitleLabel(breadcrumbs[0].label) : breadcrumbs[0].label}</span>
|
|
</h1>
|
|
) : (
|
|
<h1 className="text-sm font-semibold uppercase tracking-wider truncate">
|
|
{breadcrumbs[0].label}
|
|
</h1>
|
|
)}
|
|
</div>
|
|
{coordinatorEnabled && !breadcrumbs[0].control && breadcrumbs[0].trailing ? (
|
|
<span className="ml-2 flex shrink-0 items-center">{breadcrumbs[0].trailing}</span>
|
|
) : null}
|
|
{globalToolbarSlots}
|
|
{propertiesToggle}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Multiple breadcrumbs = breadcrumb trail
|
|
return (
|
|
<div
|
|
className={cn(
|
|
"relative h-(--sz-60px) shrink-0 flex items-center border-b border-border",
|
|
"px-4 md:px-6",
|
|
)}
|
|
>
|
|
{menuButton}
|
|
{breadcrumbTrail}
|
|
{globalToolbarSlots}
|
|
{isMobile && isTaskTrail ? null : propertiesToggle}
|
|
</div>
|
|
);
|
|
}
|