diff --git a/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRow.fixture.tsx b/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRow.fixture.tsx index 9c1843e848a..c2e4dca072b 100644 --- a/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRow.fixture.tsx +++ b/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRow.fixture.tsx @@ -35,10 +35,12 @@ const MENU_ROW = workspace({ function Row({ w = MENU_ROW, - opening = false + opening = false, + actions = ACTIONS }: { w?: typeof MENU_ROW opening?: boolean + actions?: RowActions }): React.JSX.Element { return ( ) @@ -118,6 +120,34 @@ export const menuOpen = defineFixture({ } }) +/** In front with a terminal focused: a second row copies the link to that terminal. */ +export const menuTerminalFocused = defineFixture({ + width: WIDTH, + render: () => ( +
+ 'terminal' }} /> +
+ ), + interact: async (frame) => { + openMenu(frame) + await waitFor(() => document.querySelector('[data-slot="dropdown-menu-content"]')) + } +}) + +/** In front with an agent chat focused: the second row names the chat. */ +export const menuChatFocused = defineFixture({ + width: WIDTH, + render: () => ( +
+ 'chat' }} /> +
+ ), + interact: async (frame) => { + openMenu(frame) + await waitFor(() => document.querySelector('[data-slot="dropdown-menu-content"]')) + } +}) + export const moveToSection = defineFixture({ width: WIDTH, render: () => ( diff --git a/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRowMenu.tsx b/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRowMenu.tsx index 9b2f5aa02c6..829fb3014a3 100644 --- a/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRowMenu.tsx +++ b/src/renderer/src/components/cloud-workspaces/CloudWorkspaceRowMenu.tsx @@ -12,11 +12,13 @@ import { FolderPlus, Link2, Lock, + MessageSquare, MoreHorizontal, Pin, PinOff, Play, RotateCw, + SquareTerminal, UserRoundCog, Users } from 'lucide-react' @@ -37,10 +39,11 @@ import { import { formatOptionalPrimaryShortcutLabel } from '@/hooks/useShortcutLabel' import { useTranslate } from '@/i18n/use-translate' import { useAppStore } from '@/store' -import type { - CloudWorkspace, - CloudWorkspacePatch, - CloudWorkspacePresence +import { + formatWorkspaceNumber, + type CloudWorkspace, + type CloudWorkspacePatch, + type CloudWorkspacePresence } from '../../../../shared/cloud-workspaces/cloud-workspaces-wire' import { MemberAvatar } from './CloudMemberAvatars' import { openTeammateProfile } from '../teammates/teammate-profile-store' @@ -55,9 +58,12 @@ export type RowActions = { open: (w: CloudWorkspace) => void /** Asleep: the read-only copy it saved when it went to sleep (never wakes it). */ read: (w: CloudWorkspace) => void - /** The link to the chat you have in front when this workspace is in front, else the workspace. */ + /** The workspace's link (W-number), the same as ⌘⌥⇧L and the tab-bar chip. */ copyLink: (w: CloudWorkspace) => void + /** The link to the chat or terminal you have focused in it (only offered while it is in front). */ copyWorkspaceLink: (w: CloudWorkspace) => void + /** What is focused in this workspace right now, if it is the one in front. */ + focusedItem?: (w: CloudWorkspace) => 'chat' | 'terminal' | null /** One-time jump: open the workspace on the chat this teammate has in front. */ goToChat: (w: CloudWorkspace, member: CloudWorkspacePresence) => void patch: (w: CloudWorkspace, patch: CloudWorkspacePatch) => void @@ -124,6 +130,8 @@ export function CloudWorkspaceRowMenu({ const t = useTranslate() const keybindings = useAppStore((state) => state.keybindings) const copyShortcut = formatOptionalPrimaryShortcutLabel('cloudWorkspace.copyLink', keybindings) + // Read when the menu renders (it re-renders on open), not kept: focus moves between opens. + const focused = open ? (actions.focusedItem?.(w) ?? null) : null const teammatesHere = canOpen ? presentMembers(w.presence, selfId).filter((p) => p.userId !== selfId) : [] @@ -224,13 +232,24 @@ export function CloudWorkspaceRowMenu({ )} actions.copyLink(w)}> - {t('auto.components.cloudWorkspaces.copyLink', 'Copy link')} + {w.number + ? t('auto.components.cloudWorkspaces.copyLinkTo', 'Copy link to {{number}}', { + number: formatWorkspaceNumber(w.number) + }) + : t('auto.components.cloudWorkspaces.copyLink', 'Copy link')} {copyShortcut ? {copyShortcut} : null} - actions.copyWorkspaceLink(w)}> - - {t('auto.components.cloudWorkspaces.copyWorkspaceLink', 'Copy workspace link')} - + {focused ? ( + actions.copyWorkspaceLink(w)}> + {focused === 'terminal' ? : } + {focused === 'terminal' + ? t( + 'auto.components.cloudWorkspaces.copyLinkToTerminal', + 'Copy link to this terminal' + ) + : t('auto.components.cloudWorkspaces.copyLinkToChat', 'Copy link to this chat')} + + ) : null} {w.ownerUserId !== selfId && ( openTeammateProfile(w.ownerUserId)}> diff --git a/src/renderer/src/components/cloud-workspaces/CloudWorkspacesHome.tsx b/src/renderer/src/components/cloud-workspaces/CloudWorkspacesHome.tsx index 7a6c51d8a52..4bb5d8d56db 100644 --- a/src/renderer/src/components/cloud-workspaces/CloudWorkspacesHome.tsx +++ b/src/renderer/src/components/cloud-workspaces/CloudWorkspacesHome.tsx @@ -28,7 +28,7 @@ import { refreshCloudMessageSenders } from '@/lib/cloud-message-sender' import { describeError } from './cloud-workspace-errors' import { focusCloudChat } from './cloud-chat-focus' import * as homeArchive from './cloud-workspace-home-archive' -import { frontCloudChat } from './cloud-workspace-links' +import { focusedKind, frontCloudChat } from './cloud-workspace-links' import { cloudWorkspaceTitle, copyCloudWorkspaceLink, @@ -228,11 +228,17 @@ export function CloudWorkspacesHome({ () => ({ open: (w: CloudWorkspace) => void open(w), read: (w: CloudWorkspace) => setReadingId(w.id), - copyLink: (w: CloudWorkspace) => { + copyLink: (w: CloudWorkspace) => void copyCloudWorkspaceLink(w.id), + copyWorkspaceLink: (w: CloudWorkspace) => { const front = frontCloudChat() - void copyCloudWorkspaceLink(w.id, front?.sandboxId === w.id ? front.chatId : null) + if (front?.sandboxId === w.id && front.chatId) { + void copyCloudWorkspaceLink(w.id, front.chatId) + } + }, + focusedItem: (w: CloudWorkspace) => { + const front = frontCloudChat() + return front?.sandboxId === w.id ? focusedKind(front.chatId) : null }, - copyWorkspaceLink: (w: CloudWorkspace) => void copyCloudWorkspaceLink(w.id), goToChat: (w: CloudWorkspace, member: CloudWorkspacePresence) => void open(w, member.chatId), patch: (w: CloudWorkspace, change: CloudWorkspacePatch) => void patch(w, change), setPinned: arrangement.pin, diff --git a/src/renderer/src/components/cloud-workspaces/cloud-workspace-copy-link.test.ts b/src/renderer/src/components/cloud-workspaces/cloud-workspace-copy-link.test.ts new file mode 100644 index 00000000000..26cd5b34273 --- /dev/null +++ b/src/renderer/src/components/cloud-workspaces/cloud-workspace-copy-link.test.ts @@ -0,0 +1,26 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const copy = vi.hoisted(() => vi.fn(async () => true)) +vi.mock('./open-cloud-workspace', () => ({ + copyCloudWorkspaceLink: copy, + openCloudWorkspace: vi.fn() +})) + +import { copyShortcutLink, focusedKind } from './cloud-workspace-links' + +const ID = 'sbx_00000000000000000000c197' + +describe('copy link (⌘⌥⇧L)', () => { + beforeEach(() => copy.mockClear()) + + it('copies the workspace link only, never the focused chat or terminal', async () => { + await copyShortcutLink(ID) + expect(copy).toHaveBeenCalledWith(ID, null) + }) + + it('names the focused item for the separate menu row', () => { + expect(focusedKind('t:term_1')).toBe('terminal') + expect(focusedKind('s:session_1')).toBe('chat') + expect(focusedKind(null)).toBeNull() + }) +}) diff --git a/src/renderer/src/components/cloud-workspaces/cloud-workspace-links.ts b/src/renderer/src/components/cloud-workspaces/cloud-workspace-links.ts index 4f1df5920ad..f988e467c7a 100644 --- a/src/renderer/src/components/cloud-workspaces/cloud-workspace-links.ts +++ b/src/renderer/src/components/cloud-workspaces/cloud-workspace-links.ts @@ -79,6 +79,19 @@ type Front = { } | null let front: Front = null +/** + * ⌘⌥⇧L: the workspace's own link (its W-number), like the tab-bar chip and Home's "Copy link to + * W-n". A link to the focused chat or terminal is a separate menu item, never the shortcut. + */ +export function copyShortcutLink(sandboxId: string): Promise { + return copyCloudWorkspaceLink(sandboxId, null) +} + +/** What a focused chat id points at: `t:` terminals, anything else an agent chat. */ +export function focusedKind(chatId: string | null | undefined): 'chat' | 'terminal' | null { + return !chatId ? null : chatId.startsWith('t:') ? 'terminal' : 'chat' +} + /** The cloud workspace in front and the chat focused in it, for "Copy link" with the chat. */ export function frontCloudChat(): { sandboxId: string; chatId: string | null } | null { return front ? { sandboxId: front.sandboxId, chatId: front.chatId } : null @@ -253,7 +266,7 @@ export function installCloudWorkspaceLinks(): () => void { ) ) { event.preventDefault() - void copyCloudWorkspaceLink(front.sandboxId, front.chatId) + void copyShortcutLink(front.sandboxId) return } const editing = target?.isContentEditable || target?.tagName === 'TEXTAREA' diff --git a/src/renderer/src/components/orca-cloud/CloudCopyWorkspaceLinkItem.fixture.tsx b/src/renderer/src/components/orca-cloud/CloudCopyWorkspaceLinkItem.fixture.tsx new file mode 100644 index 00000000000..4a492f3a201 --- /dev/null +++ b/src/renderer/src/components/orca-cloud/CloudCopyWorkspaceLinkItem.fixture.tsx @@ -0,0 +1,77 @@ +import { Copy } from 'lucide-react' +import { defineFixture } from '../../component-fixtures/component-fixture' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSub, + DropdownMenuSubContent, + DropdownMenuSubTrigger, + DropdownMenuTrigger +} from '@/components/ui/dropdown-menu' +import { CloudCopyWorkspaceLinkItem } from './CloudWorkspaceMenuItems' +import { workspace } from '../cloud-workspaces/cloud-workspaces.test-fixture' + +const WORKTREE = 'repo-1::/vercel/orca/workspaces/app/fix-login' +const SANDBOX = 'sbx_00000000000000000000c197' + +/** The sidebar's right-click Copy ▸ submenu for a cloud workspace: "Link to W-197", Path, Worktree Name. */ +export const sidebarCopySubmenu = defineFixture({ + width: 520, + setup: () => { + Object.assign(window.api.cloudWorkspaces, { + localWorkspaces: () => + Promise.resolve([{ sandboxId: SANDBOX, worktreeId: WORKTREE, runtimeEnvironmentId: null }]), + environmentBindings: () => Promise.resolve({}), + get: () => + Promise.resolve({ + ok: true as const, + value: workspace({ id: SANDBOX, number: 197, title: 'Fix login' }) + }) + }) + }, + render: () => ( +
+ + Menu + + + + + Copy + + + + + + Path + + + + Worktree Name + + + + + +
+ ), + interact: async () => { + const deadline = performance.now() + 3000 + let trigger: HTMLElement | null = null + while (!trigger && performance.now() < deadline) { + trigger = document.querySelector('[data-slot="dropdown-menu-sub-trigger"]') + await new Promise((resolve) => setTimeout(resolve, 50)) + } + trigger?.focus() + trigger?.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true })) + while ( + ![...document.querySelectorAll('[role=menuitem]')].some((el) => + el.textContent?.includes('W-197') + ) && + performance.now() < deadline + 2000 + ) { + await new Promise((resolve) => setTimeout(resolve, 50)) + } + } +}) diff --git a/src/renderer/src/components/orca-cloud/CloudWorkspaceMenuItems.tsx b/src/renderer/src/components/orca-cloud/CloudWorkspaceMenuItems.tsx index bc125e08daf..78d02ac266b 100644 --- a/src/renderer/src/components/orca-cloud/CloudWorkspaceMenuItems.tsx +++ b/src/renderer/src/components/orca-cloud/CloudWorkspaceMenuItems.tsx @@ -24,7 +24,10 @@ import { cloudWorkspaceActionGroups, type CloudWorkspaceAction } from '@/components/cloud-workspaces/cloud-workspace-action-groups' -import type { CloudWorkspace } from '../../../../shared/cloud-workspaces/cloud-workspaces-wire' +import { + formatWorkspaceNumber, + type CloudWorkspace +} from '../../../../shared/cloud-workspaces/cloud-workspaces-wire' import { useCloudWorkspaceView } from './use-cloud-workspace-view' import { useCloudPanelActions } from './use-cloud-panel-actions' import { useCloudWorkspaceRecord } from './use-cloud-workspace-record' @@ -194,7 +197,11 @@ export function CloudCopyWorkspaceLinkItem({ return ( void copyCloudWorkspaceLink(workspace.id)}> - {t('auto.components.cloudWorkspaces.workspaceLinkOption', 'Workspace link')} + {workspace.number + ? t('auto.components.cloudWorkspaces.linkToNumber', 'Link to {{number}}', { + number: formatWorkspaceNumber(workspace.number) + }) + : t('auto.components.cloudWorkspaces.workspaceLinkOption', 'Workspace link')} ) } diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index ebc5febaf26..a47732c0c2e 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -20976,7 +20976,6 @@ "connected": "{{value0}} is connected. Its projects are in the sidebar.", "copyFailed": "Couldn't copy the link. Try again.", "copyLink": "Copy link", - "copyWorkspaceLink": "Copy workspace link", "emptyArchivedBody": "Archived cloud workspaces show up here.", "emptyArchivedTitle": "No archived workspaces", "emptyFilteredBody": "Try another owner or repository.", @@ -21119,7 +21118,10 @@ "restartElsewhere": "Restart it from the computer that created it.", "makePrivateSidebar": "Teammates’ devices are disconnected. Only the owner will be able to open it.", "shareFailed": "Couldn’t change who can open it. Try again.", - "workspaceLinkOption": "Workspace link" + "workspaceLinkOption": "Workspace link", + "copyLinkToTerminal": "Copy link to this terminal", + "copyLinkToChat": "Copy link to this chat", + "linkToNumber": "Link to {{number}}" }, "orcaCloud": { "QueuedPrompt": {