TypeScript
fix(web): open pull request row actions on right-click (#16612)
Jake Leventhald8d037eae1b7
diff --git a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsxindex 643c17d4b77..42b09f4387e 100644--- a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx+++ b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx@@ -11,7 +11,7 @@ import {MoreHorizontalIcon,PlusIcon,} from "lucide-react";-import { useCallback, useMemo } from "react";+import { useCallback, useMemo, useState } from "react";import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";import { useOpenPrLink } from "~/lib/openPullRequestLink";@@ -84,6 +84,15 @@ function LinkRow({onSetWatching: ((link: ThreadPullRequestLink, watching: boolean) => void) | null;}) {const openPrLink = useOpenPrLink(threadRef);+ const [menuOpen, setMenuOpen] = useState(false);+ const [menuPosition, setMenuPosition] = useState<{ x: number; y: number } | null>(null);+ const menuAnchor = useMemo(+ () =>+ menuPosition+ ? { getBoundingClientRect: () => new DOMRect(menuPosition.x, menuPosition.y, 0, 0) }+ : undefined,+ [menuPosition],+ );const { link, depth, stack } = line;const snapshot = link.snapshot;const open = snapshot === null || snapshot.state === "open";@@ -91,6 +100,12 @@ function LinkRow({return (<divclassName={cn(PULL_REQUEST_ROW_CLASS, "relative hover:bg-accent/60")}+ onContextMenu={(event) => {+ event.preventDefault();+ event.stopPropagation();+ setMenuPosition({ x: event.clientX, y: event.clientY });+ setMenuOpen(true);+ }}// Each layer steps in under the one it targets. The step is capped: beyond a few layers// the indent only says "still in the stack", which the connector line already does, and// a sixteen-layer stack would otherwise stair-step off the right edge.@@ -221,7 +236,13 @@ function LinkRow({)}><span aria-hidden className="absolute inset-0 bg-accent/60" />- <Menu>+ <Menu+ open={menuOpen}+ onOpenChange={(open) => {+ setMenuOpen(open);+ if (!open) setMenuPosition(null);+ }}+ ><MenuTriggerrender={<Button@@ -234,7 +255,12 @@ function LinkRow({</Button>}/>- <MenuPopup align="end" side="bottom">+ <MenuPopup+ anchor={menuAnchor}+ align={menuPosition ? "start" : "end"}+ side="bottom"+ sideOffset={menuPosition ? 0 : 4}+ ><MenuItem onClick={() => void writeTextToClipboard(link.url, "link")}><LinkIcon className="size-3.5" />Copy link