84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { Link } from 'react-router-dom';
|
|
import type { ChronologicalValidationSummary } from '@stock-bot/stock-config/chronological-validation';
|
|
import { Button } from '@/components/ui/Button';
|
|
import { chronologicalValidationDurableApi } from '../services/chronologicalValidationDurableApi';
|
|
|
|
export function SavedChronologicalValidations({ backtestId }: { backtestId: string }) {
|
|
const [rows, setRows] = useState<ChronologicalValidationSummary[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState('');
|
|
const [reload, setReload] = useState(0);
|
|
useEffect(() => {
|
|
let current = true;
|
|
const controller = new AbortController();
|
|
setRows([]);
|
|
setLoading(true);
|
|
setError('');
|
|
void chronologicalValidationDurableApi
|
|
.list(backtestId || undefined, controller.signal)
|
|
.then(value => {
|
|
if (current) {
|
|
setRows(value);
|
|
}
|
|
})
|
|
.catch(cause => {
|
|
if (current) {
|
|
setError(
|
|
cause instanceof Error ? cause.message : 'Could not load chronological validations'
|
|
);
|
|
}
|
|
})
|
|
.finally(() => {
|
|
if (current) {
|
|
setLoading(false);
|
|
}
|
|
});
|
|
return () => {
|
|
current = false;
|
|
controller.abort();
|
|
};
|
|
}, [backtestId, reload]);
|
|
return (
|
|
<section aria-label="Saved chronological validations" className="space-y-3">
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
<h2 className="font-semibold">Saved chronological validations</h2>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
disabled={loading}
|
|
onClick={() => setReload(value => value + 1)}
|
|
>
|
|
Refresh chronological validations
|
|
</Button>
|
|
</div>
|
|
{loading && <p role="status">Loading chronological validations...</p>}
|
|
{error && (
|
|
<p role="alert" className="text-error">
|
|
{error}
|
|
</p>
|
|
)}
|
|
{!loading && !error && rows.length === 0 && <p>No saved chronological validations.</p>}
|
|
{rows.map(item => (
|
|
<article key={item.id} className="rounded-lg border border-border p-3 space-y-1">
|
|
<Link
|
|
className="font-medium text-primary-500"
|
|
to={`/experiments/validation/${encodeURIComponent(item.id)}`}
|
|
>
|
|
{item.name}
|
|
</Link>
|
|
<p className="text-sm">
|
|
{item.stage === 'reported'
|
|
? 'Execution complete · report saved'
|
|
: item.stage === 'holdouts'
|
|
? 'Validation and test admitted'
|
|
: 'Training candidates admitted'}{' '}
|
|
· {item.trainingCandidateCount} training candidates
|
|
</p>
|
|
{item.cancelRequested && <p className="text-sm">Cancellation requested</p>}
|
|
<p className="text-xs text-text-secondary">Created {item.createdAt}</p>
|
|
</article>
|
|
))}
|
|
</section>
|
|
);
|
|
}
|