import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Loader2, ArrowRight, History, RefreshCw, Trash2 } from "lucide-react"; import { WorkflowHistorySummaryDto } from '@/api/schema.gen'; import { z } from 'zod'; import { client } from '@/api/client'; import { useAnalysisTemplates } from "@/hooks/useConfig"; type WorkflowHistorySummary = z.infer; export function RecentWorkflowsList() { const [history, setHistory] = useState([]); const [loading, setLoading] = useState(false); const navigate = useNavigate(); const { data: templates } = useAnalysisTemplates(); const fetchHistory = async () => { setLoading(true); try { // Using generated client to fetch history const data = await client.get_workflow_histories({ queries: { limit: 5 } }); setHistory(data); } catch (err) { console.error("Failed to fetch history:", err); } finally { setLoading(false); } }; const handleClearHistory = async () => { if (confirm("Are you sure you want to clear ALL history? This cannot be undone.")) { try { const res = await fetch('/api/v1/system/history', { method: 'DELETE' }); if (res.ok) { fetchHistory(); } else { console.error("Failed to clear history"); alert("Failed to clear history"); } } catch (e) { console.error(e); alert("Error clearing history"); } } }; useEffect(() => { fetchHistory(); }, []); if (!loading && history.length === 0) { return null; } return (
Recent Analysis Reports Your recently generated fundamental analysis reports.
Symbol Market Template Status Date Action {loading && history.length === 0 ? ( ) : ( history.map((item) => ( navigate(`/history/${item.request_id}`)}> {item.symbol} {item.market} {templates?.find(t => t.id === item.template_id)?.name || item.template_id || 'Default'} {new Date(item.start_time).toLocaleString()} )) )}
); } function StatusBadge({ status }: { status: string }) { let variant: "default" | "destructive" | "outline" | "secondary" = "outline"; let className = ""; switch (status.toLowerCase()) { case 'completed': variant = "default"; className = "bg-green-600 hover:bg-green-700"; break; case 'failed': variant = "destructive"; break; case 'running': case 'pending': variant = "secondary"; className = "text-blue-600 bg-blue-100"; break; default: variant = "outline"; } return ( {status} ); }