: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 channel breadcrumb actions (#81293)
Peter Kirkhamacc4fb359df4
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.test.tsxindex 0353b144bfb6..310b9b7a8118 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.test.tsx@@ -8,6 +8,19 @@ const router = vi.hoisted(() => ({pathname: "/website/team/artifacts",navigate: vi.fn(),}));+const channels = vi.hoisted(() => ({+ current: [+ {+ id: "team",+ name: "Team",+ channelType: "public" as const,+ starred: false,+ },+ ],+ star: vi.fn().mockResolvedValue(undefined),+ unstar: vi.fn().mockResolvedValue(undefined),+ copyLink: vi.fn().mockResolvedValue(undefined),+}));vi.mock("@tanstack/react-router", () => ({useNavigate: () => router.navigate,@@ -20,6 +33,18 @@ vi.mock("@tanstack/react-router", () => ({vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({useChannelsLayout: () => true,}));+vi.mock("@posthog/ui/features/canvas/hooks/useChannels", () => ({+ useChannels: () => ({ channels: channels.current, isLoading: false }),+}));+vi.mock("@posthog/ui/features/canvas/hooks/useChannelStars", () => ({+ useChannelStarMutations: () => ({+ star: channels.star,+ unstar: channels.unstar,+ }),+}));+vi.mock("@posthog/ui/features/canvas/utils/copyChannelLink", () => ({+ copyChannelLink: channels.copyLink,+}));import { ChannelBreadcrumb } from "./ChannelBreadcrumb";@@ -27,6 +52,10 @@ describe("ChannelBreadcrumb", () => {beforeEach(() => {router.pathname = "/website/team/artifacts";router.navigate.mockClear();+ channels.star.mockClear();+ channels.unstar.mockClear();+ channels.copyLink.mockClear();+ channels.current[0].starred = false;});it("closes title editing when the editable leaf changes", () => {@@ -128,4 +157,52 @@ describe("ChannelBreadcrumb", () => {fireEvent.click(root);expect(router.navigate).not.toHaveBeenCalled();});++ it("opens channel actions from the root segment", async () => {+ render(+ <Theme>+ <ChannelBreadcrumb+ channelName="Team"+ channelId="team"+ leafLabel="Artifacts"+ />+ </Theme>,+ );++ fireEvent.contextMenu(screen.getByRole("button", { name: /Team/ }));++ expect(await screen.findByText("Star channel")).toBeInTheDocument();+ expect(screen.getByText("Copy link to channel")).toBeInTheDocument();+ });++ it("runs star and copy actions for the channel", async () => {+ render(+ <Theme>+ <ChannelBreadcrumb channelName="Team" channelId="team" />+ </Theme>,+ );++ const root = screen.getByRole("button", { name: /Team/ });+ fireEvent.contextMenu(root);+ fireEvent.click(await screen.findByText("Star channel"));+ expect(channels.star).toHaveBeenCalledWith("team");++ fireEvent.contextMenu(root);+ fireEvent.click(await screen.findByText("Copy link to channel"));+ expect(channels.copyLink).toHaveBeenCalledWith("team", "title_bar");+ });++ it("offers to unstar a starred channel", async () => {+ channels.current[0].starred = true;+ render(+ <Theme>+ <ChannelBreadcrumb channelName="Team" channelId="team" />+ </Theme>,+ );++ fireEvent.contextMenu(screen.getByRole("button", { name: /Team/ }));+ fireEvent.click(await screen.findByText("Unstar channel"));++ expect(channels.unstar).toHaveBeenCalledWith("team");+ });});diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.tsxindex 670f0715181a..c34c76bed08e 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelBreadcrumb.tsx@@ -1,13 +1,25 @@+import { LinkIcon, StarIcon } from "@phosphor-icons/react";import {Button,+ ContextMenu,+ ContextMenuContent,+ ContextMenuItem,+ ContextMenuSeparator,+ ContextMenuTrigger,cn,Tooltip,TooltipContent,TooltipTrigger,} from "@posthog/quill";+import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";import { channelGlyph } from "@posthog/ui/features/canvas/components/channelGlyph";+import { useChannelStarMutations } from "@posthog/ui/features/canvas/hooks/useChannelStars";+import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";+import { copyChannelLink } from "@posthog/ui/features/canvas/utils/copyChannelLink";import { HeaderTitleEditor } from "@posthog/ui/features/task-detail/HeaderTitleEditor";+import { toast } from "@posthog/ui/primitives/toast";+import { track } from "@posthog/ui/shell/analytics";import { Flex, Text } from "@radix-ui/themes";import { useNavigate, useRouterState } from "@tanstack/react-router";import { type ReactNode, useState } from "react";@@ -69,31 +81,40 @@ export function ChannelBreadcrumb({? pathname === `/website/${channelId}`: false;+ const channelSegment = (+ <BreadcrumbSegment+ icon={channelGlyph(channelName, {+ size: 12,+ space: spacesLayout,+ className: "shrink-0 text-muted-foreground/80",+ })}+ label={channelName}+ strong+ onClick={+ channelId && !atChannelHome+ ? () =>+ void navigate({+ to: "/website/$channelId",+ params: { channelId },+ })+ : undefined+ }+ contextMenu={Boolean(channelId)}+ />+ );+return (<Flex align="center" justify="between" gap="2" className="w-full min-w-0">{/* flex-1 so the inline editor can stretch across the row; the trailingslot still sits at the far end. */}<Flex align="center" gap="0.5" className="min-w-0 flex-1">- <BreadcrumbSegment- icon={channelGlyph(channelName, {- size: 12,- space: spacesLayout,- className: "shrink-0 text-muted-foreground/80",- })}- label={channelName}- strong- // Nowhere to go from the space's own index, and no channelId means no- // route at all — either way the segment stops responding.- onClick={- channelId && !atChannelHome- ? () =>- void navigate({- to: "/website/$channelId",- params: { channelId },- })- : undefined- }- />+ {channelId ? (+ <ChannelSegmentContextMenu channelId={channelId}>+ {channelSegment}+ </ChannelSegmentContextMenu>+ ) : (+ channelSegment+ )}{middle && (<><BreadcrumbSeparator />@@ -165,6 +186,7 @@ function BreadcrumbSegment({strong,muted,onClick,+ contextMenu = false,...rest}: {icon?: ReactNode;@@ -175,6 +197,7 @@ function BreadcrumbSegment({muted?: boolean;/** Navigates, or (on a renamable leaf) opens the inline editor. */onClick?: () => void;+ contextMenu?: boolean;}) {const interactive = Boolean(onClick);@@ -192,7 +215,7 @@ function BreadcrumbSegment({// any other button: pointer cursor and hover fill. Inert ones read as// plain text — full opacity, ordinary cursor, and no hover (quill's// hover rules already skip aria-disabled) — and leave the tab order.- interactive+ interactive || contextMenu? "cursor-pointer!": "pointer-events-none cursor-default! opacity-100!",)}@@ -215,6 +238,63 @@ function BreadcrumbSegment({);}+function ChannelSegmentContextMenu({+ channelId,+ children,+}: {+ channelId: string;+ children: ReactNode;+}) {+ const { channels } = useChannels();+ const { star, unstar } = useChannelStarMutations();+ const channel = channels.find((candidate) => candidate.id === channelId);+ const canStar = channel != null && channel.channelType !== "personal";+ const isStarred = channel?.starred ?? false;++ const toggleStar = async () => {+ try {+ await (isStarred ? unstar(channelId) : star(channelId));+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {+ action_type: isStarred ? "unstar" : "star",+ surface: "title_bar",+ channel_id: channelId,+ });+ } catch (error) {+ toast.error(+ isStarred ? "Couldn't unstar channel" : "Couldn't star channel",+ {+ description: error instanceof Error ? error.message : String(error),+ },+ );+ }+ };++ return (+ <ContextMenu>+ <ContextMenuTrigger render={<span className="flex min-w-0" />}>+ {children}+ </ContextMenuTrigger>+ <ContextMenuContent className="no-drag">+ {canStar && (+ <>+ <ContextMenuItem onClick={() => void toggleStar()}>+ <StarIcon size={14} weight={isStarred ? "fill" : "regular"} />+ {isStarred ? "Unstar channel" : "Star channel"}+ </ContextMenuItem>+ <ContextMenuSeparator />+ </>+ )}+ <ContextMenuItem+ onClick={() => void copyChannelLink(channelId, "title_bar")}+ >+ <LinkIcon size={14} />+ Copy link to channel+ </ContextMenuItem>+ </ContextMenuContent>+ </ContextMenu>+ );+}+function BreadcrumbSeparator() {return (<Text className="shrink-0 text-[13px] text-muted-foreground/20">/</Text>diff --git a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsxindex f81e49815b74..25669880618c 100644--- a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsx@@ -50,6 +50,12 @@ vi.mock("@posthog/ui/features/canvas/hooks/useChannels", () => ({channels: [{ id: "chan-1", name: "project-bluebird" }],}),}));+vi.mock("@posthog/ui/features/canvas/hooks/useChannelStars", () => ({+ useChannelStarMutations: () => ({+ star: vi.fn(),+ unstar: vi.fn(),+ }),+}));vi.mock("@posthog/ui/features/canvas/hooks/useDashboards", () => ({useDashboard,useDashboardMutations: () => ({}),