Files
opencode-manager/frontend/src/components/repo/RepoRowActions.tsx
T
ioplex 4ec62cd4e7 fix: address findings from the full Docker evaluation of main
Critical and high:
- repos: unlinking a local repo removes only the Manager reference and alias,
  never the repository files; confirm button reads "Unlink"
- auth: rate-limit by the socket address; trust proxy headers only when
  AUTH_TRUSTED_PROXY_HEADERS is set (documented and forwarded in compose)
- composer: per-session in-memory drafts (text, bash mode, attachments);
  Escape no longer clears the prompt
- url params: compose same-tick updates so schedule dialogs stay closed after
  create/delete; delete dialog names the job

Medium:
- tool rows show failures (non-zero shell exit, failed exploration members)
- voice conversation shows the specific error and a starting state
- settings: Escape in dropdowns and the shortcut recorder no longer closes
  the dialog; mobile deep links open the requested section; one content tree
  per platform
- closing pushed sheets, settings, tool panels and schedule dialogs goes back
  in history
- login returns to the requested page; signed-out pages make no
  authenticated requests
- action terminals keep their output (Manager-side output capture and replay)
- unpushed-commit detection, commit message kept on failure
- binary files with unknown extensions are detected and not editable
- tool panel resizes when docked and floats as a dismissible sheet when the
  page is too narrow
- Docker image runs tini as PID 1

Low: not-found states, add-repo and branch validation errors (4xx),
search-aware empty states, mobile repo sort/filter/select cues, sidebar
resize affordance and collapse shortcut, mobile unread badge, preview port
filtering, terminal close handling, walkthrough empty state and helper
session filtering, placeholder contrast, permission labels and focus,
TTS task-list sanitizing, git identity email validation, quieter git
logging, hermetic worktree tests, and accessible names for icon-only
controls.
2026-10-23 11:42:37 -04:00

328 lines
11 KiB
TypeScript

