diff --git a/site/src/pages/AgentsPage/components/ChatActionsMenuItems.tsx b/site/src/pages/AgentsPage/components/ChatActionsMenuItems.tsx index 624ba7ba1c8..9d5fc7ff1ff 100644 --- a/site/src/pages/AgentsPage/components/ChatActionsMenuItems.tsx +++ b/site/src/pages/AgentsPage/components/ChatActionsMenuItems.tsx @@ -55,6 +55,7 @@ import { clearPersistedRightPanelState } from "../utils/rightPanelTabStorage"; import { clearPersistedSidebarTabId } from "../utils/sidebarTabStorage"; import { ArchiveAndDeleteWorkspaceDialog } from "./ArchiveAndDeleteWorkspaceDialog"; import { getParentChatID } from "./ChatConversation/chatHelpers"; +import { ChatPRMenuItems } from "./ChatsSidebar/tree/ChatPRMenuItems"; // Backend chatstate permits archive only from W, E0, and E1. Unknown status // stays fail-open so the server conflict response remains the backstop. @@ -108,8 +109,8 @@ export const canManageChat = ( type ChatActionsMenuItemsProps = { readonly chat: TypesGen.Chat; /** - * See {@link canManageChat}. When false, only the subagents toggle and the - * copy actions render. + * See {@link canManageChat}. When false, only the subagents toggle, the + * copy actions and the PR links render. */ readonly canManage: boolean; readonly hasWorkspace: boolean; @@ -129,6 +130,8 @@ type ChatActionsMenuItemsProps = { readonly onArchiveAndDeleteWorkspace: () => void; /** When omitted, the "Rename chat" item is hidden. */ readonly onOpenRenameDialog?: () => void; + /** When omitted or empty, no PR links render. */ + readonly prStatuses?: readonly TypesGen.ChatDiffStatus[]; readonly Item: ItemComponent; readonly Separator: SeparatorComponent; readonly Sub: SubComponent; @@ -316,6 +319,7 @@ const ChatActionsMenuItems: React.FC = ({ onUnarchiveAgent, onArchiveAndDeleteWorkspace, onOpenRenameDialog, + prStatuses, Item, Separator, Sub, @@ -412,6 +416,18 @@ const ChatActionsMenuItems: React.FC = ({ ) : ( copyItems ); + const prLinks = prStatuses && prStatuses.length > 0 && ( + <> + + + + ); if (!canManage) { return ( @@ -419,6 +435,7 @@ const ChatActionsMenuItems: React.FC = ({ {subagentToggle} {hasActionsAboveCopy && } {copyActions} + {prLinks} ); } @@ -465,6 +482,7 @@ const ChatActionsMenuItems: React.FC = ({ )} {hasActionsAboveCopy && } {copyActions} + {prLinks} {showArchiveActions && ( <> diff --git a/site/src/pages/AgentsPage/components/ChatDiffStats.tsx b/site/src/pages/AgentsPage/components/ChatDiffStats.tsx index f911e0db345..8189537be81 100644 --- a/site/src/pages/AgentsPage/components/ChatDiffStats.tsx +++ b/site/src/pages/AgentsPage/components/ChatDiffStats.tsx @@ -1,13 +1,17 @@ import { cn } from "cn"; -import type { Chat } from "#/api/typesGenerated"; -import { getChatDisplayConfig } from "./ChatsSidebar/tree/statusConfig"; +import type { Chat, ChatDiffStatus } from "#/api/typesGenerated"; +import { ChatNodePRIcon } from "./ChatsSidebar/tree/ChatNodePRIcon"; +import { + getChatDisplayConfig, + getPRIconConfig, +} from "./ChatsSidebar/tree/statusConfig"; type ChatDiffStatsProps = { readonly chat: Chat; }; export const ChatPRStateIcon: React.FC = ({ chat }) => { - const { prIcon } = getChatDisplayConfig(chat); + const prIcon = getPRIconConfig(chat.diff_status); if (!prIcon) { return null; } @@ -21,13 +25,12 @@ export const ChatPRStateIcon: React.FC = ({ chat }) => { ); }; -const ChatLineStats: React.FC = ({ chat }) => { - const { diffStatus } = getChatDisplayConfig(chat); - const changedFiles = diffStatus?.changed_files ?? 0; - const additions = diffStatus?.additions ?? 0; - const deletions = diffStatus?.deletions ?? 0; +const ChatLineStats: React.FC<{ readonly status: ChatDiffStatus }> = ({ + status, +}) => { + const { changed_files: changedFiles, additions, deletions } = status; const hasLineStats = additions > 0 || deletions > 0 || changedFiles > 0; - if (!diffStatus?.url || !hasLineStats) { + if (!status.url || !hasLineStats) { return null; } const filesChangedLabel = `${changedFiles} ${ @@ -45,9 +48,17 @@ const ChatLineStats: React.FC = ({ chat }) => { ); }; -export const ChatDiffStats: React.FC = ({ chat }) => ( - <> - - - -); +export const ChatDiffStats: React.FC = ({ chat }) => { + const { prStatuses } = getChatDisplayConfig(chat); + + // The sole PR's line stats can differ from the primary row's, + // which may be a newer branch-only ref with zeroed counts. + const solePR = prStatuses.length === 1 ? prStatuses[0] : undefined; + + return ( + <> + + {solePR && } + + ); +}; diff --git a/site/src/pages/AgentsPage/components/ChatTopBar.tsx b/site/src/pages/AgentsPage/components/ChatTopBar.tsx index dcce4976301..56ef6dbb90a 100644 --- a/site/src/pages/AgentsPage/components/ChatTopBar.tsx +++ b/site/src/pages/AgentsPage/components/ChatTopBar.tsx @@ -35,6 +35,7 @@ import { Button } from "#/components/Button/Button"; import { DropdownMenu, DropdownMenuContent, + DropdownMenuItem, DropdownMenuTrigger, } from "#/components/DropdownMenu/DropdownMenu"; import { Popover, PopoverTrigger } from "#/components/Popover/Popover"; @@ -346,7 +347,7 @@ export const ChatTopBar: React.FC = ({ - + ) : ( diff --git a/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.stories.tsx b/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.stories.tsx index 2c8ff0b3947..b6d696856e7 100644 --- a/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.stories.tsx +++ b/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.stories.tsx @@ -16,7 +16,7 @@ import { chatProjectsKey } from "#/api/queries/chatProjects"; import { userChatProviderConfigsKey } from "#/api/queries/chats"; import type * as TypesGen from "#/api/typesGenerated"; import type { Chat } from "#/api/typesGenerated"; -import { MockChat } from "#/testHelpers/chatEntities"; +import { MockChat, MockChatDiffStatus } from "#/testHelpers/chatEntities"; import { MockChatProject, MockUserOwner, @@ -1552,61 +1552,65 @@ export const WithDiffStats: Story = { id: "diff-both", title: "Agent with additions and deletions", updated_at: recentTimestamp, - diff_status: { - chat_id: "diff-both", - url: "https://github.com/coder/coder/pull/1", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 42, - deletions: 7, - changed_files: 5, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "diff-both", + pr_number: 1, + url: "https://github.com/coder/coder/pull/1", + additions: 42, + deletions: 7, + changed_files: 5, + }, + ], }), buildChat({ id: "diff-add-only", title: "Agent with additions only", updated_at: recentTimestamp, - diff_status: { - chat_id: "diff-add-only", - url: "https://github.com/coder/coder/pull/2", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 120, - deletions: 0, - changed_files: 3, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "diff-add-only", + pr_number: 2, + url: "https://github.com/coder/coder/pull/2", + additions: 120, + deletions: 0, + changed_files: 3, + }, + ], }), buildChat({ id: "diff-del-only", title: "Agent with deletions only", updated_at: recentTimestamp, - diff_status: { - chat_id: "diff-del-only", - url: "https://github.com/coder/coder/pull/3", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 0, - deletions: 35, - changed_files: 2, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "diff-del-only", + pr_number: 3, + url: "https://github.com/coder/coder/pull/3", + additions: 0, + deletions: 35, + changed_files: 2, + }, + ], }), buildChat({ id: "diff-none", title: "Agent with no diff changes", updated_at: recentTimestamp, - diff_status: { - chat_id: "diff-none", - url: "https://github.com/coder/coder/pull/4", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 0, - deletions: 0, - changed_files: 0, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "diff-none", + pr_number: 4, + url: "https://github.com/coder/coder/pull/4", + additions: 0, + deletions: 0, + changed_files: 0, + }, + ], }), ], }, @@ -1628,46 +1632,49 @@ export const WithDiffStatsLight: Story = { id: "diff-both-light", title: "Agent with additions and deletions", updated_at: recentTimestamp, - diff_status: { - chat_id: "diff-both-light", - url: "https://github.com/coder/coder/pull/1", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 42, - deletions: 7, - changed_files: 5, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "diff-both-light", + pr_number: 1, + url: "https://github.com/coder/coder/pull/1", + additions: 42, + deletions: 7, + changed_files: 5, + }, + ], }), buildChat({ id: "diff-add-only-light", title: "Agent with additions only", updated_at: recentTimestamp, - diff_status: { - chat_id: "diff-add-only-light", - url: "https://github.com/coder/coder/pull/2", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 120, - deletions: 0, - changed_files: 3, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "diff-add-only-light", + pr_number: 2, + url: "https://github.com/coder/coder/pull/2", + additions: 120, + deletions: 0, + changed_files: 3, + }, + ], }), buildChat({ id: "diff-del-only-light", title: "Agent with deletions only", updated_at: recentTimestamp, - diff_status: { - chat_id: "diff-del-only-light", - url: "https://github.com/coder/coder/pull/3", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 0, - deletions: 35, - changed_files: 2, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "diff-del-only-light", + pr_number: 3, + url: "https://github.com/coder/coder/pull/3", + additions: 0, + deletions: 35, + changed_files: 2, + }, + ], }), ], }, @@ -1686,80 +1693,123 @@ export const WithPRStateIcons: Story = { id: "pr-open", title: "Open pull request", updated_at: recentTimestamp, - diff_status: { - chat_id: "pr-open", - url: "https://github.com/coder/coder/pull/100", - pull_request_state: "open", - pull_request_title: "feat: add new feature", - pull_request_draft: false, - changes_requested: false, - additions: 50, - deletions: 10, - changed_files: 4, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "pr-open", + pr_number: 100, + url: "https://github.com/coder/coder/pull/100", + pull_request_title: "feat: add new feature", + additions: 50, + deletions: 10, + changed_files: 4, + }, + ], }), buildChat({ id: "pr-draft", title: "Draft pull request", updated_at: recentTimestamp, - diff_status: { - chat_id: "pr-draft", - url: "https://github.com/coder/coder/pull/101", - pull_request_state: "open", - pull_request_title: "wip: draft changes", - pull_request_draft: true, - changes_requested: false, - additions: 20, - deletions: 5, - changed_files: 2, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "pr-draft", + pr_number: 101, + url: "https://github.com/coder/coder/pull/101", + pull_request_title: "wip: draft changes", + pull_request_draft: true, + additions: 20, + deletions: 5, + changed_files: 2, + }, + ], }), buildChat({ id: "pr-merged", title: "Merged pull request", updated_at: recentTimestamp, - diff_status: { - chat_id: "pr-merged", - url: "https://github.com/coder/coder/pull/102", - pull_request_state: "merged", - pull_request_title: "feat: completed feature", - pull_request_draft: false, - changes_requested: false, - additions: 200, - deletions: 80, - changed_files: 12, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "pr-merged", + pr_number: 102, + url: "https://github.com/coder/coder/pull/102", + pull_request_state: "merged", + pull_request_title: "feat: completed feature", + additions: 200, + deletions: 80, + changed_files: 12, + }, + ], }), buildChat({ id: "pr-closed", title: "Closed pull request", updated_at: recentTimestamp, - diff_status: { - chat_id: "pr-closed", - url: "https://github.com/coder/coder/pull/103", - pull_request_state: "closed", - pull_request_title: "fix: abandoned approach", - pull_request_draft: false, - changes_requested: false, - additions: 15, - deletions: 3, - changed_files: 1, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "pr-closed", + pr_number: 103, + url: "https://github.com/coder/coder/pull/103", + pull_request_state: "closed", + pull_request_title: "fix: abandoned approach", + additions: 15, + deletions: 3, + changed_files: 1, + }, + ], }), buildChat({ id: "pr-no-state", title: "No PR state (branch only)", updated_at: recentTimestamp, - diff_status: { - chat_id: "pr-no-state", - url: "https://github.com/coder/coder/tree/my-branch", - pull_request_title: "", - pull_request_draft: false, - changes_requested: false, - additions: 10, - deletions: 2, - changed_files: 1, - }, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "pr-no-state", + git_branch: "my-branch", + url: "https://github.com/coder/coder/tree/my-branch", + pr_number: undefined, + pull_request_state: undefined, + pull_request_title: "", + additions: 10, + deletions: 2, + changed_files: 1, + }, + ], + }), + // A newer branch-only push becomes the primary, but the + // sole PR still pairs its icon with its own line stats. + buildChat({ + id: "pr-with-newer-branch", + title: "PR with a newer branch push", + updated_at: recentTimestamp, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "pr-with-newer-branch", + git_branch: "feat/newer-branch", + url: "https://github.com/coder/coder/tree/feat/newer-branch", + pr_number: undefined, + pull_request_state: undefined, + pull_request_title: "", + additions: 0, + deletions: 0, + changed_files: 0, + }, + { + ...MockChatDiffStatus, + chat_id: "pr-with-newer-branch", + git_branch: "feat/older-pr", + pr_number: 104, + url: "https://github.com/coder/coder/pull/104", + pull_request_title: "feat: sole PR with newer branch", + additions: 33, + deletions: 4, + changed_files: 2, + }, + ], }), ], }, @@ -1771,6 +1821,146 @@ export const WithPRStateIcons: Story = { }, }; +export const WithMultiplePRs: Story = { + args: { + chats: [ + buildChat({ + id: "multi-pr", + title: "Agent with three pull requests", + updated_at: recentTimestamp, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "multi-pr", + git_branch: "feat/one", + pr_number: 201, + url: "https://github.com/coder/coder/pull/201", + pull_request_title: "feat: add login page", + additions: 50, + deletions: 10, + changed_files: 4, + }, + { + ...MockChatDiffStatus, + chat_id: "multi-pr", + git_branch: "feat/two", + pr_number: 202, + url: "https://github.com/coder/coder/pull/202", + pull_request_title: "fix: correct the login redirect", + pull_request_draft: true, + additions: 20, + deletions: 5, + changed_files: 2, + }, + { + ...MockChatDiffStatus, + chat_id: "multi-pr", + git_branch: "feat/three", + pr_number: 203, + url: "https://github.com/coder/coder/pull/203", + pull_request_state: "merged", + pull_request_title: "feat: add the login tests", + additions: 200, + deletions: 80, + changed_files: 12, + }, + ], + }), + ], + }, + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + await userEvent.click( + canvas.getByLabelText("Open actions for Agent with three pull requests"), + ); + // The menus portal to the body, outside the story canvas. + const body = within(document.body); + await userEvent.click(await body.findByRole("menuitem", { name: "3 PRs" })); + await body.findByRole("menuitem", { name: /PR #201/ }); + }, + parameters: { + reactRouter: reactRouterParameters({ + location: { path: "/agents" }, + routing: agentsRouting, + }), + }, +}; + +// Enough PRs to show the submenu's height limit. +export const WithManyPRs: Story = { + args: { + chats: [ + buildChat({ + id: "many-prs", + title: "Agent with fifteen pull requests", + updated_at: recentTimestamp, + diff_statuses: Array.from({ length: 15 }, (_, index) => ({ + ...MockChatDiffStatus, + chat_id: "many-prs", + git_branch: `refactor/agents-${index + 1}`, + url: `https://github.com/coder/coder/pull/${29901 + index}`, + pr_number: 29901 + index, + pull_request_title: `refactor(site): split the agents page into smaller parts, step ${index + 1}`, + })), + }), + ], + }, + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + await userEvent.click( + canvas.getByLabelText( + "Open actions for Agent with fifteen pull requests", + ), + ); + const body = within(document.body); + await userEvent.click( + await body.findByRole("menuitem", { name: "15 PRs" }), + ); + await body.findByRole("menuitem", { name: /PR #29901/ }); + }, + parameters: { + reactRouter: reactRouterParameters({ + location: { path: "/agents" }, + routing: agentsRouting, + }), + }, +}; + +export const WithOnePRMenuOpen: Story = { + args: { + chats: [ + buildChat({ + id: "one-pr-menu", + title: "Agent with one pull request", + updated_at: recentTimestamp, + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "one-pr-menu", + pr_number: 301, + url: "https://github.com/coder/coder/pull/301", + pull_request_title: + "fix(site/src/pages/AgentsPage): keep the session alive when the workspace restarts", + }, + ], + }), + ], + }, + parameters: { + reactRouter: reactRouterParameters({ + location: { path: "/agents" }, + routing: agentsRouting, + }), + }, + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + await userEvent.click( + canvas.getByLabelText("Open actions for Agent with one pull request"), + ); + await within(document.body).findByRole("menuitem", { name: /PR #301/ }); + }, +}; + export const ActiveChatKebabPersistent: Story = { args: { chats: [ diff --git a/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.test.tsx b/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.test.tsx index e343c72ed3a..133ad8cab1d 100644 --- a/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.test.tsx +++ b/site/src/pages/AgentsPage/components/ChatsSidebar/ChatsSidebar.test.tsx @@ -18,7 +18,7 @@ import type { Chat } from "#/api/typesGenerated"; import { TooltipProvider } from "#/components/Tooltip/Tooltip"; import { ThemeOverride } from "#/contexts/ThemeProvider"; import { DashboardContext } from "#/modules/dashboard/DashboardProvider"; -import { MockChat } from "#/testHelpers/chatEntities"; +import { MockChat, MockChatDiffStatus } from "#/testHelpers/chatEntities"; import { MockChatModel } from "#/testHelpers/chatModels"; import { MockAppearanceConfig, @@ -1425,6 +1425,192 @@ describe("ChatsSidebar load-more behavior", () => { }); }); +describe("ChatsSidebar pull requests", () => { + const mockMultiPRChat = buildChat({ + id: "multi-pr", + title: "Multiple pull requests", + diff_statuses: [ + { + ...MockChatDiffStatus, + chat_id: "multi-pr", + git_branch: "feat/one", + url: "https://github.com/coder/coder/pull/1", + pr_number: 1, + pull_request_state: "open", + pull_request_title: "feat: add login page", + }, + { + ...MockChatDiffStatus, + chat_id: "multi-pr", + git_branch: "feat/two", + url: "https://github.com/coder/coder/pull/2", + pr_number: 2, + pull_request_state: "merged", + pull_request_title: "feat: add login tests", + }, + ], + }); + + it("announces the pull request state when the chat tracks one pull request", () => { + render( + + + , + ); + + expect( + screen.getByRole("img", { name: /pull request/i }), + ).toHaveAccessibleName("Pull request open"); + }); + + it("announces the tracked pull request count when the chat tracks several", () => { + render( + + + , + ); + + // The count and the glyph are one named image, so the link + // does not announce the count twice. + expect( + screen.getByRole("img", { name: /pull request/i }), + ).toHaveAccessibleName("2 pull requests"); + const link = screen.getByRole("link", { + name: /multiple pull requests/i, + }); + expect(link).toHaveAccessibleName( + /Multiple pull requests.*2 pull requests/, + ); + expect(link).not.toHaveAccessibleName(/2 pull requests.*2 pull requests/); + }); + + it("links every pull request from the actions menu of a multi-PR chat", async () => { + const user = userEvent.setup(); + + render( + + + , + ); + + await user.click( + screen.getByRole("button", { + name: "Open actions for Multiple pull requests", + }), + ); + await user.click(await screen.findByRole("menuitem", { name: "2 PRs" })); + + const links = await screen.findAllByRole("menuitem", { name: /PR #/ }); + expect(links.map((link) => link.getAttribute("href"))).toEqual([ + "https://github.com/coder/coder/pull/1", + "https://github.com/coder/coder/pull/2", + ]); + expect(links[1]).toHaveAccessibleName(/Pull request merged/); + }); + + it("leaves pull requests without a URL out of the actions menu", async () => { + const user = userEvent.setup(); + + render( + + + , + ); + + await user.click( + screen.getByRole("button", { + name: "Open actions for Unlinked pull request", + }), + ); + + // One linkable PR is left, so the menu links it directly. + expect( + await screen.findByRole("menuitem", { name: /PR #1/ }), + ).toHaveAttribute("href", "https://github.com/coder/coder/pull/1"); + }); + + it("links the pull request for viewers of a shared chat", async () => { + const user = userEvent.setup(); + + render( + + + , + ); + + await user.click( + screen.getByRole("button", { + name: "Open actions for Shared pull request", + }), + ); + + expect( + await screen.findByRole("menuitem", { name: /PR #7/ }), + ).toHaveAttribute("href", "https://github.com/coder/coder/pull/7"); + }); +}); + describe("ChatsSidebar subtitles", () => { const modelConfigs: TypesGen.ChatModel[] = [ { diff --git a/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchDialog.stories.tsx b/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchDialog.stories.tsx index 547e4866e36..66043ff000c 100644 --- a/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchDialog.stories.tsx +++ b/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchDialog.stories.tsx @@ -29,6 +29,16 @@ const mockChat: Chat = { updated_at: "2026-05-20T07:30:00.000Z", has_unread: true, diff_status: mockDiffStatus, + diff_statuses: [mockDiffStatus], +}; + +const mockChat2DiffStatus: NonNullable = { + ...mockDiffStatus, + chat_id: "chat-2", + pull_request_title: "Fix flaky story", + additions: 48, + deletions: 12, + changed_files: 3, }; const mockChats: Chat[] = [ @@ -42,16 +52,14 @@ const mockChats: Chat[] = [ created_at: "2026-05-20T05:00:00.000Z", updated_at: "2026-05-20T08:45:00.000Z", has_unread: false, - diff_status: { - ...mockDiffStatus, - chat_id: "chat-2", - pull_request_title: "Fix flaky story", - additions: 48, - deletions: 12, - changed_files: 3, - }, + diff_status: mockChat2DiffStatus, + diff_statuses: [mockChat2DiffStatus], }, ]; +const mockOverflowDiffStatus: NonNullable = { + ...mockDiffStatus, + chat_id: "chat-long-1", +}; const overflowMockChats: Chat[] = [ { ...MockChat, @@ -64,10 +72,8 @@ const overflowMockChats: Chat[] = [ created_at: "2026-05-20T05:00:00.000Z", updated_at: "2026-05-20T09:30:00.000Z", has_unread: false, - diff_status: { - ...mockDiffStatus, - chat_id: "chat-long-1", - }, + diff_status: mockOverflowDiffStatus, + diff_statuses: [mockOverflowDiffStatus], }, ]; const cappedMockChats: Chat[] = Array.from( diff --git a/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchResults.tsx b/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchResults.tsx index e060be55a6f..a21e437b3f3 100644 --- a/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchResults.tsx +++ b/site/src/pages/AgentsPage/components/ChatsSidebar/dialogs/ChatSearchResults.tsx @@ -8,6 +8,7 @@ import { ScrollArea } from "#/components/ScrollArea/ScrollArea"; import { Skeleton } from "#/components/Skeleton/Skeleton"; import { Spinner } from "#/components/Spinner/Spinner"; import { shortRelativeTime } from "#/utils/time"; +import { ChatNodePRIcon } from "../tree/ChatNodePRIcon"; import { getChatDisplayConfig } from "../tree/statusConfig"; type ChatSearchResultsProps = { @@ -256,15 +257,17 @@ const ChatSearchResultRow: React.FC = ({ icon: StatusIcon, className: statusClassName, label: statusLabel, - prIcon, - diffStatus, + prStatuses, } = getChatDisplayConfig(chat); - const PRIcon = prIcon?.icon; - const additions = diffStatus?.additions ?? 0; - const deletions = diffStatus?.deletions ?? 0; - const changedFiles = diffStatus?.changed_files ?? 0; + // Line stats only make sense for one PR; several PRs have no + // single set of counts, and the icon shows the count instead. + const solePR = prStatuses.length === 1 ? prStatuses[0] : undefined; + + const additions = solePR?.additions ?? 0; + const deletions = solePR?.deletions ?? 0; + const changedFiles = solePR?.changed_files ?? 0; const hasLineStats = - Boolean(diffStatus?.url) && + Boolean(solePR?.url) && (additions > 0 || deletions > 0 || changedFiles > 0); const subtitle = chat.last_turn_summary?.trim() || "No summary available"; @@ -298,13 +301,7 @@ const ChatSearchResultRow: React.FC = ({ {chat.title}
- {PRIcon && prIcon && ( - - )} + {hasLineStats && ( +{additions} diff --git a/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatNodePRIcon.tsx b/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatNodePRIcon.tsx new file mode 100644 index 00000000000..077f1eb8d5d --- /dev/null +++ b/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatNodePRIcon.tsx @@ -0,0 +1,50 @@ +import { cn } from "cn"; +import { GitPullRequestArrowIcon } from "lucide-react"; +import type { ChatDiffStatus } from "#/api/typesGenerated"; +import { getPRIconConfig } from "./statusConfig"; + +type ChatNodePRIconProps = { + readonly prStatuses: ChatDiffStatus[]; +}; + +export const ChatNodePRIcon: React.FC = ({ + prStatuses, +}) => { + // Several PRs share the count glyph: picking one state would + // misrepresent the rest. + if (prStatuses.length === 0) { + return null; + } + if (prStatuses.length === 1) { + const soleConfig = getPRIconConfig(prStatuses[0]); + if (!soleConfig) { + return null; + } + const SoleIcon = soleConfig.icon; + return ( + + ); + } + + // One name for the whole glyph; the count and the icon carry it + // visually only. + return ( + + + + ); +}; diff --git a/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatPRMenuItems.tsx b/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatPRMenuItems.tsx new file mode 100644 index 00000000000..1f56b03a5d5 --- /dev/null +++ b/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatPRMenuItems.tsx @@ -0,0 +1,51 @@ +import { GitPullRequestIcon } from "lucide-react"; +import type { ChatDiffStatus } from "#/api/typesGenerated"; +import type { + ContextMenuItem, + ContextMenuSub, + ContextMenuSubContent, + ContextMenuSubTrigger, +} from "#/components/ContextMenu/ContextMenu"; +import type { + DropdownMenuItem, + DropdownMenuSub, + DropdownMenuSubContent, + DropdownMenuSubTrigger, +} from "#/components/DropdownMenu/DropdownMenu"; +import { PRMenuLinks, prMenuContentClassName } from "../../PRMenuLinks"; + +type ChatPRMenuItemsProps = { + readonly prStatuses: readonly ChatDiffStatus[]; + readonly Item: typeof DropdownMenuItem | typeof ContextMenuItem; + readonly Sub: typeof DropdownMenuSub | typeof ContextMenuSub; + readonly SubTrigger: + | typeof DropdownMenuSubTrigger + | typeof ContextMenuSubTrigger; + readonly SubContent: + | typeof DropdownMenuSubContent + | typeof ContextMenuSubContent; +}; + +export const ChatPRMenuItems: React.FC = ({ + prStatuses, + Item, + Sub, + SubTrigger, + SubContent, +}) => { + const links = ; + + if (prStatuses.length === 1) { + return links; + } + + return ( + + + + {prStatuses.length} PRs + + {links} + + ); +}; diff --git a/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatTreeNode.tsx b/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatTreeNode.tsx index a84b8b0c9f3..8f16a97ea4c 100644 --- a/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatTreeNode.tsx +++ b/site/src/pages/AgentsPage/components/ChatsSidebar/tree/ChatTreeNode.tsx @@ -133,6 +133,7 @@ export const ChatTreeNode: React.FC = ({ icon: StatusIcon, className: statusClassName, label: statusLabel, + prStatuses, } = getChatDisplayConfig(chat); const workspaceId = chat.workspace_id; const queryClient = useQueryClient(); @@ -233,6 +234,7 @@ export const ChatTreeNode: React.FC = ({ onOpenRenameDialog: onOpenRenameDialog ? () => onOpenRenameDialog(chat) : undefined, + prStatuses: prStatuses.filter((status) => status.url), }; return ( @@ -240,7 +242,7 @@ export const ChatTreeNode: React.FC = ({
= ({ {!isArchivingThisChat && (