import { useState } from "react"; import { useFetcher } from "@remix-run/react"; import { AlertCircle, Info, Trash } from "lucide-react"; import { cn } from "~/lib/utils"; import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../ui/dialog"; import { Button } from "../ui"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "../ui/alert-dialog"; import { Badge } from "../ui/badge"; import { type LogItem } from "~/hooks/use-logs"; interface LogTextCollapseProps { text?: string; error?: string; logData: any; log: LogItem; id: string; episodeUUID?: string; } const getStatusColor = (status: string) => { switch (status) { case "PROCESSING": return "bg-blue-100 text-blue-800 hover:bg-blue-100 hover:text-blue-800"; case "PENDING": return "bg-yellow-100 text-yellow-800 hover:bg-yellow-100 hover:text-yellow-800"; case "COMPLETED": return "bg-success/10 text-success hover:bg-success/10 hover:text-success"; case "FAILED": return "bg-destructive/10 text-destructive hover:bg-destructive/10 hover:text-destructive"; case "CANCELLED": return "bg-gray-100 text-gray-800 hover:bg-gray-100 hover:text-gray-800"; default: return "bg-gray-100 text-gray-800 hover:bg-gray-100 hover:text-gray-800"; } }; export function LogTextCollapse({ episodeUUID, text, error, id, logData, log, }: LogTextCollapseProps) { const [dialogOpen, setDialogOpen] = useState(false); const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const deleteFetcher = useFetcher(); const handleDelete = () => { if (!episodeUUID) { console.error("No episodeUuid found in log data"); return; } deleteFetcher.submit( { id }, { method: "DELETE", action: "/api/v1/ingestion_queue/delete", encType: "application/json", }, ); setDeleteDialogOpen(false); }; // Show collapse if text is long (by word count) const COLLAPSE_WORD_LIMIT = 30; if (!text) { return (
No log details.
); } // Split by words for word count const words = text.split(/\s+/); const isLong = words.length > COLLAPSE_WORD_LIMIT; let displayText: string; if (isLong) { displayText = words.slice(0, COLLAPSE_WORD_LIMIT).join(" ") + " ..."; } else { displayText = text; } return (
setDialogOpen(true)} >
Log Details

{error && (

Error Details

{error}

)}
{log.status.charAt(0).toUpperCase() + log.status.slice(1).toLowerCase()}
{new Date(log.time).toLocaleString()}
{episodeUUID && ( Delete Episode Are you sure you want to delete this episode? This action cannot be undone. Cancel Continue )}
); }