GeezerVison is showing github.com — fix(web): PR timeline "Open activity on host" buttons honor 'Open lin… · patroza/t3code@60eed62
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/pullRequest
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestTimelineTab.browser.test.tsx +75Lines changed: 75 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,11 +2,23 @@ import { | 2 | 2 | EnvironmentId, | 3 | 3 | ProjectId, | 4 | 4 | SourceControlProviderKind, | | 5 | + ThreadId, | 5 | 6 | type PullRequestDetailView, | 6 | 7 | } from "@t3tools/contracts"; | 7 | 8 | import { expect, it, vi } from "vite-plus/test"; | 8 | 9 | import { userEvent } from "vite-plus/test/browser"; | 9 | 10 |
| | 11 | +const linkState = vi.hoisted(() => ({ | | 12 | + openLink: vi.fn(async () => {}), | | 13 | + useOpenLink: vi.fn(), | | 14 | +})); | | 15 | +vi.mock(import("~/browser/useOpenLink"), () => ({ | | 16 | + useOpenLink: (threadRef: unknown) => { | | 17 | + linkState.useOpenLink(threadRef); | | 18 | + return linkState.openLink; | | 19 | + }, | | 20 | +})); | | 21 | + | 10 | 22 | import { render } from "../../../test/render"; | 11 | 23 | import "../../index.css"; | 12 | 24 | import { PullRequestTimelineTab } from "./PullRequestTimelineTab"; | @@ -221,3 +233,66 @@ it("gives each comment and review a heading for screen reader navigation", async | 221 | 233 | await expect.element(screen.getByText("One question", { exact: true })).toBeVisible(); | 222 | 234 | await expect.element(screen.getByRole("heading", { name: /alice commented/ })).toBeVisible(); | 223 | 235 | }); | | 236 | + | | 237 | +it("opens activity host links through the link-target setting", async () => { | | 238 | + linkState.openLink.mockClear(); | | 239 | + linkState.useOpenLink.mockClear(); | | 240 | + const reviewUrl = `${detail.url}#pullrequestreview-1`; | | 241 | + const commentUrl = `${detail.url}#issuecomment-2`; | | 242 | + const threadRef = { | | 243 | + environmentId: EnvironmentId.make("environment"), | | 244 | + threadId: ThreadId.make("thread-1"), | | 245 | + }; | | 246 | + const commented: PullRequestDetailView = { | | 247 | + ...detail, | | 248 | + commits: [], | | 249 | + comments: [ | | 250 | + { | | 251 | + id: "review", | | 252 | + kind: "review", | | 253 | + author: { login: "bob", name: null, avatarUrl: null }, | | 254 | + body: "Looks good", | | 255 | + createdAt: "2026-10-01T00:00:00Z", | | 256 | + url: reviewUrl, | | 257 | + path: null, | | 258 | + reviewState: "APPROVED", | | 259 | + }, | | 260 | + { | | 261 | + id: "comment", | | 262 | + kind: "issue-comment", | | 263 | + author: { login: "alice", name: null, avatarUrl: null }, | | 264 | + body: "One question", | | 265 | + createdAt: "2026-10-01T00:01:00Z", | | 266 | + url: commentUrl, | | 267 | + path: null, | | 268 | + reviewState: null, | | 269 | + }, | | 270 | + ], | | 271 | + }; | | 272 | + await using screen = await render( | | 273 | + <div style={{ height: 600 }}> | | 274 | + <PullRequestTimelineTab | | 275 | + scrollerRef={() => {}} | | 276 | + detail={commented} | | 277 | + environmentId={threadRef.environmentId} | | 278 | + threadRef={threadRef} | | 279 | + reference={detail} | | 280 | + order="oldest" | | 281 | + onOpenCommit={() => {}} | | 282 | + onRefresh={() => {}} | | 283 | + /> | | 284 | + </div>, | | 285 | + ); | | 286 | + await userEvent.click(screen.getByRole("button", { name: "Open activity on host" })); | | 287 | + expect(linkState.useOpenLink).toHaveBeenCalledWith(threadRef); | | 288 | + expect(linkState.openLink).toHaveBeenLastCalledWith(reviewUrl, { | | 289 | + event: expect.objectContaining({ metaKey: false, ctrlKey: false }), | | 290 | + }); | | 291 | + | | 292 | + await userEvent.click(screen.getByRole("button", { name: /1 comment/ })); | | 293 | + const buttons = screen.getByRole("button", { name: "Open activity on host" }).all(); | | 294 | + await userEvent.click(buttons[1]!); | | 295 | + expect(linkState.openLink).toHaveBeenLastCalledWith(commentUrl, { | | 296 | + event: expect.objectContaining({ metaKey: false, ctrlKey: false }), | | 297 | + }); | | 298 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx +15-9Lines changed: 15 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,8 +28,8 @@ import { msg, T, useGT, useMessages, Var } from "gt-react"; | 28 | 28 | import { m } from "~/i18n/messages"; | 29 | 29 | import { useEffect, useEffectEvent, useRef, useState, type ReactNode } from "react"; | 30 | 30 |
| | 31 | +import { useOpenLink } from "~/browser/useOpenLink"; | 31 | 32 | import { cn } from "~/lib/utils"; | 32 | | -import { readLocalApi } from "~/localApi"; | 33 | 33 | import { pullRequestEnvironment } from "~/state/pullRequests"; | 34 | 34 | import { RelativeTime } from "~/components/RelativeTime"; | 35 | 35 |
| @@ -219,15 +219,20 @@ function AddToChatButton({ | 219 | 219 | ); | 220 | 220 | } | 221 | 221 |
| 222 | | -function OpenOnHostButton({ url, onOpen }: { url: string | null; onOpen: (url: string) => void }) { | | 222 | +type OpenOnHost = ( | | 223 | + url: string, | | 224 | + event: { readonly metaKey: boolean; readonly ctrlKey: boolean; readonly button?: number }, | | 225 | +) => void; | | 226 | + | | 227 | +function OpenOnHostButton({ url, onOpen }: { url: string | null; onOpen: OpenOnHost }) { | 223 | 228 | const gt = useGT(); | 224 | 229 | return url === null ? null : ( | 225 | 230 | <Button | 226 | 231 | size="icon-xs" | 227 | 232 | variant="ghost-muted" | 228 | 233 | className="-mr-1 shrink-0" | 229 | 234 | aria-label={gt("Open activity on host")} | 230 | | - onClick={() => onOpen(url)} | | 235 | + onClick={(event) => onOpen(url, event)} | 231 | 236 | > | 232 | 237 | <ExternalLinkIcon className="size-3" /> | 233 | 238 | </Button> | @@ -247,7 +252,7 @@ function ConversationCard({ | 247 | 252 | event: PullRequestTimelineEvent; | 248 | 253 | editable: PullRequestComment | null; | 249 | 254 | cwd: string; | 250 | | - onOpen: (url: string) => void; | | 255 | + onOpen: OpenOnHost; | 251 | 256 | reactions: ReactionSurface; | 252 | 257 | showPath?: boolean; | 253 | 258 | /** A reply goes with its conversation, from the card that heads it. */ | @@ -402,7 +407,7 @@ function ConversationGroup({ | 402 | 407 | events: ReadonlyArray<PullRequestTimelineEvent>; | 403 | 408 | editable: ReadonlyMap<string, PullRequestComment>; | 404 | 409 | cwd: string; | 405 | | - onOpen: (url: string) => void; | | 410 | + onOpen: OpenOnHost; | 406 | 411 | reactions: ReactionSurface; | 407 | 412 | }) { | 408 | 413 | const [open, setOpen] = useState( | @@ -493,7 +498,7 @@ function ReviewThreadEvent({ | 493 | 498 | detail: PullRequestDetailView; | 494 | 499 | editable: ReadonlyMap<string, PullRequestComment>; | 495 | 500 | cwd: string; | 496 | | - onOpen: (url: string) => void; | | 501 | + onOpen: OpenOnHost; | 497 | 502 | reactions: ReactionSurface; | 498 | 503 | }) { | 499 | 504 | const gt = useGT(); | @@ -734,7 +739,7 @@ function ReviewVerdictEvent({ | 734 | 739 | outcome: PullRequestReviewOutcome; | 735 | 740 | stale: boolean; | 736 | 741 | cwd: string; | 737 | | - onOpen: (url: string) => void; | | 742 | + onOpen: OpenOnHost; | 738 | 743 | reactions: ReactionSurface; | 739 | 744 | }) { | 740 | 745 | const gt = useGT(); | @@ -911,8 +916,9 @@ export function PullRequestTimelineTab({ | 911 | 916 | }, [revealUrl, targetIndex]); | 912 | 917 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- the hold observes DOM outside React and must end with the tab | 913 | 918 | useEffect(() => () => stopHolding.current?.(), []); | 914 | | - const openOnHost = (url: string) => { | 915 | | - void readLocalApi()?.shell.openExternal(url); | | 919 | + const openLink = useOpenLink(threadRef); | | 920 | + const openOnHost: OpenOnHost = (url, event) => { | | 921 | + void openLink(url, { event }).catch(console.error); | 916 | 922 | }; | 917 | 923 |
| 918 | 924 | const rowKey = (row: PullRequestTimelineRow) => { | |
|