Files
PaperClipAI/ui/src/components/CoordinatorAgentSwitcher.tsx
T
DottaandPaperclip 44a9a043b8 fix(ui): make the full chat agent selector clickable (#18708)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Chat gives each person a standing conversation with an agent.
> - The Coordinator chat header shows an agent avatar, name, and caret.
> - Only the caret opened the agent picker. The avatar and name were
separate text.
> - This pull request puts all three parts in one button that opens the
existing picker.
> - The benefit is a larger click target with one keyboard focus stop.

## Linked Issues or Issue Description

**What happened?**

In Coordinator Chat, the caret opened the agent picker. The agent avatar
and name did not open it.

**Expected behavior**

The avatar, name, and caret must form one control. Each part must open
the same picker.

**Steps to reproduce**

1. Enable the personal Coordinator workspace and open an agent chat.
2. Click the agent avatar or name in the header.
3. Compare the result with a click on the caret.

## What Changed

- Put the avatar, name, and caret inside one button in
`CoordinatorAgentSwitcher`. Keep its current-page marker for screen
readers.
- Add an optional trigger to `AgentChatPicker`. The shared dialog
handles keyboard access and focus return.
- Add an optional breadcrumb control slot. The chat owns its button,
while the text label still sets the document title.
- Add regression cases for both header layouts on desktop and mobile.
Check all three click areas, Escape, focus return, and selection of
another agent.
- Add a Coordinator chat Storybook case with production components and
fixture API data. Update the feature recipe.

## Verification

- Passed 235 focused tests for `BreadcrumbBar`, `AgentChatPicker`,
`BreadcrumbContext`, and `IssueDetail`. The header cases also check the
current-page marker.
- Passed UI typecheck and UI production build.
- Passed token gates, map checks, and Storybook catalog checks. All 30
map and catalog regression tests passed.
- The new header cases failed before the change and passed after it.
- Full local typecheck could not finish because this workspace has no
`cargo` command.
- Full local build and the first UI typecheck attempt reached the 8 GB
workspace memory limit. The separate UI build and typecheck passed. The
full local test run was stopped to free memory for browser verification;
it has no complete verdict.
- Passed 18 browser checks in Chromium across desktop light, mobile
light, and desktop dark. Each case checks avatar/name/caret clicks,
Enter, Space, Escape/focus return, and selection of QAChecker. No page
render errors occurred.
- Captured six screenshots of the header and picker across these
viewports and themes. Review images remain outside the repository.
- Browser review first found stale fixture responses for recent
comments, decision receipts, chat handoffs, and ordinary-task email
state. Correct API response shapes removed those fixture render failures
before the successful review.

## Risks

- Low risk. The shared breadcrumb renderer has a new optional control
slot. Callers that omit it retain their existing rendering.
- Chat selection uses the existing picker and route. No database or API
contract changes are required.
- The Storybook API is simulated. It does not prove provider execution
or server persistence.

## Model Used

OpenAI Codex, GPT-6. The runtime did not expose the exact deployed model
ID or context window. The agent used code editing, terminal checks, and
browser automation.

## 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
#` 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
- [ ] All Paperclip CI gates are green
- [ ] 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: Paperclip <noreply@paperclip.ing>
2026-11-03 07:20:20 -06:00

37 lines
1.6 KiB
TypeScript

import { useState } from "react";
import { ChevronDown } from "lucide-react";
import type { Agent } from "@paperclipai/shared";
import { AgentChatPicker } from "./AgentChatPicker";
import { AgentAvatar } from "./AgentAvatar";
import { Button } from "./ui/button";
import { useAgentChatNavigation } from "@/hooks/useAgentChatNavigation";
import { useNavigate } from "@/lib/router";
import { agentRouteRef } from "@/lib/utils";
/** Switching opens the existing conversation or its unsaved draft view.
* The production chat controller persists it only when the user sends. */
export function CoordinatorAgentSwitcher({ agent }: { agent: Agent }) {
const [open, setOpen] = useState(false);
const { agents, chats } = useAgentChatNavigation();
const navigate = useNavigate();
return (
<AgentChatPicker
open={open}
onOpenChange={setOpen}
trigger={
<Button variant="ghost" size="sm" className="min-w-0 max-w-full gap-1.5 px-1.5 text-foreground" aria-label={`Switch agent. Currently ${agent.name}`} aria-current="page" title="Switch agent">
<AgentAvatar agent={agent} size={24} />
<span data-agent-name className="truncate">{agent.name}</span>
<ChevronDown className="size-4" />
</Button>
}
agents={(agents.data ?? []).filter(item => item.status !== "terminated")}
loading={agents.isPending}
error={agents.error}
onRetry={() => { void agents.refetch(); }}
existingChatAgentIds={(chats.data ?? []).flatMap(chat => chat.conversationAgentId ? [chat.conversationAgentId] : [])}
onSelect={next => { navigate(`/chats/${encodeURIComponent(agentRouteRef(next))}`); }}
/>
);
}