: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(desktop): add copy link to sidebar item menus (#96327)
Peter Kirkhama4fa9abd2afe
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsxindex 1033214f327b..aeee9dbdef18 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsx@@ -4,6 +4,7 @@ import {DEFAULT_CHANNEL_ITEM_GROUPING,DEFAULT_CHANNEL_ITEM_SORT,} from "@posthog/core/canvas/channelItems";+import { useAuthStore } from "@posthog/ui/features/auth/store";import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";import { Theme } from "@radix-ui/themes";import { fireEvent, render, screen } from "@testing-library/react";@@ -58,6 +59,15 @@ vi.mock("@posthog/ui/features/canvas/components/ChannelsFab", () => ({vi.mock("@posthog/ui/features/canvas/hooks/useChannels", () => ({useChannels: () => ({ channels: [] }),}));+vi.mock("@posthog/ui/features/canvas/hooks/useFileTaskToChannel", () => ({+ useFileTaskToChannel: () => vi.fn(),+}));+vi.mock("@posthog/ui/features/browser-tabs/useOpenBrowserTab", () => ({+ useOpenBrowserTab: () => vi.fn(),+}));+vi.mock("@posthog/ui/shell/analytics", () => ({+ track: vi.fn(),+}));vi.mock("@posthog/ui/features/auth/authClient", () => ({useOptionalAuthenticatedClient: () => null,}));@@ -142,6 +152,43 @@ describe("ChannelSidebar", () => {mocks.channelReportsFlag = false;});+ it.each([+ ["task", "Sessions", "/code/channel/channel-1/tasks/item-1"],+ ["canvas", "Canvases", "/code/canvas/channel-1/item-1"],+ ] as const)(+ "copies the %s link from its context menu",+ async (kind, tab, path) => {+ const user = userEvent.setup({ pointerEventsCheck: 0 });+ const writeText = vi+ .spyOn(navigator.clipboard, "writeText")+ .mockResolvedValue();+ const previousAuth = useAuthStore.getState().authState;+ useAuthStore.setState({+ authState: { ...previousAuth, cloudRegion: "us" },+ });+ mocks.items = [+ item({+ key: `${kind}:item-1`,+ kind,+ id: "item-1",+ title: "Example item",+ }),+ ];+ try {+ renderSidebar();+ await user.click(screen.getByRole("tab", { name: tab }));+ fireEvent.contextMenu(screen.getByText("Example item"));+ await user.click(+ await screen.findByRole("menuitem", { name: "Copy link" }),+ );+ expect(writeText).toHaveBeenCalledWith(`https://us.posthog.com${path}`);+ } finally {+ useAuthStore.setState({ authState: previousAuth });+ writeText.mockRestore();+ }+ },+ );+it.each([{what: "nothing has arrived yet",diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsxindex d755eb436f26..ed5bae30c875 100644--- a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx@@ -4,6 +4,7 @@ import {CaretRightIcon,DotsThreeIcon,FolderSimpleIcon,+ LinkIcon,MagnifyingGlassIcon,PencilSimpleIcon,PushPinIcon,@@ -34,6 +35,8 @@ import type { Task } from "@posthog/shared/domain-types";import { useOpenBrowserTab } from "@posthog/ui/features/browser-tabs/useOpenBrowserTab";import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";import { useFileTaskToChannel } from "@posthog/ui/features/canvas/hooks/useFileTaskToChannel";+import { copyCanvasLink } from "@posthog/ui/features/canvas/utils/copyCanvasLink";+import { copyChannelLink } from "@posthog/ui/features/canvas/utils/copyChannelLink";import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";import { useSidebarPeekStore } from "@posthog/ui/features/sidebar/sidebarPeekStore";import { useHoldSidebarPeek } from "@posthog/ui/features/sidebar/useHoldSidebarPeek";@@ -182,6 +185,20 @@ function TaskRowMenuItems({<ArrowSquareOutIcon size={14} />Open in new tab</Item>+ <Item+ disabled={!menu.channelId}+ onClick={() => {+ if (!menu.channelId) return;+ if (isTask) {+ void copyChannelLink(menu.channelId, "sidebar", menu.id);+ } else {+ void copyCanvasLink(menu.channelId, menu.id, "sidebar");+ }+ }}+ >+ <LinkIcon size={14} />+ Copy link+ </Item><Item onClick={menu.onTogglePin}>{menu.isPinned ? (<PushPinSlashIcon size={14} />