fix: Robogo板块移除API Key+添加分支下拉选择

This commit is contained in:
jiawei.chen 2026-07-08 18:06:02 +08:00
parent 57dcdbbb37
commit 47f4823bb6

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'
import { useTaskLogs } from '../../hooks/useTaskLogs'
import { Play, RefreshCw, Terminal, Zap, Layers, Cloud, FolderOpen, FileCode, ArrowRight, Monitor, Search } from 'lucide-react'
import { Play, RefreshCw, Terminal, Zap, Layers, Cloud, FolderOpen, FileCode, ArrowRight, Monitor, Search, GitBranch, ChevronDown } from 'lucide-react'
import { DCLOUD_NAV_ITEMS, DCLOUD_MODULE_INFO } from '../layout/navConfig'
interface TestFunc { name: string; readable: string; doc: string }
@ -32,9 +32,27 @@ export default function ExistingTestsView() {
const [roboForm, setRoboForm] = useState({ product: 'robogo', env: 'PROD', scope: 'all', run_count: 1, account: '', password: '' })
const [feUrl, setFeUrl] = useState('')
const [feBranch, setFeBranch] = useState('main')
const [feApiKey, setFeApiKey] = useState('')
const [feBranchSuggestions, setFeBranchSuggestions] = useState<{name:string;commit:string}[]>([])
const [feShowBranchPicker, setFeShowBranchPicker] = useState(false)
const [feScanningBranches, setFeScanningBranches] = useState(false)
const [feTaskId, setFeTaskId] = useState<string | null>(null)
const { logs: feLogs, running: feRunning, connect: feConnect } = useTaskLogs()
const detectFeBranches = async (repoUrl: string) => {
if (!repoUrl || !repoUrl.includes('://')) return
setFeScanningBranches(true)
setFeBranchSuggestions([])
try {
const res = await fetch('/api/repos/branches?url=' + encodeURIComponent(repoUrl))
const data = await res.json()
if (data.branches && data.branches.length > 0) {
setFeBranchSuggestions(data.branches)
const selected = data.latest && data.latest !== data.default ? data.latest : data.default
setFeBranch(selected || 'main')
}
} catch {}
setFeScanningBranches(false)
}
const [taskId, setTaskId] = useState<string | null>(null)
const { logs, running, connect } = useTaskLogs()
@ -297,29 +315,48 @@ export default function ExistingTestsView() {
<input
placeholder="前端仓库 URL"
value={feUrl}
onChange={e => setFeUrl(e.target.value)}
onChange={e => { setFeUrl(e.target.value); setFeShowBranchPicker(false) }}
onBlur={() => { if (feUrl.includes('://')) detectFeBranches(feUrl) }}
className="flex-1 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] outline-none"
/>
<input
placeholder="分支"
value={feBranch}
onChange={e => setFeBranch(e.target.value)}
className="w-28 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] outline-none"
/>
<input
type="password"
placeholder="API Key (可选)"
value={feApiKey}
onChange={e => setFeApiKey(e.target.value)}
className="w-48 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] outline-none"
/>
<div className="relative w-40">
<div className="flex items-center gap-1 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] cursor-pointer" onClick={() => { if (feUrl.includes('://')) detectFeBranches(feUrl); setFeShowBranchPicker(!feShowBranchPicker) }}>
<GitBranch className="w-3.5 h-3.5 text-[rgb(var(--color-text-secondary))] shrink-0" />
{feScanningBranches ? (
<span className="flex-1 text-xs text-[rgb(var(--color-text-secondary))]">扫描中...</span>
) : (
<span className="flex-1 truncate">{feBranch}</span>
)}
<ChevronDown className="w-3 h-3 text-[rgb(var(--color-text-secondary))] shrink-0 transition-transform" style={{ transform: feShowBranchPicker ? 'rotate(180deg)' : 'none' }} />
</div>
{feShowBranchPicker && (
<div className="absolute top-full left-0 right-0 mt-1 rounded-lg border shadow-lg z-50 overflow-hidden max-h-48 overflow-y-auto" style={{ backgroundColor: 'rgb(var(--color-surface))', borderColor: 'rgb(var(--color-border))' }}>
{feScanningBranches ? (
<div className="px-3 py-4 text-center text-xs text-[rgb(var(--color-text-secondary))]">
<RefreshCw className="w-4 h-4 mx-auto mb-1 animate-spin" />
正在扫描远程分支...
</div>
) : (
feBranchSuggestions.map(b => (
<button key={b.name} className="w-full text-left px-3 py-2 text-xs transition-colors flex items-center gap-2" style={{ color: b.name === feBranch ? 'rgb(var(--color-accent))' : 'rgb(var(--color-text-secondary))', backgroundColor: b.name === feBranch ? 'rgb(var(--color-accent)/0.1)' : 'transparent' }}
onClick={() => { setFeBranch(b.name); setFeShowBranchPicker(false) }}
onMouseEnter={e => { if (b.name !== feBranch) e.currentTarget.style.backgroundColor = 'rgb(var(--color-surface-hover))' }}
onMouseLeave={e => { if (b.name !== feBranch) e.currentTarget.style.backgroundColor = 'transparent' }}>
<GitBranch className="w-3 h-3 shrink-0" />{b.name}
{b.commit && <span className="text-[10px] font-mono opacity-50 shrink-0">{b.commit}</span>}
</button>
))
)}
</div>
)}
</div>
<button
onClick={async () => {
if (!feUrl) return
const res = await fetch('/api/repos/check-ui', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: feUrl, branch: feBranch, api_key: feApiKey }),
body: JSON.stringify({ url: feUrl, branch: feBranch }),
})
const task = await res.json()
setFeTaskId(task.id)