Files
PaperClipAI/ui/src/components/EntityRow.tsx
T
096060598d Add project pinning to the Coordinator sidebar (#22805)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Operators use projects to organize and review related tasks.
> - The Coordinator sidebar provides quick access to pinned items.
> - Project pins were available from Recents after a project visit.
> - This PR makes each project pinnable directly from More → Projects.
> - Pinned project rows expand in place so operators can open a recent
task from the sidebar.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Project navigation in the Coordinator workspace.

**Subsystem affected**

The board UI, specifically the Projects list and the left sidebar.

**Current behavior**

Users who review work by project must visit a project before they can
pin it from Recents. Project rows use a separate expand control. Hidden
sidebar controls also reserve space that can truncate project and task
names.

**Proposed behavior**

Give each Coordinator project row a pin action. Let users click the
sidebar project row to open or close its recent tasks, and give labels
the full available width while row controls are hidden.

**Reason and benefit**

Users can set up several project shortcuts from one page and reach the
tasks they review regularly from the sidebar.

## What Changed

- Add pin and unpin actions to Coordinator Projects rows using the
existing per-user browser preference.
- Make pinned and recent project rows expand and collapse their tasks.
Show closed and open folder icons for the two states.
- Match nested task spacing to adjacent navigation items and give nested
tasks a small indent.
- Reserve sidebar label space for controls when they are visible. Keep
the project icon and text centered in the Projects list.
- Scope project star and join or leave controls to Classic mode.

## Verification

- Run `pnpm --filter @paperclipai/ui typecheck`.
- Run the focused workspace preference, project query, and pinned
navigation Vitest files.
- Run `tests/e2e/project-pinning.spec.ts` in Chromium to verify pinning,
persistence, label width, expansion, and task navigation.
- In Chromium, open More → Projects and pin a project. Reload and
confirm the shortcut persists. Expand it using the mouse or keyboard,
open a nested task, reorder pins, and unpin from either the list or the
sidebar.
- Check label widths at rest and with hover, keyboard focus, and touch
controls. Check that Classic mode shows the star and membership
controls.

- GitHub Actions passed on `e96959bffe`, including build, typecheck, and
all eight browser shards. Two server shards passed on retry. [CI
run](https://github.com/paperclipai/paperclip/actions/runs/45466386598)
- Greptile gave the same commit 5/5 with no open review threads.
[Review](https://github.com/paperclipai/paperclip/pull/22805#issuecomment-7141648518)

## Risks

- Clicking a project row in the Coordinator sidebar now opens its task
list in place. Users can still open the full project from the Projects
page.
- This UI change reuses the existing browser preference and project task
query. It requires no database migration.

## Model Used

OpenAI Codex with GPT-6.2-Sol. Used local code execution, Chromium, and
GitHub CLI.

## 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 not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run 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 <scott@scotts-mbp-m5-max.local>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-24 11:31:38 -08:00

154 lines
4.7 KiB
TypeScript

import { type ReactNode } from "react";
import { Link } from "@/lib/router";
import { cn } from "../lib/utils";
interface EntityRowProps {
leading?: ReactNode;
identifier?: string;
title: string;
titleAccessory?: ReactNode;
subtitle?: ReactNode;
/**
* Optional metadata columns rendered immediately after the title. When set,
* the title stops flex-growing and a spacer is inserted between `meta` and
* `trailing`, so meta sits next to the name while trailing stays pinned right.
*/
meta?: ReactNode;
metaSpacerClassName?: string;
trailing?: ReactNode;
selected?: boolean;
to?: string;
onClick?: () => void;
className?: string;
titleClassName?: string;
titleTextClassName?: string;
subtitleClassName?: string;
/**
* Make the title (the row's primary identifier) win the flex fight: it keeps a
* usable min-width floor and ellipsizes, while the `meta` cluster is the item
* that shrinks (and can wrap its own children). Without this, a wide `meta`
* cluster starves the title down to zero at narrow widths. Opt-in so existing
* callers keep the "title shrinks first" behavior.
*/
titlePriority?: boolean;
/**
* Optional content rendered on its own full-width line beneath the main row.
* Use this for a chip/action cluster that would otherwise starve the title at
* narrow widths — gate it with `xl:hidden` and keep the inline copy in `meta`
* behind `hidden xl:flex` so wide layouts are unchanged.
*/
secondaryRow?: ReactNode;
/** Override the secondary line's default spacing or indentation. */
secondaryRowClassName?: string;
}
export function EntityRow({
leading,
identifier,
title,
titleAccessory,
subtitle,
meta,
metaSpacerClassName,
trailing,
selected,
to,
onClick,
className,
titleClassName,
titleTextClassName,
subtitleClassName,
titlePriority,
secondaryRow,
secondaryRowClassName,
}: EntityRowProps) {
const isClickable = !!(to || onClick);
const shellClasses = cn(
// When a secondaryRow is present the shell stacks (main line + secondary
// line); otherwise the shell itself is the single flex row.
secondaryRow ? "block" : "flex items-center gap-3",
"px-4 py-2 text-sm border-b border-border last:border-b-0 transition-colors",
isClickable && "cursor-pointer hover:bg-accent/50",
selected && "bg-accent/30",
className
);
const content = (
<>
{leading && <div className="flex items-center gap-2 shrink-0">{leading}</div>}
<div
className={cn(
// `titlePriority` gives the name a floor so it ellipsizes instead of
// collapsing to zero; otherwise the title may shrink to nothing.
titlePriority ? "min-w-(--sz-6rem)" : "min-w-0",
!meta && "flex-1",
titleClassName,
)}
>
<div className="flex items-center gap-2">
{identifier && (
<span className="text-xs text-muted-foreground font-mono shrink-0 relative top-(--sz-1px)">
{identifier}
</span>
)}
<span className={cn(!titleTextClassName && "truncate", titleTextClassName)} title={title}>
{title}
</span>
{titleAccessory}
</div>
{Boolean(subtitle) && (
<p
className={cn(
"text-xs text-muted-foreground mt-0.5 min-h-4",
!subtitleClassName && "truncate",
subtitleClassName,
)}
>
{subtitle}
</p>
)}
</div>
{meta && (
<div
className={cn(
"flex items-center gap-2",
// In title-priority mode the meta cluster yields (shrinks/wraps)
// before the name does; otherwise it holds its width.
titlePriority ? "min-w-0 shrink" : "shrink-0",
)}
>
{meta}
</div>
)}
{meta && <div className={cn("flex-1", metaSpacerClassName)} />}
{trailing && <div className="flex items-center gap-2 shrink-0">{trailing}</div>}
</>
);
// With a secondaryRow, wrap the main line in its own flex row and stack the
// secondary content beneath it (indented to align under the title, past the
// leading capsule). Without it, `content` is rendered directly (unchanged).
const body = secondaryRow ? (
<>
<div className="flex items-center gap-3">{content}</div>
<div className={cn("mt-1 pl-5", secondaryRowClassName)}>{secondaryRow}</div>
</>
) : (
content
);
if (to) {
return (
<Link to={to} className={cn("no-underline text-inherit", shellClasses)} onClick={onClick}>
{body}
</Link>
);
}
return (
<div className={shellClasses} onClick={onClick}>
{body}
</div>
);
}