Files
PaperClipAI/ui/src/components/RoutineSubSidebar.tsx
T
scotttongandClaude Fable 5 53d09d4c34 fix(ui): inbox/task list parity, nesting alignment, hover perf, and routine detail polish (#9317)
## Thinking Path

> - Paperclip's UI is governed by the design system merged in #9134 and
the component convergence in #9240 — one Card, one Badge, one nav row,
one `IssueRow`, a single multiplicative radius ladder.
> - With those primitives in place, the remaining rough edges were
interaction and alignment details on the surfaces people use every day:
the inbox, the task list, the sidebar, and the routine/task detail
pages.
> - Each item here was reported from live use and fixed against a
running instance, then verified by measurement (pixel alignment, frame
timing) rather than by eye alone.
> - The result is that the inbox and task lists now behave as one system
(same hover, keyboard nav, tree-guide, and archive language), list
nesting reads correctly, list hover is smooth, and the routine detail
page scrolls and aligns like the rest of the app.

## Linked Issues or Issue Description

No public GitHub issue exists for this work; describing per the feature
template.

- **Problem**: after the design-system foundation (#9134) and component
convergence (#9240), the inbox/task lists still had interaction and
alignment gaps — hover lag on long lists, keyboard navigation that only
partly matched between the two lists, workspace/parent nesting whose
guides and chevrons didn't line up, an inbox that sat offset from the
task list, and a routine detail page with an odd double-scroll and a
bespoke sub-nav.
- **Proposed behavior**: the inbox and task lists share one interaction
contract (hover, keyboard nav, collapse, archive), list nesting aligns
to the status column with clean chevrons, list hover is CSS-only (no
per-hover re-render), and the routine detail page uses a fixed
header/sub-nav with a single scrolling content region and a sub-nav that
matches the primary nav.

## What Changed

- **List hover performance**: hover is now painted purely by CSS
`:hover` and records the hovered row in a ref, instead of writing
list-selection state on every `mouseenter` (which re-rendered 100–300
non-memoized rows per hover). Keyboard nav reads the ref so it still
continues from the hovered row; the keyboard band clears on the first
real mouse move so hover and keyboard selection never show two bands at
once. The row's `transition-colors` fade was removed so the highlight
snaps (no comet-tail). Measured on a 100-row scrub: worst frame **333 ms
→ 33 ms**, long frames (>50 ms) **12 → 0**, avg **41 → 60 fps**.
- **Inbox ↔ task-list parity**: keyboard navigation works on every inbox
tab (archive/read keys stay scoped to the archivable tab); group headers
and parent tasks collapse/expand with the arrow keys in both lists; the
task list gains the same j/k / arrows / Enter selection model as the
inbox; hover selection bands match; the `g` then `i` go-to-inbox chord
works app-wide.
- **List nesting & alignment**: the workspace group-header chevron lines
up exactly with the task chevrons below it (both lists); the
parent→child connector line drops from under the parent's **status
icon** rather than its chevron and breaks with a 14px gap around a
nested row's own chevron; and inbox rows line up with the task list
(read rows no longer reserve a mark-read column).
- **Inbox archive affordance**: moved from a bare `x` left of the status
icon to an `Archive` icon + label button on the right (before the
timestamp), revealed on row hover; the left slot now carries only the
unread dot; swipe-to-archive is unchanged.
- **Sidebar**: when no agent has a live run, the AGENTS section shows 3
recent agents (was 5) plus "See all agents"; the working-agents view is
unchanged.
- **Routine detail page**: the layout is bounded to the main scroll area
so the header (Run now + automation toggle) and the sub-nav stay fixed
and only the section content scrolls (was a page-level scroll competing
with a `sticky` sub-nav). The sub-nav items adopt the primary nav's
rhythm — row padding/height, inset rounded pill, type scale, and 16px
icons — and its background matches the main nav.
- **Task detail**: dropped the redundant `🔵` prefix the breadcrumb added
for live/in-progress tasks; the status glyph already conveys that state.

## Verification

- `pnpm check:token-gates` → 3/3 CLEAN
- `pnpm typecheck` → green (all packages)
- `cd ui && npx vitest run` → 2255/2255 (assertions updated in lockstep
where behavior changed)
- `pnpm --filter @paperclipai/ui build` → exit 0
- Storybook visual regression: run locally throughout (the
baseline-manifest archive is still unpublished, so CI cannot run this
suite — pre-existing condition from #9134). Every visible delta was
reviewed against a live instance and, where it was intentional (nesting
alignment, routine sub-nav restyle, unread-row shift), the affected
snapshots were re-baselined locally.
- Manual/measured: inbox + task lists (grouped and nested, light +
dark), hover-scrub frame timing, keyboard navigation, and the routine
detail scroll/alignment were exercised on a running instance.

## Risks

- Behavior-and-alignment changes concentrated in `IssueRow` /
`IssuesList` / `Inbox` (the shared task-row surfaces). The riskiest area
— the hover/keyboard-selection model — is covered by unit tests (updated
in lockstep) and was measured and driven live.
- The routine detail scroll change restructures that page's layout
container; verified the page's own scroll stays fixed while only the
section content scrolls.
- The visual suite cannot yet run in CI (unpublished baseline archive —
pre-existing); snapshot coverage is local-only until that lands.

## Model Used

- Claude Fable 5 (`claude-fable-5`, Anthropic) via Claude Code — agentic
coding with tool use (file editing, test execution, Playwright
measurement/screenshot verification); extended thinking enabled.

## 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

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 14:25:48 -07:00

217 lines
6.6 KiB
TypeScript

import { useRef } from "react";
import {
Activity as ActivityIcon,
Circle,
Clock3,
History as HistoryIcon,
KeyRound,
LayoutGrid,
Play,
Send,
SlidersHorizontal,
} from "lucide-react";
import type { LucideIcon } from "lucide-react";
import { Link } from "@/lib/router";
import { cn } from "@/lib/utils";
import {
ROUTINE_SECTION_KEYS,
type RoutineSectionKey,
} from "./routine-sections/context";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
type NavItem = {
key: RoutineSectionKey;
label: string;
icon: LucideIcon;
};
type NavGroup = {
label: string;
items: NavItem[];
};
const NAV_GROUPS: NavGroup[] = [
{
label: "Routine",
items: [
{ key: "overview", label: "Overview", icon: Circle },
{ key: "triggers", label: "Triggers", icon: Clock3 },
{ key: "variables", label: "Variables", icon: LayoutGrid },
{ key: "secrets", label: "Secrets", icon: KeyRound },
{ key: "delivery", label: "Delivery", icon: Send },
],
},
{
label: "Operate",
items: [
{ key: "runs", label: "Runs", icon: Play },
{ key: "activity", label: "Activity", icon: ActivityIcon },
{ key: "history", label: "History", icon: HistoryIcon },
],
},
];
const ALL_ITEMS: NavItem[] = NAV_GROUPS.flatMap((group) => group.items);
export function RoutineSubSidebar({
activeSection,
hrefFor,
isSectionDirty,
hasLiveRun,
onNavigate,
}: {
activeSection: RoutineSectionKey;
hrefFor: (section: RoutineSectionKey) => string;
isSectionDirty: (section: RoutineSectionKey) => boolean;
hasLiveRun: boolean;
onNavigate: (section: RoutineSectionKey) => void;
}) {
const itemRefs = useRef<Array<HTMLAnchorElement | null>>([]);
const focusItem = (index: number) => {
const clamped = (index + ALL_ITEMS.length) % ALL_ITEMS.length;
itemRefs.current[clamped]?.focus();
onNavigate(ALL_ITEMS[clamped].key);
};
const handleKeyDown = (event: React.KeyboardEvent, index: number) => {
switch (event.key) {
case "ArrowDown":
event.preventDefault();
focusItem(index + 1);
break;
case "ArrowUp":
event.preventDefault();
focusItem(index - 1);
break;
case "Home":
event.preventDefault();
focusItem(0);
break;
case "End":
event.preventDefault();
focusItem(ALL_ITEMS.length - 1);
break;
default:
break;
}
};
let flatIndex = -1;
return (
<nav
aria-label="Routine sections"
className="hidden h-full w-52 shrink-0 flex-col gap-4 overflow-y-auto border-r border-border bg-background px-3 py-4 md:flex"
>
{NAV_GROUPS.map((group) => (
<div key={group.label} className="flex flex-col gap-0.5">
<p className="mx-2 px-2 pb-1 text-(length:--text-nano) font-medium uppercase tracking-widest font-mono text-muted-foreground/60">
{group.label}
</p>
{group.items.map((item) => {
flatIndex += 1;
const index = flatIndex;
const isActive = item.key === activeSection;
const Icon = item.icon;
const dirty = isSectionDirty(item.key);
const showLiveDot = item.key === "runs" && hasLiveRun;
return (
<Link
key={item.key}
ref={(node) => {
itemRefs.current[index] = node;
}}
to={hrefFor(item.key)}
replace
role="tab"
aria-current={isActive ? "page" : undefined}
tabIndex={isActive ? 0 : -1}
onKeyDown={(event) => handleKeyDown(event, index)}
onClick={() => onNavigate(item.key)}
className={cn(
// Match the primary nav rows (SidebarNavItem): same rhythm,
// inset pill, type scale, and icon size.
"flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium transition-colors motion-safe:duration-150",
isActive
? "bg-accent text-foreground"
: "text-foreground/80 hover:bg-accent/50 hover:text-foreground",
)}
>
<Icon className="h-4 w-4 shrink-0" />
<span className="truncate">{item.label}</span>
{showLiveDot ? (
<span className="ml-auto h-1.5 w-1.5 shrink-0 rounded-full bg-blue-500 motion-safe:animate-pulse" />
) : dirty ? (
<span
aria-label="Unsaved changes"
className="ml-auto h-1.5 w-1.5 shrink-0 rounded-full bg-amber-500 ring-2 ring-background"
/>
) : null}
</Link>
);
})}
</div>
))}
</nav>
);
}
/** Mobile section picker — collapses the sub-sidebar into a grouped `<Select>`. */
export function RoutineSectionPicker({
activeSection,
onNavigate,
isSectionDirty,
}: {
activeSection: RoutineSectionKey;
onNavigate: (section: RoutineSectionKey) => void;
isSectionDirty: (section: RoutineSectionKey) => boolean;
}) {
return (
<div className="sticky top-0 z-10 border-b border-border bg-background px-4 py-2 md:hidden">
<Select
value={activeSection}
onValueChange={(value) => {
if (ROUTINE_SECTION_KEYS.includes(value as RoutineSectionKey)) {
onNavigate(value as RoutineSectionKey);
}
}}
>
<SelectTrigger className="h-11 w-full" aria-label="Routine section">
<SelectValue />
</SelectTrigger>
<SelectContent>
{NAV_GROUPS.map((group) => (
<SelectGroup key={group.label}>
<SelectLabel className="uppercase tracking-(--tracking-eyebrow) text-(length:--text-micro)">
{group.label}
</SelectLabel>
{group.items.map((item) => (
<SelectItem key={item.key} value={item.key} className="h-11">
<span className="flex items-center gap-2">
<item.icon className="h-3.5 w-3.5" />
{item.label}
{isSectionDirty(item.key) ? (
<span className="h-1.5 w-1.5 rounded-full bg-amber-500" />
) : null}
</span>
</SelectItem>
))}
</SelectGroup>
))}
</SelectContent>
</Select>
</div>
);
}
export { ALL_ITEMS as ROUTINE_NAV_ITEMS };