import { useState } from 'react'
import { Loader2, GitBranch, GitBranchPlus, Download, Trash2, MoreVertical, Pencil } from 'lucide-react'
import { Button } from '@/components/ui/button'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { SourceControlPanel } from '@/components/source-control/SourceControlPanel'
import { DownloadDialog } from '@/components/ui/download-dialog'
import { CreateWorktreeDialog } from '@/components/repo/CreateWorktreeDialog'
import { RenameRepoDialog } from '@/components/repo/RenameRepoDialog'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
import { useQueryClient, useMutation } from '@tanstack/react-query'
import { downloadRepo, renameRepo } from '@/api/repos'
import { showToast } from '@/lib/toast'
import { getRepoDisplayName } from '@/lib/utils'
import { invalidateRepoListCaches } from '@/lib/queryInvalidation'
interface RepoRowActionsProps {
repo: {
id: number
name?: string | null
repoUrl?: string | null
localPath?: string
sourcePath?: string
branch?: string
currentBranch?: string
cloneStatus: string
isWorktree?: boolean
isLocal?: boolean
fullPath?: string
}
gitStatus?: {
branch: string
ahead: number
behind: number
}
onDelete: (id: number) => void
isDeleting: boolean
isMobile: boolean
onActionsOpenChange?: (isOpen: boolean) => void
}
export function RepoRowActions({
repo,
gitStatus,
onDelete,
isDeleting,
isMobile,
onActionsOpenChange,
}: RepoRowActionsProps) {
const [showDownloadDialog, setShowDownloadDialog] = useState(false)
const [showSourceControl, setShowSourceControl] = useState(false)
const [showWorktreeDialog, setShowWorktreeDialog] = useState(false)
const [showRenameDialog, setShowRenameDialog] = useState(false)
const repoName = getRepoDisplayName(repo)
const branchToDisplay = gitStatus?.branch || repo.currentBranch || repo.branch
const isReady = repo.cloneStatus === 'ready'
const queryClient = useQueryClient()
const renameMutation = useMutation({
mutationFn: (name: string | null) => renameRepo(repo.id, name),
onSuccess: (updated) => {
invalidateRepoListCaches(queryClient)
queryClient.setQueryData(['repo', repo.id], updated)
queryClient.invalidateQueries({ queryKey: ['all-schedules'] })
queryClient.invalidateQueries({ queryKey: ['all-schedule-runs'] })
queryClient.invalidateQueries({ queryKey: ['repo-schedules', repo.id] })
showToast.success('Repository renamed')
},
onError: (error: unknown) => {
showToast.error(error instanceof Error ? error.message : 'Rename failed')
},
})
const handleSourceControlOpen = (open: boolean) => {
setShowSourceControl(open)
onActionsOpenChange?.(open)
}
const handleRenameOpen = (open: boolean) => {
setShowRenameDialog(open)
onActionsOpenChange?.(open)
}
const handleDownloadDialogOpen = (open: boolean) => {
setShowDownloadDialog(open)
onActionsOpenChange?.(open)
}
const handleWorktreeDialogOpen = (open: boolean) => {
setShowWorktreeDialog(open)
onActionsOpenChange?.(open)
}
const canCreateWorktree = isReady && !repo.isWorktree && Boolean(repo.repoUrl)
const isUnlinkableLocalRepo = Boolean(repo.isLocal && !repo.isWorktree)
const deleteLabel = isUnlinkableLocalRepo ? 'Unlink Repository' : 'Delete Repository'
const handleDownload = async (options: { includeGit?: boolean; includePaths?: string[] }) => {
try {
await downloadRepo(repo.id, repoName, options)
showToast.success('Download complete')
} catch (error: unknown) {
showToast.error(error instanceof Error ? error.message : 'Download failed')
}
}
if (isMobile) {
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
aria-label="Repository actions"
size="sm"
variant="ghost"
className="h-8 w-8 p-0"
title="Repository actions"
onClick={(e) => e.stopPropagation()}
>
<MoreVertical className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent
align="end"
className="z-[200]"
onClick={(e) => e.stopPropagation()}
onPointerDown={(e) => e.stopPropagation()}
>
<DropdownMenuItem
onClick={() => handleSourceControlOpen(true)}
disabled={!isReady}
>
<GitBranch className="w-4 h-4 mr-2" />
Source Control
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleRenameOpen(true)}>
<Pencil className="w-4 h-4 mr-2" />
Rename
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => handleDownloadDialogOpen(true)}
disabled={!isReady}
>
<Download className="w-4 h-4 mr-2" />
Download
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => onDelete(repo.id)}
disabled={isDeleting}
className="text-destructive"
>
{isDeleting ? (
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
) : (
<Trash2 className="w-4 h-4 mr-2" />
)}
{isUnlinkableLocalRepo ? 'Unlink' : 'Delete'}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<SourceControlPanel
repoId={repo.id}
isOpen={showSourceControl}
onClose={() => {
setShowSourceControl(false)
onActionsOpenChange?.(false)
}}
currentBranch={branchToDisplay || ''}
repoName={repoName}
/>
<DownloadDialog
open={showDownloadDialog}
onOpenChange={(open) => {
setShowDownloadDialog(open)
onActionsOpenChange?.(open)
}}
onDownload={handleDownload}
title="Download Repository"
description="This will create a ZIP archive of the entire repository."
itemName={repoName}
targetPath={repo.fullPath}
/>
<RenameRepoDialog
isOpen={showRenameDialog}
currentName={repo.name ?? ''}
derivedName={repoName}
onClose={() => handleRenameOpen(false)}
onSave={(name) => renameMutation.mutate(name)}
/>
</>
)
}
return (
<>
<TooltipProvider delayDuration={200}>
<div className="flex items-center gap-1" onClick={(e) => e.stopPropagation()}>
<Tooltip>
<TooltipTrigger asChild>
<Button
aria-label="Rename Repository"
size="sm"
variant="ghost"
onClick={() => handleRenameOpen(true)}
className="h-8 w-8 p-0"
title="Rename Repository"
>
<Pencil className="w-4 h-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Rename Repository</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
aria-label="Source Control"
size="sm"
variant="ghost"
onClick={() => handleSourceControlOpen(true)}
disabled={!isReady}
className="h-8 w-8 p-0"
title="Source Control"
>
<GitBranch className="w-4 h-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Source Control</TooltipContent>
</Tooltip>
{canCreateWorktree && (
<Tooltip>
<TooltipTrigger asChild>
<Button
aria-label="Create Worktree"
size="sm"
variant="ghost"
onClick={() => handleWorktreeDialogOpen(true)}
className="h-8 w-8 p-0"
title="Create Worktree"
>
<GitBranchPlus className="w-4 h-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Create Worktree</TooltipContent>
</Tooltip>
)}
<Tooltip>
<TooltipTrigger asChild>
<Button
aria-label="Download Repository"
size="sm"
variant="ghost"
onClick={() => handleDownloadDialogOpen(true)}
disabled={!isReady}
className="h-8 w-8 p-0"
title="Download Repository"
>
<Download className="w-4 h-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Download Repository</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
aria-label={deleteLabel}
size="sm"
variant="ghost"
onClick={() => onDelete(repo.id)}
disabled={isDeleting}
className="h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10"
title={deleteLabel}
>
{isDeleting ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Trash2 className="w-4 h-4" />
)}
</Button>
</TooltipTrigger>
<TooltipContent>{deleteLabel}</TooltipContent>
</Tooltip>
</div>
</TooltipProvider>
<SourceControlPanel
repoId={repo.id}
isOpen={showSourceControl}
onClose={() => { setShowSourceControl(false); onActionsOpenChange?.(false); }}
currentBranch={branchToDisplay || ''}
repoName={repoName}
/>
<DownloadDialog
open={showDownloadDialog}
onOpenChange={(open) => { setShowDownloadDialog(open); onActionsOpenChange?.(open); }}
onDownload={handleDownload}
title="Download Repository"
description="This will create a ZIP archive of the entire repository."
itemName={repoName}
targetPath={repo.fullPath}
/>
<CreateWorktreeDialog
open={showWorktreeDialog}
onOpenChange={handleWorktreeDialogOpen}
repoId={repo.id}
repoUrl={repo.repoUrl}
defaultBaseBranch={branchToDisplay}
/>
<RenameRepoDialog
isOpen={showRenameDialog}
currentName={repo.name ?? ''}
derivedName={repoName}
onClose={() => handleRenameOpen(false)}
onSave={(name) => renameMutation.mutate(name)}
/>
</>
)
}