fix(research): preserve settings and capture across tabs (RP06)

This commit is contained in:
Boki 2026-10-27 09:31:46 -04:00
parent 6d549542a9
commit c838e3d05a
4 changed files with 405 additions and 46 deletions

View file

@ -36,6 +36,8 @@ export function BacktestDetailPageV2() {
const [showFinding, setShowFinding] = useState(false);
const [showArchiveDialog, setShowArchiveDialog] = useState(false);
const [showCanonicalSetup, setShowCanonicalSetup] = useState(false);
// A visited editor owns drafts and captured dataset retries until this backtest changes.
const [settingsOwner, setSettingsOwner] = useState<string | null>(null);
const navigationGeneration = useRef(0);
const {
@ -95,13 +97,18 @@ export function BacktestDetailPageV2() {
navigationGeneration.current++;
setShowNewRun(false);
setShowArchiveDialog(false);
setShowCanonicalSetup(false);
setShowFinding(false);
return () => {
navigationGeneration.current++;
};
}, [id, runId]);
useEffect(() => {
setSettingsOwner(null);
setShowCanonicalSetup(false);
setActiveTab('runs');
}, [id]);
useEffect(() => {
if (id) {
void loadBacktest(id);
@ -217,6 +224,44 @@ export function BacktestDetailPageV2() {
[backtest]
);
const renderSettings = () => (
<div className="max-w-4xl mx-auto space-y-4">
{catalog && backtest && (showCanonicalSetup || backtest.config.canonical) ? (
<CanonicalSetup
key={backtest.id}
backtest={backtest}
disabled={archived || isLoading}
onSave={request => updateBacktest(backtest.id, request)}
onClose={!backtest.config.canonical ? () => setShowCanonicalSetup(false) : undefined}
/>
) : (
<>
{catalog && (
<div className="space-y-2">
<p className="text-sm text-text-secondary">
This draft is not configured for canonical execution. Select an eligible retained
dataset and inspect the simulation policy before running.
</p>
<button
type="button"
className="px-3 py-2 border border-border rounded-md text-primary-500 disabled:opacity-50"
disabled={archived || isLoading}
onClick={() => setShowCanonicalSetup(true)}
>
Configure canonical research
</button>
</div>
)}
<BacktestConfiguration
onSubmit={handleConfigSubmit}
disabled={archived || isLoading}
initialConfig={backtestConfig}
/>
</>
)}
</div>
);
const renderTabContent = () => {
if (['details', 'trades'].includes(activeTab)) {
if (isLoading) {
@ -329,46 +374,6 @@ export function BacktestDetailPageV2() {
/>
</div>
);
case 'settings':
return (
<div className="max-w-4xl mx-auto space-y-4">
{catalog && backtest && (showCanonicalSetup || backtest.config.canonical) ? (
<CanonicalSetup
key={backtest.id}
backtest={backtest}
disabled={archived || isLoading}
onSave={request => updateBacktest(backtest.id, request)}
onClose={
!backtest.config.canonical ? () => setShowCanonicalSetup(false) : undefined
}
/>
) : (
<>
{catalog && (
<div className="space-y-2">
<p className="text-sm text-text-secondary">
This draft is not configured for canonical execution. Select an eligible
retained dataset and inspect the simulation policy before running.
</p>
<button
type="button"
className="px-3 py-2 border border-border rounded-md text-primary-500 disabled:opacity-50"
disabled={archived || isLoading}
onClick={() => setShowCanonicalSetup(true)}
>
Configure canonical research
</button>
</div>
)}
<BacktestConfiguration
onSubmit={handleConfigSubmit}
disabled={archived || isLoading}
initialConfig={backtestConfig}
/>
</>
)}
</div>
);
case 'details':
// Only render if we have matching results or no results yet
if (runResults && currentRun && runResults.runId !== currentRun.id) {
@ -462,7 +467,12 @@ export function BacktestDetailPageV2() {
{(currentRun ? runTabs : []).concat(baseTabs).map(tab => (
<button
key={tab.id}
onClick={() => setActiveTab(tab.id)}
onClick={() => {
if (tab.id === 'settings' && id) {
setSettingsOwner(id);
}
setActiveTab(tab.id);
}}
className={`
whitespace-nowrap py-2 px-3 border-b-2 font-medium text-sm
${
@ -621,7 +631,12 @@ export function BacktestDetailPageV2() {
currentRun.id === runId &&
currentRun.backtestId === id &&
backtest?.id === id && <RunReproduction run={currentRun} archived={archived} />}
{renderTabContent()}
{settingsOwner === id && backtest?.id === id && (
<div key={id} hidden={activeTab !== 'settings'} aria-label="Backtest settings panel">
{renderSettings()}
</div>
)}
{activeTab !== 'settings' && renderTabContent()}
</div>
</div>
{showFinding && findingResult && (