fix(web): open pull request row actions on right-click (#16612)
This commit is contained in:
1 parent
13aabf3d7d
commit
d8d037eae1
1 file changed
+29
-3
@@ -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 (
|
||||
<div
|
||||
className={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);
|
||||
}}
|
||||
>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<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
|
||||
|
||||
Reference in new issue
Block a user