1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-12-04 18:56:44 +01:00
archivr/frontend/src/components/RunsView.jsx
TheGeneralist fb1115a409
feat: non-blocking batch capture dialog, toasts on failure, fix /runs errors
CaptureDialog:
- Replace single textarea with multi-row inputs; + button adds rows
- Submit fires all pending rows in parallel, dialog stays open/usable
- Polling intervals live on a persistent ref (not cleared on close) so
  toasts fire even after the dialog is dismissed
- archiveId stored per item at submit time; page-refresh reconnect uses
  it.archiveId instead of the possibly-null prop
- Completed rows flash green then self-remove; failed rows show inline
  error + retry button
- Cancel becomes Close while jobs are in flight

ToastStack (new component):
- Fixed bottom-right overlay with spring-in animation
- Error toast: truncated locator, View error / Hide toggle expanding
  full error_text in a monospace pre block
- Auto-dismisses after 7 s; timer pauses while detail is expanded

RunsView:
- Failed rows are clickable and expand a full-width detail row showing
  error_summary in a scrollable monospace block

capture.rs (archivr-core):
- Staging dir is now "{millis}-{uuid}" — parallel captures in the same
  millisecond can no longer collide on temp paths
- create_archive_run moved before URL Content-Type probe so every
  attempt appears in /runs regardless of outcome
- Probe failures now call create_archive_run_item with source_metadata
  fallback then fail_run, recording error_text on the item and
  error_summary on the run with correct failed_count

styles.css:
- Capture dialog: header row, multi-row layout, status dots, spinner,
  add-row dashed button, per-row error text
- Toast stack: fixed overlay, error card with coloured left border,
  monospace detail expansion
- Run error rows: clickable hover tint, expand hint chevron, detail pre
2026-07-05 13:56:00 +02:00

86 lines
2.8 KiB
JavaScript

import { useState } from 'react'
function fmtDate(iso) {
if (!iso) return '—';
try {
return new Date(iso).toLocaleString(undefined, {
year: 'numeric', month: 'short', day: 'numeric',
hour: '2-digit', minute: '2-digit',
});
} catch {
return iso;
}
}
function StatusBadge({ status }) {
const cls = status === 'completed' ? 'run-status--completed'
: status === 'failed' ? 'run-status--failed'
: status === 'in_progress' ? 'run-status--in-progress'
: '';
const label = status ? status.replace(/_/g, ' ') : '—';
return <span className={`run-status ${cls}`}>{label}</span>;
}
export default function RunsView({ runs }) {
const [expanded, setExpanded] = useState(null) // run_uid of the expanded row
function toggle(uid) {
setExpanded(prev => prev === uid ? null : uid)
}
return (
<section id="runs-view" className="view is-active">
<table className="entry-table">
<thead>
<tr>
<th>Started</th>
<th>Status</th>
<th>Requested</th>
<th>Completed</th>
<th>Failed</th>
</tr>
</thead>
<tbody>
{runs.length === 0 ? (
<tr>
<td colSpan={5} style={{ color: 'var(--muted)', padding: '24px 16px', textAlign: 'center' }}>
No runs yet.
</td>
</tr>
) : runs.map(run => {
const hasError = run.status === 'failed' && run.error_summary
const isExpanded = expanded === run.run_uid
return [
<tr
key={run.run_uid}
className={hasError ? 'run-row run-row--failed' : 'run-row'}
onClick={hasError ? () => toggle(run.run_uid) : undefined}
title={hasError ? (isExpanded ? 'Click to hide error' : 'Click to view error') : undefined}
>
<td>{fmtDate(run.started_at)}</td>
<td>
<StatusBadge status={run.status} />
{hasError && (
<span className="run-expand-hint" aria-hidden="true">
{isExpanded ? '▴' : '▾'}
</span>
)}
</td>
<td>{run.requested_count ?? '—'}</td>
<td>{run.completed_count ?? '—'}</td>
<td>{run.failed_count ?? '—'}</td>
</tr>,
hasError && isExpanded && (
<tr key={`${run.run_uid}-detail`} className="run-error-row">
<td colSpan={5}>
<pre className="run-error-detail">{run.error_summary}</pre>
</td>
</tr>
),
]
})}
</tbody>
</table>
</section>
);
}