Files
opencode-manager/frontend/src/components/session/SessionSandboxMenu.tsx
T
Chris Scott 95a9f6e1ed feat(sandbox): add the session sandbox control to the desktop composer
The sandbox toggle and resources dialog were only reachable from the mobile composer menu. Add SessionSandboxMenu next to the permission toggle on desktop and share the sandbox menu items with the mobile menu.
2026-10-15 16:53:49 -04:00

53 lines
1.8 KiB
TypeScript

import { useState } from 'react'
import { Box } from 'lucide-react'
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'
import { getIconToggleButtonClassName } from '@/components/ui/icon-toggle-button'
import { useSandboxToggle } from '@/hooks/useSandboxToggle'
import { shouldShowSandboxResources } from '@/lib/sandboxResources'
import { SandboxMenuItems } from '@/components/message/SandboxMenuItems'
import { SessionSandboxResourcesDialog } from '@/components/message/SessionSandboxResourcesDialog'
interface SessionSandboxMenuProps {
sessionID: string
}
export function SessionSandboxMenu({ sessionID }: SessionSandboxMenuProps) {
const sandbox = useSandboxToggle(sessionID)
const [resourcesOpen, setResourcesOpen] = useState(false)
if (!sandbox.available) return null
const label = `Sandbox: ${sandbox.isSandboxed ? 'on' : 'off'}${
sandbox.lockedReason === 'child' ? ` (${sandbox.label})` : ''
}`
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
type="button"
aria-label={label}
title={label}
className={getIconToggleButtonClassName(sandbox.isSandboxed)}
>
<Box className="w-5 h-5" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent side="top" align="start" collisionPadding={8} className="w-64">
<SandboxMenuItems sandbox={sandbox} onOpenResources={() => setResourcesOpen(true)} />
</DropdownMenuContent>
</DropdownMenu>
{shouldShowSandboxResources(sandbox) ? (
<SessionSandboxResourcesDialog
sessionID={sessionID}
open={resourcesOpen}
onOpenChange={setResourcesOpen}
override={sandbox.resources}
effective={sandbox.effectiveResources!}
/>
) : null}
</>
)
}