From 2c5edf90da8af644cce13a567bf3f8cdd61177fc Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 15 Sep 2026 19:07:23 -0400 Subject: [PATCH] feat(site): add copy link button to chat sharing popover (#29365) --- .../components/ChatSharingPopover.test.tsx | 30 +++++++++++++++ .../components/ChatSharingPopover.tsx | 38 ++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 site/src/pages/AgentsPage/components/ChatSharingPopover.test.tsx diff --git a/site/src/pages/AgentsPage/components/ChatSharingPopover.test.tsx b/site/src/pages/AgentsPage/components/ChatSharingPopover.test.tsx new file mode 100644 index 00000000000..b9c7ed0290d --- /dev/null +++ b/site/src/pages/AgentsPage/components/ChatSharingPopover.test.tsx @@ -0,0 +1,30 @@ +import { screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, expect, it, vi } from "vitest"; +import { API } from "#/api/api"; +import { renderWithAuth } from "#/testHelpers/renderHelpers"; +import { ChatShareButton } from "./ChatSharingPopover"; + +const chatId = "chat-1"; + +describe("ChatSharingPopover", () => { + it("copies the absolute chat link to the clipboard", async () => { + vi.spyOn(API.experimental, "getChatACL").mockResolvedValue({ + users: [], + groups: [], + }); + const user = userEvent.setup(); + const writeText = vi + .spyOn(navigator.clipboard, "writeText") + .mockResolvedValue(); + + renderWithAuth(); + + await user.click(await screen.findByRole("button", { name: "Share" })); + await user.click(await screen.findByRole("button", { name: "Copy link" })); + + expect(writeText).toHaveBeenCalledWith( + `${window.location.origin}/agents/${chatId}`, + ); + }); +}); diff --git a/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx b/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx index 7fca07da7f9..eda50c0fdfe 100644 --- a/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx +++ b/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx @@ -1,4 +1,9 @@ -import { EllipsisVerticalIcon, Share2Icon, UserPlusIcon } from "lucide-react"; +import { + EllipsisVerticalIcon, + LinkIcon, + Share2Icon, + UserPlusIcon, +} from "lucide-react"; import { type FC, type ReactNode, useState } from "react"; import { useMutation, useQuery, useQueryClient } from "react-query"; import { toast } from "sonner"; @@ -9,6 +14,7 @@ import { } from "#/api/queries/chats"; import type * as TypesGen from "#/api/typesGenerated"; import { ErrorAlert } from "#/components/Alert/ErrorAlert"; +import { CheckIcon } from "#/components/AnimatedIcons/Check"; import { Avatar } from "#/components/Avatar/Avatar"; import { AvatarData } from "#/components/Avatar/AvatarData"; import { Button } from "#/components/Button/Button"; @@ -34,6 +40,7 @@ import { TableRow, } from "#/components/Table/Table"; import { useAuthenticated } from "#/hooks/useAuthenticated"; +import { useClipboard } from "#/hooks/useClipboard"; import { getGroupSubtitle, isGroup } from "#/modules/groups"; import { UserOrGroupAutocomplete, @@ -146,6 +153,32 @@ const MemberIdentity: FC = (props) => { ); }; +type CopyChatLinkButtonProps = { + chatId: string; +}; + +/** + * Copies the absolute chat URL so it can be shared from contexts without an + * address bar, such as an installed PWA. + */ +const CopyChatLinkButton: FC = ({ chatId }) => { + const { copyToClipboard, showCopiedSuccess } = useClipboard(); + const chatLink = new URL(`/agents/${chatId}`, window.location.origin).href; + + return ( + + ); +}; + type MobileMemberRowProps = { children: ReactNode; disabled: boolean; @@ -281,8 +314,9 @@ export const ChatSharingPopoverContent: FC = ({ align="end" className="w-[calc(100vw-2rem)] p-3 sm:w-[580px] sm:p-4" > -
+

Chat sharing

+