import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { Loader2 } from 'lucide-react'; import { api } from '../api/client'; interface PrintLogTableProps { archiveId: number; } function formatDuration(seconds: number | null): string { if (!seconds || seconds <= 0) return '—'; const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); if (h > 0) return `${h}h ${m}m`; return `${m}m`; } function formatDate(isoString: string | null): string { if (!isoString) return '—'; const d = new Date(isoString); return d.toLocaleString(); } export function PrintLogTable({ archiveId }: PrintLogTableProps) { const { t } = useTranslation(); const { data, isLoading } = useQuery({ queryKey: ['archive-runs', archiveId], queryFn: () => api.getArchiveRuns(archiveId), }); if (isLoading) { return (
{t('archives.runLog.empty')}
); } return (| {t('archives.runLog.col.date')} | {t('archives.runLog.col.status')} | {t('archives.runLog.col.duration')} | {t('archives.runLog.col.filament')} | {t('archives.runLog.col.cost')} |
|---|---|---|---|---|
| {formatDate(run.started_at || run.created_at)} | {t(`archives.runLog.status.${run.status}`, { defaultValue: run.status })} {run.failure_reason && ( {run.failure_reason} )} | {formatDuration(run.duration_seconds)} | {run.filament_used_grams != null ? `${run.filament_used_grams.toFixed(1)} g` : '—'} | {run.cost != null ? run.cost.toFixed(2) : '—'} |