Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): Add "copy url" to PR dropdown (#94552)

Marcel Poelkerb5beada6e873
diff --git a/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.stories.tsx b/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.stories.tsx
index 970ef7d50f28..1efaef57c615 100644
--- a/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.stories.tsx
+++ b/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.stories.tsx
@@ -3,7 +3,7 @@ import {
type GitState,
} from "@posthog/core/git-interaction/gitInteractionLogic";
import type { Meta, StoryObj } from "@storybook/react";
-import { GitActionControl } from "./TaskActionsMenu";
+import { GitActionControl, PrBadgeControl } from "./TaskActionsMenu";
// Runs the real computeGitInteractionState over a realistic GitState, so the
// stories show exactly what the task header offers in each environment,
@@ -86,3 +86,40 @@ export const GhCliUnauthenticated: Story = {
/>
),
};
+
+const prBadgeProps = {
+ prUrl: "https://github.com/example/example-repo/pull/1234",
+ prState: "open",
+ merged: false,
+ draft: false,
+ branchName: "feature/add-export",
+ otherPrs: [],
+ isPrPending: false,
+ gitItems: [],
+ onGitSelect: () => {},
+ onPrSelect: () => {},
+ onOtherPrSelect: () => {},
+};
+
+/** Open the chevron to see the PR actions, including the two copy items. */
+export const PrOpen: StoryObj<typeof PrBadgeControl> = {
+ render: () => (
+ <div className="p-4">
+ <PrBadgeControl {...prBadgeProps} />
+ </div>
+ ),
+};
+
+/** A merged PR has no lifecycle actions left, so the copy items are the menu. */
+export const PrMerged: StoryObj<typeof PrBadgeControl> = {
+ render: () => (
+ <div className="p-4">
+ <PrBadgeControl
+ {...prBadgeProps}
+ prState="closed"
+ merged
+ branchName={null}
+ />
+ </div>
+ ),
+};
diff --git a/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.tsx b/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.tsx
index 3e05d63f1e21..b417ef38bca6 100644
--- a/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.tsx
+++ b/products/desktop/packages/ui/src/features/git-interaction/components/TaskActionsMenu.tsx
@@ -7,6 +7,7 @@ import {
GitCommit,
GitFork,
GitPullRequest,
+ Link,
} from "@phosphor-icons/react";
import { getPrVisualConfig } from "@posthog/core/git-interaction/prStatus";
import { parseGithubUrl } from "@posthog/git/utils";
@@ -30,7 +31,7 @@ import {
import type { PrActionType } from "@posthog/shared";
import { Spinner } from "@posthog/ui/primitives/Spinner";
import { ChevronDown } from "lucide-react";
-import type { ReactNode } from "react";
+import type { ReactElement, ReactNode } from "react";
import { toast } from "../../../primitives/toast";
import { useLocalRepoPath } from "../../workspace/useLocalRepoPath";
import { getPrActionIcon, getPrVisualIcon } from "../prIcon";
@@ -284,7 +285,7 @@ interface PrBadgeControlProps {
onOtherPrSelect: (url: string) => void;
}
-function PrBadgeControl({
+export function PrBadgeControl({
prUrl,
prState,
merged,
@@ -296,12 +297,20 @@ function PrBadgeControl({
onGitSelect,
onPrSelect,
onOtherPrSelect,
-}: PrBadgeControlProps) {
+}: PrBadgeControlProps): ReactElement {
const config = getPrVisualConfig(prState, merged, draft);
const tone = prBadgeToneProps(config);
const lifecycleItems = config.actions;
const hasMenuItems = gitItems.length + lifecycleItems.length > 0;
- const hasDropdown = hasMenuItems || !!branchName || otherPrs.length > 0;
+
+ const copyPrUrl = async () => {
+ try {
+ await navigator.clipboard.writeText(prUrl);
+ toast.success("Pull request URL copied");
+ } catch {
+ toast.error("Couldn't copy pull request URL");
+ }
+ };
const copyBranchName = async () => {
if (!branchName) return;
@@ -323,93 +332,87 @@ function PrBadgeControl({
isPrPending={isPrPending}
otherCount={otherPrs.length}
/>
- {hasDropdown && (
- <>
- {/* quill's group only collapses corners, and both halves share one
- fill, so without a seam the trigger disappears into the badge. */}
- <ButtonGroupSeparator />
- <ChevronMenu
- label="Pull request actions"
- disabled={isPrPending}
- // The trigger wears the badge's own lifecycle colour: the group is
- // one control, and a neutral half beside a green one reads as two.
- variant={tone.variant}
- className={tone.className}
+ {/* quill's group only collapses corners, and both halves share one
+ fill, so without a seam the trigger disappears into the badge. */}
+ <ButtonGroupSeparator />
+ {/* The chevron is unconditional: this half only renders for a task that
+ has a PR, and the PR's URL is always something to copy. */}
+ <ChevronMenu
+ label="Pull request actions"
+ disabled={isPrPending}
+ // The trigger wears the badge's own lifecycle colour: the group is
+ // one control, and a neutral half beside a green one reads as two.
+ variant={tone.variant}
+ className={tone.className}
+ >
+ {gitItems.map((item) => (
+ <GitDropdownItem key={item.id} action={item} onSelect={onGitSelect} />
+ ))}
+ {gitItems.length > 0 && lifecycleItems.length > 0 && (
+ <DropdownMenuSeparator />
+ )}
+ {lifecycleItems.map((action) => (
+ <QDropdownMenuItem
+ key={action.id}
+ onClick={() => onPrSelect(action.id)}
>
- {gitItems.map((item) => (
- <GitDropdownItem
- key={item.id}
- action={item}
- onSelect={onGitSelect}
- />
- ))}
- {gitItems.length > 0 && lifecycleItems.length > 0 && (
- <DropdownMenuSeparator />
- )}
- {lifecycleItems.map((action) => (
- <QDropdownMenuItem
- key={action.id}
- onClick={() => onPrSelect(action.id)}
- >
- {getPrActionIcon(action.id)}
- {action.label}
- </QDropdownMenuItem>
- ))}
- {otherPrs.length > 0 && (
- <>
- {hasMenuItems && <DropdownMenuSeparator />}
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>
- <GitPullRequest size={12} weight="bold" />
- Other PRs
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent>
- {otherPrs.map((otherPr) => (
- <QDropdownMenuItem
- key={otherPr.url}
- onClick={() => onOtherPrSelect(otherPr.url)}
- >
- <OtherPrStateIcon visual={otherPr.visual} />
- <span>
- {otherPr.label}
- {otherPr.summary && ` ${otherPr.summary}`}
- {otherPr.visual && (
- <span
- style={{
- color: `var(--${otherPr.visual.color}-11)`,
- }}
- >
- {" "}
- · {otherPr.visual.label}
- </span>
- )}
- {otherPr.repoLabel && (
- <span className="text-muted-foreground">
- {" "}
- · {otherPr.repoLabel}
- </span>
- )}
+ {getPrActionIcon(action.id)}
+ {action.label}
+ </QDropdownMenuItem>
+ ))}
+ {otherPrs.length > 0 && (
+ <>
+ {hasMenuItems && <DropdownMenuSeparator />}
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger>
+ <GitPullRequest size={12} weight="bold" />
+ Other PRs
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ {otherPrs.map((otherPr) => (
+ <QDropdownMenuItem
+ key={otherPr.url}
+ onClick={() => onOtherPrSelect(otherPr.url)}
+ >
+ <OtherPrStateIcon visual={otherPr.visual} />
+ <span>
+ {otherPr.label}
+ {otherPr.summary && ` ${otherPr.summary}`}
+ {otherPr.visual && (
+ <span
+ style={{
+ color: `var(--${otherPr.visual.color}-11)`,
+ }}
+ >
+ {" "}
+ · {otherPr.visual.label}
</span>
- </QDropdownMenuItem>
- ))}
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- </>
- )}
- {branchName && (
- <>
- {(hasMenuItems || otherPrs.length > 0) && (
- <DropdownMenuSeparator />
- )}
- <QDropdownMenuItem onClick={copyBranchName}>
- <Copy size={12} weight="bold" />
- Copy branch name
- </QDropdownMenuItem>
- </>
- )}
- </ChevronMenu>
- </>
- )}
+ )}
+ {otherPr.repoLabel && (
+ <span className="text-muted-foreground">
+ {" "}
+ · {otherPr.repoLabel}
+ </span>
+ )}
+ </span>
+ </QDropdownMenuItem>
+ ))}
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ </>
+ )}
+ {(hasMenuItems || otherPrs.length > 0) && <DropdownMenuSeparator />}
+ <QDropdownMenuItem onClick={copyPrUrl}>
+ <Link size={12} weight="bold" />
+ Copy URL
+ </QDropdownMenuItem>
+ {branchName && (
+ <QDropdownMenuItem onClick={copyBranchName}>
+ <Copy size={12} weight="bold" />
+ Copy branch name
+ </QDropdownMenuItem>
+ )}
+ </ChevronMenu>
</ButtonGroup>
);
}