Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,21 @@ export default function Sidebar() {
);
},
});
const { copyToClipboard: copyPrLinkToClipboard } = useCopyToClipboard<{ url: string }>({
target: "PR link",
onCopy: ({ url }) => {
toastManager.add({ type: "success", title: "PR link copied", description: url });
},
onError: (error) => {
toastManager.add(
stackedThreadToast({
type: "error",
title: "Failed to copy PR link",
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
},
});
const { copyToClipboard: copyThreadIdToClipboard } = useCopyToClipboard<{ threadId: ThreadId }>({
onCopy: ({ threadId }) => {
toastManager.add({
Expand Down Expand Up @@ -3909,12 +3924,14 @@ export default function Sidebar() {
const isSettled = settledThreadKeysRef.current.has(threadKey);
const isSnoozed = snoozedThreadKeysRef.current.has(threadKey);
const isPinned = thread.pinnedAt != null;
const prUrl = (thread.linkedPullRequest ?? thread.branchPullRequest)?.url ?? null;
// Presets resolve at menu-open time (same as the popover).
const snoozePresets = resolveSnoozePresets(new Date(), timestampFormat);
const clicked = await settlePromise(() =>
api.contextMenu.show(
buildThreadActionMenuItems({
branch: thread.branch ?? null,
prUrl,
isPinned,
isSettled,
isSnoozed,
Expand Down Expand Up @@ -4033,6 +4050,11 @@ export default function Sidebar() {
copyBranchToClipboard(thread.branch, { branch: thread.branch });
}
return;
case "copy-pr-link":
if (prUrl) {
copyPrLinkToClipboard(prUrl, { url: prUrl });
}
return;
case "copy-thread-id":
copyThreadIdToClipboard(thread.id, { threadId: thread.id });
return;
Expand Down Expand Up @@ -4108,6 +4130,7 @@ export default function Sidebar() {
confirmThreadDelete,
copyBranchToClipboard,
copyPathToClipboard,
copyPrLinkToClipboard,
copyThreadIdToClipboard,
deleteThread,
handleMultiSelectContextMenu,
Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/components/threadActionMenu.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { buildThreadActionMenuItems, type ThreadActionMenuState } from "./thread

const baseState: ThreadActionMenuState = {
branch: null,
prUrl: null,
isPinned: false,
isSettled: false,
isSnoozed: false,
Expand Down Expand Up @@ -55,6 +56,19 @@ describe("buildThreadActionMenuItems", () => {
expect(allIds(baseState)).not.toContain("copy-branch");
});

it("offers PR Link in Copy only when a PR URL is available", () => {
const copy = buildThreadActionMenuItems({
...baseState,
prUrl: "https://github.com/pingdotgg/t3code/pull/8531",
}).find((item) => item.id === "copy");
expect(copy?.children).toContainEqual({
id: "copy-pr-link",
label: "PR Link",
icon: "link",
});
expect(allIds(baseState)).not.toContain("copy-pr-link");
});

it("flips lifecycle labels with thread state", () => {
expect(ids({ ...baseState, isPinned: true, isSettled: true, isSnoozed: true })).toEqual(
expect.arrayContaining(["unpin", "unsettle", "unsnooze"]),
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/threadActionMenu.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export type ThreadActionMenuId =
| "mark-unread"
| "copy"
| "copy-path"
| "copy-pr-link"
| "copy-branch"
| "copy-thread-id"
| "archive"
| "delete";

export interface ThreadActionMenuState {
readonly branch: string | null;
readonly prUrl: string | null;
readonly isPinned: boolean;
readonly isSettled: boolean;
readonly isSnoozed: boolean;
Expand Down Expand Up @@ -117,6 +119,7 @@ export function buildThreadActionMenuItems(
...(state.branch
? [{ id: "copy-branch" as const, label: "Branch", icon: "git-branch" }]
: []),
...(state.prUrl ? [{ id: "copy-pr-link" as const, label: "PR Link", icon: "link" }] : []),
{ id: "copy-thread-id", label: "Thread ID", icon: "hash" },
],
},
Expand Down
10 changes: 10 additions & 0 deletions apps/web/src/contextMenuFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ const ICON_PATHS: Record<string, ReadonlyArray<{ tag: string; attrs: Record<stri
{ tag: "line", attrs: { x1: "10", x2: "8", y1: "3", y2: "21" } },
{ tag: "line", attrs: { x1: "16", x2: "14", y1: "3", y2: "21" } },
],
link: [
{
tag: "path",
attrs: { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" },
},
{
tag: "path",
attrs: { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" },
},
],
"mail-open": [
{
tag: "path",
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/hooks/useThreadActionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export function useThreadActionMenu(input: {
},
onError: (error) => failureToast("Failed to copy branch", error),
});
const { copyToClipboard: copyPrLinkToClipboard } = useCopyToClipboard<{ url: string }>({
target: "PR link",
onCopy: ({ url }) => {
toastManager.add({ type: "success", title: "PR link copied", description: url });
},
onError: (error) => failureToast("Failed to copy PR link", error),
});
const { copyToClipboard: copyThreadIdToClipboard } = useCopyToClipboard<{ threadId: ThreadId }>({
onCopy: ({ threadId }) => {
toastManager.add({ type: "success", title: "Thread ID copied", description: threadId });
Expand All @@ -136,9 +143,11 @@ export function useThreadActionMenu(input: {
titleRegeneration: readEnvironmentSupportsTitleRegeneration(threadRef.environmentId),
};
const isRegeneratingTitle = thread.titleRegeneration != null;
const prUrl = (thread.linkedPullRequest ?? thread.branchPullRequest)?.url ?? null;
const snoozePresets = resolveSnoozePresets(now, timestampFormat);
const items = buildThreadActionMenuItems({
branch: thread.branch ?? null,
prUrl,
isPinned: thread.pinnedAt != null,
isSettled: supports.settlement && thread.settledOverride === "settled",
isSnoozed: supports.snooze && effectiveSnoozed(thread, { now: now.toISOString() }),
Expand Down Expand Up @@ -273,6 +282,11 @@ export function useThreadActionMenu(input: {
copyBranchToClipboard(thread.branch, { branch: thread.branch });
}
return;
case "copy-pr-link":
if (prUrl) {
copyPrLinkToClipboard(prUrl, { url: prUrl });
}
return;
case "copy-thread-id":
copyThreadIdToClipboard(thread.id, { threadId: thread.id });
return;
Expand Down Expand Up @@ -335,6 +349,7 @@ export function useThreadActionMenu(input: {
confirmAndUnpinThread,
copyBranchToClipboard,
copyPathToClipboard,
copyPrLinkToClipboard,
copyThreadIdToClipboard,
deleteThread,
handleNewThread,
Expand Down
Loading