Elffuss BraidHub

kikocis/clonagent public

main · 2.6 KiBRawPermalink
1import { useEffect, useState } from 'react';
2import { X, RotateCcw, Clock, GitBranch } from 'lucide-react';
3import { api } from '../api.js';
4
5export default function VersionsModal({ agentId, onClose, onRollback }) {
6 const [versions, setVersions] = useState([]);
7 const [busy, setBusy] = useState(false);
8
9 async function reload() { setVersions(await api(`/api/agents/${agentId}/versions`)); }
10 useEffect(() => { reload().catch(() => {}); }, [agentId]);
11
12 async function rollback(v) {
13 if (!confirm(`Rollback a v${v}? Esto crea una nueva versión a partir de la v${v}.`)) return;
14 setBusy(true);
15 try {
16 await api(`/api/agents/${agentId}/versions/${v}/rollback`, { method: 'POST' });
17 await reload();
18 onRollback && onRollback();
19 } finally { setBusy(false); }
20 }
21
22 return (
23 <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4" onClick={onClose}>
24 <div className="bg-surface-1 border border-border-subtle rounded-xl w-full max-w-2xl max-h-[80vh] flex flex-col" onClick={e => e.stopPropagation()}>
25 <header className="px-5 py-3 border-b border-border-subtle flex items-center justify-between">
26 <div className="flex items-center gap-2">
27 <GitBranch size={14} className="text-violet-300" />
28 <h2 className="text-sm font-semibold text-slate-100">Versiones de <span className="font-mono">{agentId}</span></h2>
29 </div>
30 <button onClick={onClose} className="text-slate-500 hover:text-slate-200">
31 <X size={16} />
32 </button>
33 </header>
34 <div className="flex-1 overflow-y-auto p-3 space-y-1.5">
35 {versions.length === 0 && <div className="text-center text-sm text-slate-500 py-8">Sin versiones aún.</div>}
36 {[...versions].reverse().map(v => (
37 <div key={v.version} className="flex items-center gap-3 px-3 py-2 rounded-lg bg-surface-2/50 hover:bg-surface-2 transition text-sm">
38 <span className="font-mono font-semibold text-violet-300 w-12">v{v.version}</span>
39 <div className="flex-1 min-w-0">
40 <div className="text-slate-200 truncate">{v.reason}</div>
41 <div className="text-[11px] text-slate-500 flex items-center gap-1.5">
42 <Clock size={10} /> {new Date(v.createdAt).toLocaleString('es')}
43 </div>
44 </div>
45 <button onClick={() => rollback(v.version)} disabled={busy}
46 className="btn-ghost text-xs" title="Rollback a esta versión">
47 <RotateCcw size={11} /> Rollback
48 </button>
49 </div>
50 ))}
51 </div>
52 </div>
53 </div>
54 );
55}