Skip to content
TypeScript

fix(web): Pull request panel entry works for linked PRs (#15061)

oliverf90b77d80971
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index aed3cddf649..a8eb8fd64df 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -266,7 +266,10 @@ import {
selectThreadPreviewMiniPlayer,
usePreviewMiniPlayerStore,
} from "../previewMiniPlayerStore";
-import { pullRequestPanelContext } from "./pullRequest/pullRequestDetail.logic";
+import {
+ pullRequestPanelContext,
+ threadPullRequestPanelTarget,
+} from "./pullRequest/pullRequestDetail.logic";
import { PullRequestDetailPanel } from "./pullRequest/PullRequestDetailPanel";
import { PullRequestDetailGhost } from "./pullRequest/PullRequestGhosts";
import { PullRequestsUnavailableState } from "./pullRequest/PullRequestsUnavailableState";
@@ -6776,12 +6779,20 @@ export default function ChatView(props: ChatViewProps) {
},
);
}, [activeThreadReferenceCopyTarget]);
+ const pullRequestPanelTarget = activeThread
+ ? threadPullRequestPanelTarget({
+ projectId: activeThread.projectId,
+ pullRequests: visiblePullRequests,
+ linkedPullRequest: linkedThreadPullRequest,
+ branchPullRequest: activeThreadShell?.branchPullRequest ?? activeThread.branchPullRequest,
+ })
+ : null;
const addPullRequestSurface = useCallback(() => {
- if (!supportsPullRequests || activeThreadRef === null || linkedThreadPullRequest === null)
+ if (!supportsPullRequests || activeThreadRef === null || pullRequestPanelTarget === null)
return;
- useRightPanelStore.getState().openPullRequest(activeThreadRef, linkedThreadPullRequest);
- }, [activeThreadRef, linkedThreadPullRequest, supportsPullRequests]);
- const pullRequestSurfaceAvailable = supportsPullRequests && linkedThreadPullRequest !== null;
+ useRightPanelStore.getState().openPullRequest(activeThreadRef, pullRequestPanelTarget);
+ }, [activeThreadRef, pullRequestPanelTarget, supportsPullRequests]);
+ const pullRequestSurfaceAvailable = supportsPullRequests && pullRequestPanelTarget !== null;
const supportsSettlement = serverConfig?.environment.capabilities.threadSettlement === true;
const supportsSnooze = serverConfig?.environment.capabilities.threadSnooze === true;
const supportsPinning = serverConfig?.environment.capabilities.threadPinning === true;
@@ -10535,6 +10546,8 @@ export default function ChatView(props: ChatViewProps) {
projectId: activeThread.projectId,
pullRequests: visiblePullRequests,
linkedPullRequest: linkedThreadPullRequest,
+ branchPullRequest:
+ activeThreadShell?.branchPullRequest ?? activeThread.branchPullRequest,
},
renderedRightPanelSurface,
)}
diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
index 978ae69583d..3d5676ecbf5 100644
--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
@@ -35,6 +35,7 @@ import {
isStackedPullRequestBase,
loadingPullRequestCheckoutCommand,
pullRequestPanelContext,
+ threadPullRequestPanelTarget,
latestPullRequestReviewOutcomes,
newestPullRequestCommitAt,
mergePullRequestThreadComments,
@@ -1535,6 +1536,45 @@ describe("pull request panel context beside a thread", () => {
);
expect(pullRequestPanelContext({ projectId: null }, surface(3))).toBe("page");
});
+
+ describe("the Pull request entry's target", () => {
+ const legacy = (number: number) => ({
+ projectId: ProjectId.make("proj-a"),
+ repository: "pingdotgg/t3code",
+ number,
+ url: `https://github.com/pingdotgg/t3code/pull/${number}`,
+ });
+
+ it("opens a linked pull request the legacy field never named, ahead of the branch PR", () => {
+ expect(
+ threadPullRequestPanelTarget({
+ projectId: "proj-a",
+ pullRequests: [link(15046, { source: "agent" })],
+ linkedPullRequest: null,
+ branchPullRequest: legacy(30),
+ }),
+ ).toEqual({ ...legacy(15046), host: "github.com" });
+ });
+
+ it("reuses the legacy reference only for the same pull request on the same host", () => {
+ const linkedPullRequest = legacy(15046);
+ const onHost = (host: string) =>
+ threadPullRequestPanelTarget({
+ 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" });
+ });
+
+ 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();
+ });
+ });
});
describe("which actions need the host read again after they run", () => {
diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
index cdca896e607..00d3aafd2d2 100644
--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
@@ -27,6 +27,8 @@ import {
type VcsRef,
} from "@t3tools/contracts";
import {
+ legacyThreadPullRequestKey,
+ resolveThreadCurrentPullRequestLink,
threadPullRequestKeysEqual,
visibleThreadPullRequests,
} from "@t3tools/shared/threadPullRequests";
@@ -237,6 +239,33 @@ export function pullRequestPanelContext(
: "page";
}
+export function threadPullRequestPanelTarget(thread: {
+ readonly projectId: string;
+ readonly pullRequests?: ReadonlyArray<ThreadPullRequestLink> | undefined;
+ readonly linkedPullRequest?: ThreadLinkedPullRequest | null | undefined;
+ readonly branchPullRequest?: ThreadLinkedPullRequest | null | undefined;
+}) {
+ const current = resolveThreadCurrentPullRequestLink(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,
+ };
+ }
+ return legacy ?? thread.branchPullRequest ?? null;
+}
+
/** Names where a pull-request task will land, without letting each surface guess independently. */
export function pullRequestHandoffLabels(inThisThread: boolean) {
return inThisThread