mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
Merge pull request #476 from nwparker/cloud/mpg-copy-link
fix(cloud): one 'Copy link to W-n' (⌘⌥⇧L, workspace only); separate terminal/chat link only when focused
This commit is contained in:
@@ -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 (
|
||||
<ul role="list" className="rounded-xl border border-border bg-card p-1">
|
||||
@@ -52,7 +54,7 @@ function Row({
|
||||
opening={opening}
|
||||
highlighted={false}
|
||||
now={FIXTURE_NOW}
|
||||
actions={ACTIONS}
|
||||
actions={actions}
|
||||
/>
|
||||
</ul>
|
||||
)
|
||||
@@ -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: () => (
|
||||
<div className="h-[420px]">
|
||||
<Row actions={{ ...ACTIONS, focusedItem: () => 'terminal' }} />
|
||||
</div>
|
||||
),
|
||||
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: () => (
|
||||
<div className="h-[420px]">
|
||||
<Row actions={{ ...ACTIONS, focusedItem: () => 'chat' }} />
|
||||
</div>
|
||||
),
|
||||
interact: async (frame) => {
|
||||
openMenu(frame)
|
||||
await waitFor(() => document.querySelector('[data-slot="dropdown-menu-content"]'))
|
||||
}
|
||||
})
|
||||
|
||||
export const moveToSection = defineFixture({
|
||||
width: WIDTH,
|
||||
render: () => (
|
||||
|
||||
@@ -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({
|
||||
)}
|
||||
<DropdownMenuItem onSelect={() => actions.copyLink(w)}>
|
||||
<Link2 />
|
||||
{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 ? <DropdownMenuShortcut>{copyShortcut}</DropdownMenuShortcut> : null}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => actions.copyWorkspaceLink(w)}>
|
||||
<Link2 />
|
||||
{t('auto.components.cloudWorkspaces.copyWorkspaceLink', 'Copy workspace link')}
|
||||
</DropdownMenuItem>
|
||||
{focused ? (
|
||||
<DropdownMenuItem onSelect={() => actions.copyWorkspaceLink(w)}>
|
||||
{focused === 'terminal' ? <SquareTerminal /> : <MessageSquare />}
|
||||
{focused === 'terminal'
|
||||
? t(
|
||||
'auto.components.cloudWorkspaces.copyLinkToTerminal',
|
||||
'Copy link to this terminal'
|
||||
)
|
||||
: t('auto.components.cloudWorkspaces.copyLinkToChat', 'Copy link to this chat')}
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
{w.ownerUserId !== selfId && (
|
||||
<DropdownMenuItem onSelect={() => openTeammateProfile(w.ownerUserId)}>
|
||||
<MemberAvatar userId={w.ownerUserId} directory={directory} selfId={selfId} size="sm" />
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
@@ -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<boolean> {
|
||||
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'
|
||||
|
||||
@@ -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: () => (
|
||||
<div className="h-[200px]">
|
||||
<DropdownMenu defaultOpen modal={false}>
|
||||
<DropdownMenuTrigger className="sr-only">Menu</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-52">
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger>
|
||||
<Copy className="size-3.5" />
|
||||
Copy
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent>
|
||||
<CloudCopyWorkspaceLinkItem worktreeId={WORKTREE} />
|
||||
<DropdownMenuItem>
|
||||
<Copy className="size-3.5" />
|
||||
Path
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<Copy className="size-3.5" />
|
||||
Worktree Name
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
),
|
||||
interact: async () => {
|
||||
const deadline = performance.now() + 3000
|
||||
let trigger: HTMLElement | null = null
|
||||
while (!trigger && performance.now() < deadline) {
|
||||
trigger = document.querySelector<HTMLElement>('[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))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -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 (
|
||||
<DropdownMenuItem onSelect={() => void copyCloudWorkspaceLink(workspace.id)}>
|
||||
<Link2 className="size-3.5" />
|
||||
{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')}
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user