fix(web): make backtest run controls and selection reliable

This commit is contained in:
Boki 2026-10-22 14:17:25 -04:00
parent 3d26da07f5
commit 67f12b49a0
8 changed files with 1109 additions and 675 deletions

View file

@ -1,102 +1,55 @@
import { ArrowPathIcon, ForwardIcon, PauseIcon, PlayIcon } from '@heroicons/react/24/solid';
import { ArrowPathIcon, StopIcon } from '@heroicons/react/24/solid';
import type { Run } from '../services/backtestApiV2';
interface RunControlsCompactProps {
run: Run;
onPause: () => void;
onResume: () => void;
cancelRequested: boolean;
onCancel: () => void;
onRerun: (speed: number | null) => void;
onNext?: () => void;
onSpeedChange: (speed: number | null) => void;
}
export function RunControlsCompact({
run,
onPause,
onResume,
cancelRequested,
onCancel,
onRerun,
onNext,
}: RunControlsCompactProps) {
const isRunning = run.status === 'running';
const isPaused = run.status === 'paused';
const _isCompleted =
run.status === 'completed' || run.status === 'failed' || run.status === 'cancelled';
const active = ['pending', 'running', 'paused'].includes(run.status);
const requested = active && (cancelRequested || run.cancelRequested);
return (
<div className="flex items-center space-x-3">
{/* Progress */}
<div className="flex items-center space-x-2">
<span className="text-xs text-text-secondary">Progress:</span>
<div className="w-24 bg-background rounded-full h-2 overflow-hidden">
<div
className="bg-primary-500 h-2 transition-all duration-300 relative"
style={{ width: `${run.progress}%` }}
>
<div className="absolute inset-0 bg-gradient-to-r from-primary-500 to-primary-400 opacity-50"></div>
</div>
</div>
<progress className="w-24 h-2" max={100} value={run.progress} aria-label="Run progress" />
<span className="text-xs text-text-primary font-medium">{run.progress.toFixed(0)}%</span>
</div>
{/* Control Buttons */}
<div className="flex items-center space-x-1">
{isRunning ? (
{active && (
<button
onClick={onPause}
className="p-1 rounded hover:bg-surface-tertiary transition-colors"
title="Pause"
>
<PauseIcon className="w-4 h-4 text-text-primary" />
</button>
) : isPaused ? (
<button
onClick={onResume}
className="p-1 rounded hover:bg-surface-tertiary transition-colors"
title="Resume"
>
<PlayIcon className="w-4 h-4 text-text-primary" />
</button>
) : null}
{onNext && (
<button
onClick={onNext}
onClick={onCancel}
disabled={Boolean(requested)}
className="p-1 rounded hover:bg-surface-tertiary transition-colors disabled:opacity-50"
disabled={!isRunning && !isPaused}
title="Next"
title={requested ? 'Cancellation requested' : 'Cancel run'}
aria-label={requested ? 'Cancellation requested' : 'Cancel run'}
>
<ForwardIcon className="w-4 h-4 text-text-primary" />
<StopIcon className="w-4 h-4 text-text-primary" />
</button>
)}
<button
onClick={() => onRerun(null)} // Always use max speed
onClick={() => onRerun(null)}
className="p-1 rounded hover:bg-surface-tertiary transition-colors"
title="Rerun"
aria-label="Rerun"
>
<ArrowPathIcon className="w-4 h-4 text-text-primary" />
</button>
</div>
{/* Status Indicator */}
{run.status !== 'running' && run.status !== 'paused' && (
<>
<div className="h-6 w-px bg-border"></div>
<span
className={`text-xs font-medium ${
run.status === 'completed'
? 'text-success'
: run.status === 'failed'
? 'text-error'
: run.status === 'cancelled'
? 'text-text-secondary'
: 'text-text-primary'
}`}
>
{run.status.charAt(0).toUpperCase() + run.status.slice(1)}
</span>
</>
)}
<span role="status" className="text-xs font-medium text-text-primary">
{requested
? 'Cancellation requested'
: run.status.charAt(0).toUpperCase() + run.status.slice(1)}
</span>
</div>
);
}