mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
Merge pull request #819 from nwparker/cloud/share-link-flag
feat(cloud): SHARE-LINKS-HOLD share links behind cloudShareLinks capability (off)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { CloudStatusGlyph } from '@/components/orca-cloud/CloudStatusGlyph'
|
||||
import { cloudShareLinksEnabled } from '@/lib/orca-cloud/cloud-share-links-flag'
|
||||
import React, { useId, useState } from 'react'
|
||||
import { GitBranch, Loader2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -150,6 +151,7 @@ export function CloudWorkspaceRow({
|
||||
return
|
||||
}
|
||||
if (
|
||||
cloudShareLinksEnabled() &&
|
||||
keybindingMatchesAction(
|
||||
'cloudWorkspace.copyLink',
|
||||
event.nativeEvent,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { useRef } from 'react'
|
||||
import { useCloudShareLinksEnabled } from '@/lib/orca-cloud/cloud-share-links-flag'
|
||||
import { ArchiveSnapshotTooltip } from '@/components/orca-cloud/ArchiveSnapshotTooltip'
|
||||
import {
|
||||
Archive,
|
||||
@@ -111,6 +112,7 @@ export function CloudWorkspaceRowMenu({
|
||||
const t = useTranslate()
|
||||
const keybindings = useAppStore((state) => state.keybindings)
|
||||
const copyShortcut = formatOptionalPrimaryShortcutLabel('cloudWorkspace.copyLink', keybindings)
|
||||
const shareLinks = useCloudShareLinksEnabled()
|
||||
// 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
|
||||
@@ -185,16 +187,19 @@ export function CloudWorkspaceRowMenu({
|
||||
<DropdownMenuShortcut>↵</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem onSelect={() => actions.copyLink(w)}>
|
||||
<Link2 />
|
||||
{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>
|
||||
{focused ? (
|
||||
{/* SHARE-LINKS-HOLD: the Copy link items only while share links are on. */}
|
||||
{shareLinks ? (
|
||||
<DropdownMenuItem onSelect={() => actions.copyLink(w)}>
|
||||
<Link2 />
|
||||
{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>
|
||||
) : null}
|
||||
{shareLinks && focused ? (
|
||||
<DropdownMenuItem onSelect={() => actions.copyWorkspaceLink(w)}>
|
||||
{focused === 'terminal' ? <SquareTerminal /> : <MessageSquare />}
|
||||
{focused === 'terminal'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// App-level wiring for team cloud workspaces: orca://cloud links, presence for the workspace in
|
||||
// front, and the copy-link shortcut. Installed once from main.tsx; no React tree needed.
|
||||
import { cloudShareLinksEnabled } from '@/lib/orca-cloud/cloud-share-links-flag'
|
||||
import { toast } from 'sonner'
|
||||
import { useAppStore } from '@/store'
|
||||
import { getShortcutPlatform } from '@/lib/keyboard/shortcut-platform'
|
||||
@@ -232,6 +233,7 @@ export function installCloudWorkspaceLinks(): () => void {
|
||||
const target = event.target instanceof HTMLElement ? event.target : null
|
||||
if (
|
||||
!event.defaultPrevented &&
|
||||
cloudShareLinksEnabled() &&
|
||||
!shortcutOwnedElsewhere(target) &&
|
||||
keybindingMatchesAction(
|
||||
'cloudWorkspace.copyLink',
|
||||
|
||||
@@ -4,6 +4,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const toasts = vi.hoisted(() => ({ success: vi.fn(), warning: vi.fn(), error: vi.fn() }))
|
||||
vi.mock('sonner', () => ({ toast: toasts }))
|
||||
const shareLinks = vi.hoisted(() => ({ on: true }))
|
||||
vi.mock('@/lib/orca-cloud/cloud-share-links-flag', () => ({
|
||||
cloudShareLinksEnabled: () => shareLinks.on
|
||||
}))
|
||||
|
||||
import { copyCloudWorkspaceLink } from './cloud-workspace-share-link'
|
||||
import { rememberCloudWorkspaces } from './cloud-workspace-identity'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// A cloud workspace's share link: the org slug + W-number link when known, else the sandbox-id form.
|
||||
import { cloudShareLinksEnabled } from '@/lib/orca-cloud/cloud-share-links-flag'
|
||||
import { toast } from 'sonner'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import {
|
||||
@@ -47,6 +48,10 @@ export async function copyCloudWorkspaceLink(
|
||||
chatId?: string | null,
|
||||
options: { quiet?: boolean } = {}
|
||||
): Promise<boolean> {
|
||||
// SHARE-LINKS-HOLD: nothing is copied while share links are held.
|
||||
if (!cloudShareLinksEnabled()) {
|
||||
return false
|
||||
}
|
||||
const link = await shareLinkFor(id, chatId)
|
||||
try {
|
||||
// Why: main-process clipboard, like every other renderer copy. navigator.clipboard needs a
|
||||
|
||||
@@ -2,6 +2,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const toast = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn() }))
|
||||
vi.mock('sonner', () => ({ toast }))
|
||||
const shareLinks = vi.hoisted(() => ({ on: true }))
|
||||
vi.mock('@/lib/orca-cloud/cloud-share-links-flag', () => ({
|
||||
cloudShareLinksEnabled: () => shareLinks.on
|
||||
}))
|
||||
|
||||
import { copyCloudWorkspaceLink, shareLinkFor } from './open-cloud-workspace'
|
||||
import { rememberCloudWorkspaces } from './cloud-workspace-identity'
|
||||
@@ -86,4 +90,15 @@ describe('copy cloud workspace link', () => {
|
||||
expect(toast.error).toHaveBeenCalledTimes(1)
|
||||
warn.mockRestore()
|
||||
})
|
||||
|
||||
it('SHARE-LINKS-HOLD: with share links held, nothing is copied and no toast shows', async () => {
|
||||
shareLinks.on = false
|
||||
try {
|
||||
await expect(copyCloudWorkspaceLink('sbx_held')).resolves.toBe(false)
|
||||
expect(writeClipboardText).not.toHaveBeenCalled()
|
||||
expect(toast.success).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
shareLinks.on = true
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { useContext } from 'react'
|
||||
import { useCloudShareLinksEnabled } from '@/lib/orca-cloud/cloud-share-links-flag'
|
||||
import { ArchiveSnapshotTooltip } from './ArchiveSnapshotTooltip'
|
||||
import { toast } from 'sonner'
|
||||
import {
|
||||
@@ -202,7 +203,9 @@ export function CloudCopyWorkspaceLinkItem({
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
const { workspace } = useCloudWorkspaceRecord(worktreeId, hostId ?? null)
|
||||
if (!workspace) {
|
||||
// SHARE-LINKS-HOLD: no way to produce a share link while it's held.
|
||||
const shareLinks = useCloudShareLinksEnabled()
|
||||
if (!workspace || !shareLinks) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -2,6 +2,10 @@ import {
|
||||
KEYBINDING_DEFINITIONS,
|
||||
agentTabActionId
|
||||
} from '../../../../../shared/keybindings/definitions'
|
||||
import {
|
||||
CLOUD_SHARE_LINK_ACTION_ID,
|
||||
cloudShareLinksEnabled
|
||||
} from '@/lib/orca-cloud/cloud-share-links-flag'
|
||||
import type {
|
||||
KeybindingActionId,
|
||||
KeybindingDefinition
|
||||
@@ -31,6 +35,10 @@ export function groupDefinitions(
|
||||
const hiddenAgentActionIds = new Set<KeybindingActionId>(
|
||||
disabledAgentTabActionIds(disabledTuiAgents)
|
||||
)
|
||||
// SHARE-LINKS-HOLD: no ⌘⌥⇧L entry while share links are held.
|
||||
if (!cloudShareLinksEnabled()) {
|
||||
hiddenAgentActionIds.add(CLOUD_SHARE_LINK_ACTION_ID)
|
||||
}
|
||||
const groups = new Map<string, KeybindingDefinition[]>()
|
||||
for (const definition of [...KEYBINDING_DEFINITIONS, ...additionalDefinitions]) {
|
||||
if (hiddenAgentActionIds.has(definition.id)) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// SHARE-LINKS-HOLD: ⌘⌥⇧L (Copy cloud workspace link) is listed in Settings › Shortcuts and its
|
||||
// search only while share links are on.
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const shareLinks = vi.hoisted(() => ({ on: false }))
|
||||
vi.mock('@/lib/orca-cloud/cloud-share-links-flag', () => ({
|
||||
CLOUD_SHARE_LINK_ACTION_ID: 'cloudWorkspace.copyLink',
|
||||
cloudShareLinksEnabled: () => shareLinks.on
|
||||
}))
|
||||
|
||||
import { groupDefinitions } from './shortcut-groups'
|
||||
import { getShortcutsPaneSearchEntries } from './shortcuts-search'
|
||||
|
||||
const listed = (): string[] =>
|
||||
groupDefinitions([]).flatMap((group) => group.items.map((item) => item.id))
|
||||
const searched = (): string[] => getShortcutsPaneSearchEntries().map((entry) => entry.title)
|
||||
|
||||
describe('the share-link shortcut in Settings', () => {
|
||||
it('held: not listed and not searchable', () => {
|
||||
shareLinks.on = false
|
||||
expect(listed()).not.toContain('cloudWorkspace.copyLink')
|
||||
expect(searched()).not.toContain('Copy cloud workspace link')
|
||||
})
|
||||
|
||||
it('on: listed and searchable', () => {
|
||||
shareLinks.on = true
|
||||
expect(listed()).toContain('cloudWorkspace.copyLink')
|
||||
expect(searched()).toContain('Copy cloud workspace link')
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,8 @@
|
||||
import { KEYBINDING_DEFINITIONS } from '../../../../../shared/keybindings/definitions'
|
||||
import {
|
||||
CLOUD_SHARE_LINK_ACTION_ID,
|
||||
cloudShareLinksEnabled
|
||||
} from '@/lib/orca-cloud/cloud-share-links-flag'
|
||||
import type { SettingsSearchEntry } from '../search/settings-search'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { translateSearchKeyword } from '../search/settings-search-keywords'
|
||||
@@ -62,7 +66,8 @@ export function getShortcutsPaneSearchEntries(options?: {
|
||||
({ actionId }) =>
|
||||
(includeManagedBrowser ||
|
||||
(actionId !== 'tab.newBrowser' && actionId !== 'tab.newBrowserSplitRight')) &&
|
||||
(includeMobileEmulator || actionId !== 'tab.newSimulator')
|
||||
(includeMobileEmulator || actionId !== 'tab.newSimulator') &&
|
||||
(actionId !== CLOUD_SHARE_LINK_ACTION_ID || cloudShareLinksEnabled())
|
||||
)
|
||||
.map(({ searchEntry }) => searchEntry),
|
||||
getTerminalShortcutPolicySearchEntry()
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// SHARE-LINKS-HOLD (Neil): cloud workspace share links are held for this release. The code stays;
|
||||
// every way to produce a link (Copy › Workspace link / chat link, the cloud list's Copy link items,
|
||||
// ⌘⌥⇧L and its Settings entry) is off unless the account's capabilities turn on `cloudShareLinks`.
|
||||
// Opening an orca://cloud link someone already has still works. Share with team (visibility) stays.
|
||||
import { useAppStore } from '@/store'
|
||||
import type { OrcaProfileAuthStatus } from '../../../../shared/orca-profiles'
|
||||
|
||||
export const CLOUD_SHARE_LINKS_FLAG = 'cloudShareLinks'
|
||||
export const CLOUD_SHARE_LINK_ACTION_ID = 'cloudWorkspace.copyLink'
|
||||
|
||||
function enabledFor(status: OrcaProfileAuthStatus | null | undefined): boolean {
|
||||
return status?.capabilities?.flags[CLOUD_SHARE_LINKS_FLAG] === true
|
||||
}
|
||||
|
||||
/** Outside React (keyboard handlers, the copy itself, Settings' shortcut list). */
|
||||
export function cloudShareLinksEnabled(): boolean {
|
||||
return enabledFor(useAppStore.getState().orcaProfileAuthStatus)
|
||||
}
|
||||
|
||||
export function useCloudShareLinksEnabled(): boolean {
|
||||
return useAppStore((state) => enabledFor(state.orcaProfileAuthStatus))
|
||||
}
|
||||
Reference in New Issue
Block a user