diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 76ad543630fb2..a1109354cae4c 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -176,7 +176,7 @@ import { selectThreadPreviewMiniPlayer, usePreviewMiniPlayerStore, } from "../previewMiniPlayerStore"; -import { threadPullRequestPanelTarget } from "./pullRequest/pullRequestDetail.logic"; +import { threadPullRequestPanelTargets } from "./pullRequest/pullRequestDetail.logic"; import { LinkPullRequestDialogHost } from "./pullRequest/LinkPullRequestDialog"; import { GuestPendingMessages } from "./chat/GuestShareControls"; import { useDeviceState } from "~/state/device"; @@ -2339,14 +2339,14 @@ export default function ChatView(props: ChatViewProps) { if (activeThreadReferenceCopyTarget === null) return; void copyThreadReference(activeThreadReferenceCopyTarget); }; - const pullRequestPanelTarget = activeThread - ? threadPullRequestPanelTarget({ + const pullRequestPanelTargets = activeThread + ? threadPullRequestPanelTargets({ projectId: activeThread.projectId, pullRequests: visiblePullRequests, linkedPullRequest: linkedThreadPullRequest, branchPullRequest: activeThreadShell?.branchPullRequest ?? activeThread.branchPullRequest, }) - : null; + : []; const { activateRightPanelSurfaceStable, addDeviceSurfaceStable, @@ -2374,7 +2374,7 @@ export default function ChatView(props: ChatViewProps) { activePreviewState, deviceState, deviceStateLoaded, - pullRequestPanelTarget, + pullRequestPanelTargets, threadPanelPresentation, isServerThread, embedded, @@ -2394,7 +2394,7 @@ export default function ChatView(props: ChatViewProps) { onDiffPanelOpen, closeRightPanelSurface, }); - const pullRequestSurfaceAvailable = supportsPullRequests && pullRequestPanelTarget !== null; + const pullRequestSurfaceAvailable = supportsPullRequests && pullRequestPanelTargets.length > 0; const { acknowledgeActiveThreadWoke, activeBranchMismatchKey, diff --git a/apps/web/src/components/RightPanelTabs.tsx b/apps/web/src/components/RightPanelTabs.tsx index 596bdee96ad1f..712113f12379c 100644 --- a/apps/web/src/components/RightPanelTabs.tsx +++ b/apps/web/src/components/RightPanelTabs.tsx @@ -370,7 +370,7 @@ function RightPanelEmptyState(props: { onClick: props.onAddDiff, }, { - label: "Pull request", + label: "Open pull requests", icon: PullRequestGlyph.pullRequest, shortcut: "P", available: props.pullRequestAvailable, @@ -1124,7 +1124,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) { onClick: props.onAddDiff, }, { - label: "Pull request", + label: "Open pull requests", icon: PullRequestGlyph.pullRequest, shortcut: "P", available: props.pullRequestAvailable, diff --git a/apps/web/src/components/chat/useRightPanelActions.ts b/apps/web/src/components/chat/useRightPanelActions.ts index 25ec5c22c2e1a..bfdbe070cb5f8 100644 --- a/apps/web/src/components/chat/useRightPanelActions.ts +++ b/apps/web/src/components/chat/useRightPanelActions.ts @@ -28,7 +28,7 @@ import { focusActivePanelTerminal, focusTerminal } from "../../lib/terminalFocus import { subscribePreviewAction } from "../preview/previewActionBus"; import { floatDeviceSurface } from "../preview/agentOpenedPreviews"; import { browserMiniPlayerSource, usePreviewMiniPlayerStore } from "../../previewMiniPlayerStore"; -import type { threadPullRequestPanelTarget } from "../pullRequest/pullRequestDetail.logic"; +import type { threadPullRequestPanelTargets } from "../pullRequest/pullRequestDetail.logic"; import type { useDeviceState } from "../../state/device"; import { stackedThreadToast, toastManager } from "../ui/toast"; import { openDeviceSetupDialog } from "./ChatOverlayHosts"; @@ -42,7 +42,7 @@ interface RightPanelActionsInput { readonly activePreviewState: ThreadPreviewState; readonly deviceState: ReturnType["state"]; readonly deviceStateLoaded: boolean; - readonly pullRequestPanelTarget: ReturnType | null; + readonly pullRequestPanelTargets: ReturnType; readonly threadPanelPresentation: ThreadPanelPresentation; readonly isServerThread: boolean; /** A side chat pane; the main view already answers preview bus actions. */ @@ -77,7 +77,7 @@ export function useRightPanelActions(input: RightPanelActionsInput) { activePreviewState, deviceState, deviceStateLoaded, - pullRequestPanelTarget, + pullRequestPanelTargets, threadPanelPresentation, isServerThread, embedded, @@ -292,9 +292,9 @@ export function useRightPanelActions(input: RightPanelActionsInput) { }; const copyRightPanelFilePathStable = useStableCallback(copyRightPanelFilePath); const addPullRequestSurface = () => { - if (!supportsPullRequests || activeThreadRef === null || pullRequestPanelTarget === null) + if (!supportsPullRequests || activeThreadRef === null || pullRequestPanelTargets.length === 0) return; - useRightPanelStore.getState().openPullRequest(activeThreadRef, pullRequestPanelTarget); + useRightPanelStore.getState().openPullRequests(activeThreadRef, pullRequestPanelTargets); }; const addPullRequestSurfaceStable = useStableCallback(addPullRequestSurface); const onOpenTurnDiff = (runId: RunId, filePath?: string) => { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index d23c4fdfae43a..418e2f99c0017 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -42,7 +42,7 @@ import { isStackedPullRequestBase, loadingPullRequestCheckoutCommand, pullRequestPanelContext, - threadPullRequestPanelTarget, + threadPullRequestPanelTargets, latestPullRequestReviewOutcomes, newestPullRequestCommitAt, mergePullRequestThreadComments, @@ -1456,7 +1456,7 @@ describe("pull request panel context beside a thread", () => { expect(pullRequestPanelContext({ projectId: null }, surface(3))).toBe("page"); }); - describe("the Pull request entry's target", () => { + describe("the Pull requests entry's targets", () => { const legacy = (number: number) => ({ projectId: ProjectId.make("proj-a"), repository: "pingdotgg/t3code", @@ -1466,33 +1466,73 @@ describe("pull request panel context beside a thread", () => { it("opens a linked pull request the legacy field never named, ahead of the branch PR", () => { expect( - threadPullRequestPanelTarget({ + threadPullRequestPanelTargets({ projectId: "proj-a", pullRequests: [link(15046, { source: "agent" })], linkedPullRequest: null, branchPullRequest: legacy(30), }), - ).toEqual({ ...legacy(15046), host: "github.com" }); + ).toEqual([{ ...legacy(15046), host: "github.com" }]); + }); + + it("opens every visible link, including unsynced and cross-repository PRs", () => { + expect( + threadPullRequestPanelTargets({ + projectId: "proj-a", + pullRequests: [ + link(1), + link(2, { repository: "other/repo", url: "https://github.com/other/repo/pull/2" }), + link(3, { source: "stack-dismissed" }), + ], + branchPullRequest: legacy(30), + }), + ).toEqual([ + { ...legacy(1), host: "github.com" }, + { + projectId: "proj-a", + host: "github.com", + repository: "other/repo", + number: 2, + url: "https://github.com/other/repo/pull/2", + }, + ]); + const snapshot = { + state: "merged" as const, + title: "Older PR", + headBranch: "older", + baseBranch: "main", + isDraft: false, + updatedAt: "2026-09-09T00:00:00Z", + syncedAt: "2026-09-09T00:00:00Z", + }; + const targets = threadPullRequestPanelTargets({ + projectId: "proj-a", + pullRequests: [ + link(1, { snapshot }), + link(2, { snapshot: { ...snapshot, state: "open", headBranch: "current" } }), + ], + }); + expect(targets.map((target) => target.number)).toEqual([2, 1]); }); it("reuses the legacy reference only for the same pull request on the same host", () => { const linkedPullRequest = legacy(15046); const onHost = (host: string) => - threadPullRequestPanelTarget({ + threadPullRequestPanelTargets({ projectId: "proj-a", pullRequests: [link(15046, { host, url: `https://${host}/pingdotgg/t3code/pull/15046` })], linkedPullRequest, }); - expect(onHost("github.com")).toBe(linkedPullRequest); - expect(onHost("github.example.com")).toMatchObject({ host: "github.example.com" }); + expect(onHost("github.com")).toEqual([linkedPullRequest]); + expect(onHost("github.example.com")).toMatchObject([{ host: "github.example.com" }]); }); // regression: #15061 Pull request panel entry ignored the branch PR it("falls back to the branch pull request when the thread holds no link", () => { expect( - threadPullRequestPanelTarget({ projectId: "proj-a", branchPullRequest: legacy(3) }), - ).toEqual(legacy(3)); - expect(threadPullRequestPanelTarget({ projectId: "proj-a", pullRequests: [] })).toBeNull(); + threadPullRequestPanelTargets({ projectId: "proj-a", branchPullRequest: legacy(3) }), + ).toEqual([legacy(3)]); + expect(threadPullRequestPanelTargets({ projectId: "proj-a", pullRequests: [] })).toEqual([]); }); }); }); diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index bcc46b63a0476..356dba35ff5a5 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -212,31 +212,31 @@ export function pullRequestPanelContext( : "page"; } -export function threadPullRequestPanelTarget(thread: { +export function threadPullRequestPanelTargets(thread: { readonly projectId: string; readonly pullRequests?: ReadonlyArray | undefined; readonly linkedPullRequest?: ThreadLinkedPullRequest | null | undefined; readonly branchPullRequest?: ThreadLinkedPullRequest | null | undefined; }) { - const current = resolveThreadCurrentPullRequestLink(thread.pullRequests ?? []); + const links = visibleThreadPullRequests(thread.pullRequests ?? []); const legacy = thread.linkedPullRequest; - if ( - current !== null && - legacy != null && - threadPullRequestKeysEqual(current, legacyThreadPullRequestKey(legacy)) - ) { - return legacy; - } - if (current !== null) { - return { - projectId: thread.projectId, - host: current.host, - repository: current.repository, - number: current.number, - url: current.url, - }; + if (links.length > 0) { + const current = resolveThreadCurrentPullRequestLink(links); + const orderedLinks = current ? [current, ...links.filter((link) => link !== current)] : links; + return orderedLinks.map((link) => + legacy != null && threadPullRequestKeysEqual(link, legacyThreadPullRequestKey(legacy)) + ? legacy + : { + projectId: thread.projectId, + host: link.host, + repository: link.repository, + number: link.number, + url: link.url, + }, + ); } - return legacy ?? thread.branchPullRequest ?? null; + const fallback = legacy ?? thread.branchPullRequest; + return fallback ? [fallback] : []; } export function pullRequestHandoffLabels(inThisThread: boolean) { diff --git a/apps/web/src/rightPanelStore.test.ts b/apps/web/src/rightPanelStore.test.ts index ec0f4e87c12e8..4be7dd56e1b32 100644 --- a/apps/web/src/rightPanelStore.test.ts +++ b/apps/web/src/rightPanelStore.test.ts @@ -997,13 +997,19 @@ describe("rightPanelStore", () => { useRightPanelStore.getState().openPullRequest(refA, second); const url = "https://gitlab.example.com/pingdotgg/t3code/-/merge_requests/4909"; useRightPanelStore.getState().openPullRequest(refA, { ...first, url }); - useRightPanelStore.getState().openPullRequest(refA, first); + useRightPanelStore + .getState() + .setPullRequestDetailTab(refA, pullRequestSurfaceId(second), "code"); + useRightPanelStore.getState().openFile(refA, "README.md"); + useRightPanelStore.getState().openPullRequests(refA, [first, second, first]); const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA); expect(state.surfaces.map((surface) => surface.id)).toEqual([ pullRequestSurfaceId(first), pullRequestSurfaceId(second), + "file:README.md", ]); + expect(state.surfaces[1]).toMatchObject({ detailTab: "code" }); expect(state.activeSurfaceId).toBe(pullRequestSurfaceId(first)); expect( selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA), diff --git a/apps/web/src/rightPanelStore.ts b/apps/web/src/rightPanelStore.ts index 1f736d4f119ae..bd44b5518e55c 100644 --- a/apps/web/src/rightPanelStore.ts +++ b/apps/web/src/rightPanelStore.ts @@ -139,17 +139,10 @@ interface RightPanelStoreState { keepSource?: boolean, ) => void; openAttachment: (ref: ScopedThreadRef, attachment: ChatFileAttachment) => void; - openPullRequest: ( + openPullRequest: (ref: ScopedThreadRef, target: Parameters[0]) => void; + openPullRequests: ( ref: ScopedThreadRef, - target: { - environmentId?: string; - projectId: string; - host?: string; - repository: string; - number: number; - url?: string; - detailTab?: PullRequestDetailTab; - }, + targets: ReadonlyArray[0]>, ) => void; setPullRequestDetailTab: ( ref: ScopedThreadRef, @@ -747,23 +740,26 @@ export const useRightPanelStore = create()( return upsertSurface({ ...current, surfaces: withoutPlaceholder }, surface); }), ), - openPullRequest: (ref, target) => + openPullRequest: (ref, target) => get().openPullRequests(ref, [target]), + openPullRequests: (ref, targets) => { + if (targets.length === 0) return; set((state) => userAction(state, scopedThreadKey(ref), (current) => { - const surface = pullRequestSurface(target); - const next = upsertSurface(current, surface); - return target.url - ? { - ...next, - surfaces: next.surfaces.map((entry) => - entry.id === surface.id && entry.kind === "pull-request" - ? { ...entry, ...surface } - : entry, - ), - } - : next; + const surfaces = new Map(current.surfaces.map((surface) => [surface.id, surface])); + for (const target of targets) { + const surface = pullRequestSurface(target); + const existing = surfaces.get(surface.id); + surfaces.set(surface.id, existing ? { ...existing, ...surface } : surface); + } + return { + ...current, + isOpen: true, + surfaces: [...surfaces.values()], + activeSurfaceId: pullRequestSurfaceId(targets[0]!), + }; }), - ), + ); + }, setPullRequestDetailTab: (ref, surfaceId, detailTab) => set((state) => { const threadKey = scopedThreadKey(ref);