Skip to content

Commit 0b050ed

Browse files
committed
fix(web): dismiss controlled pull request tooltips on scroll
1 parent 0c8fd2e commit 0b050ed

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
CheckpointRef,
66
EnvironmentId,
77
MessageId,
8+
ProjectId,
89
RunId,
910
ThreadId,
1011
} from "@t3tools/contracts";
@@ -275,7 +276,13 @@ describe("timeline tooltip scroll dismissal", () => {
275276
"hover then focus",
276277
"outside timeline",
277278
"wheel without scroll",
278-
])("handles %s through the real tooltip interactions", async (interaction) => {
279+
"pr hover",
280+
"pr delayed hover",
281+
"pr focus",
282+
"pr hover then focus",
283+
])("handles %s through the real tooltip interactions", async (scenario) => {
284+
const isPullRequest = scenario.startsWith("pr ");
285+
const interaction = isPullRequest ? scenario.slice(3) : scenario;
279286
vi.unstubAllGlobals();
280287
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
281288
vi.useFakeTimers();
@@ -285,7 +292,33 @@ describe("timeline tooltip scroll dismissal", () => {
285292
document.body.append(container);
286293
const root = createRoot(container);
287294
const onMouseEnter = vi.fn();
288-
const tooltip = (
295+
const query = await import("~/state/query");
296+
const querySpy = isPullRequest
297+
? vi.spyOn(query, "useEnvironmentQuery").mockReturnValue({
298+
data: null,
299+
dataUpdatedAt: 0,
300+
error: "Pull request not found",
301+
failure: null,
302+
isPending: false,
303+
isSuccess: false,
304+
refresh: vi.fn(),
305+
})
306+
: null;
307+
const { PullRequestLinkPreview } = await import("../pullRequest/PullRequestLinkPreview");
308+
const tooltip = isPullRequest ? (
309+
<PullRequestLinkPreview
310+
link={<button onMouseEnter={onMouseEnter}>message link</button>}
311+
originalUrl="https://example.com"
312+
target={{
313+
environmentId: ACTIVE_THREAD_ENVIRONMENT_ID,
314+
input: {
315+
projectId: ProjectId.make("project-1"),
316+
repository: "pingdotgg/t3code",
317+
number: 1,
318+
},
319+
}}
320+
/>
321+
) : (
289322
<Tooltip>
290323
<TooltipTrigger delay={50} onMouseEnter={onMouseEnter}>
291324
message link
@@ -318,7 +351,9 @@ describe("timeline tooltip scroll dismissal", () => {
318351
document.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab" }));
319352
trigger.focus();
320353
}
321-
if (interaction !== "delayed hover") await vi.advanceTimersByTimeAsync(60);
354+
if (interaction !== "delayed hover") {
355+
await vi.advanceTimersByTimeAsync(isPullRequest ? 400 : 60);
356+
}
322357
});
323358
expect(onMouseEnter).toHaveBeenCalledTimes(interaction === "focus" ? 0 : 1);
324359
expect(
@@ -331,7 +366,7 @@ describe("timeline tooltip scroll dismissal", () => {
331366
? new WheelEvent("wheel", { bubbles: true, deltaY: 100 })
332367
: new Event("scroll"),
333368
);
334-
await vi.advanceTimersByTimeAsync(100);
369+
await vi.advanceTimersByTimeAsync(isPullRequest ? 1000 : 100);
335370
});
336371
expect(
337372
document.querySelector('[data-slot="tooltip-popup"][data-open]')?.textContent ?? null,
@@ -343,6 +378,7 @@ describe("timeline tooltip scroll dismissal", () => {
343378
}
344379
} finally {
345380
await act(async () => root.unmount());
381+
querySpy?.mockRestore();
346382
container.remove();
347383
vi.useRealTimers();
348384
vi.unstubAllGlobals();

‎apps/web/src/components/pullRequest/PullRequestLinkPreview.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { PreviewCard as PreviewCardPrimitive } from "@base-ui/react/preview-card";
12
import { isAtomCommandInterrupted } from "@t3tools/client-runtime/state/runtime";
23
import type { EnvironmentId, PullRequestRef } from "@t3tools/contracts";
34
import {
45
cloneElement,
6+
useRef,
57
useState,
68
type ComponentPropsWithoutRef,
79
type MouseEvent,
@@ -45,6 +47,7 @@ export function PullRequestLinkPreview({
4547
fallback?: ReactNode;
4648
}) {
4749
const [open, setOpen] = useState(false);
50+
const previewActionsRef = useRef<PreviewCardPrimitive.Root.Actions | null>(null);
4851
const [resolvingClick, setResolvingClick] = useState(false);
4952
const detailQuery = useEnvironmentQuery(
5053
open
@@ -96,8 +99,14 @@ export function PullRequestLinkPreview({
9699
: (detail?.author.login ?? null);
97100

98101
return (
99-
<PreviewCard open={open} onOpenChange={setOpen}>
100-
<Tooltip open={showUrlTooltip}>
102+
<PreviewCard open={open} onOpenChange={setOpen} actionsRef={previewActionsRef}>
103+
<Tooltip
104+
open={showUrlTooltip}
105+
onOpenChange={(nextOpen) => {
106+
// Cancel the card's delayed hover too, without changing its content preview.
107+
if (!nextOpen && !showCard) previewActionsRef.current?.close();
108+
}}
109+
>
101110
<PreviewCardTrigger
102111
render={<TooltipTrigger render={trigger} />}
103112
delay={350}

0 commit comments

Comments
 (0)