Skip to content

Commit fcb4afd

Browse files
jiajunagentclaude
andcommitted
Wire frontend Wizard to backend API (Step 11)
- analysis-store: add analysisId, isRunning, runError state - wizard-shell: onSubmit calls uploadFiles → startAnalysis → navigate to results - Passes all wizard params (peak detection, stats, annotation, pathway) to API Frontend → Backend → Engine data flow is now complete. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent df1ea4d commit fcb4afd

2 files changed

Lines changed: 78 additions & 4 deletions

File tree

packages/frontend/src/components/wizard/wizard-shell.tsx

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { useRouter } from 'next/navigation';
34
import { StepIndicator } from './step-indicator';
45
import { StepImport } from './steps/step-import';
56
import { StepPeak } from './steps/step-peak';
@@ -10,9 +11,16 @@ import { StepPathway } from './steps/step-pathway';
1011
import { StepExport } from './steps/step-export';
1112
import { useAnalysisStore } from '@/stores/analysis-store';
1213
import { Progress } from '@/components/ui/progress';
14+
import { uploadFiles, startAnalysis } from '@/lib/api';
1315

1416
export function WizardShell() {
15-
const { currentStep, nextStep, prevStep, setStep } = useAnalysisStore();
17+
const router = useRouter();
18+
const {
19+
currentStep, nextStep, prevStep, setStep,
20+
files, peakParams, selectedEngine, fcCutoff, pValueCutoff,
21+
databases, ms1Ppm, useSirius, pathwayWorkflows, organism,
22+
isRunning, setIsRunning, setAnalysisId, setRunError,
23+
} = useAnalysisStore();
1624

1725
const progressPercent = Math.round(((currentStep - 1) / 6) * 100);
1826

@@ -45,9 +53,52 @@ export function WizardShell() {
4553
{currentStep === 7 && (
4654
<StepExport
4755
onBack={prevStep}
48-
onSubmit={() => {
49-
// TODO: hook up to startAnalysis API
50-
alert('Analysis submitted! (API integration pending)');
56+
onSubmit={async () => {
57+
try {
58+
setIsRunning(true);
59+
setRunError(null);
60+
61+
// Step 1: Upload files
62+
const uploadedPaths = await uploadFiles(files);
63+
64+
// Step 2: Start analysis with all wizard parameters
65+
const { id } = await startAnalysis({
66+
peak_detection: {
67+
engine: selectedEngine ?? 'xcms',
68+
ppm: peakParams.ppm,
69+
peakwidth_min: peakParams.peakwidthMin,
70+
peakwidth_max: peakParams.peakwidthMax,
71+
snthresh: peakParams.snthresh,
72+
noise: peakParams.noise,
73+
polarity: 'positive',
74+
deconv_method: 'camera',
75+
},
76+
statistics: {
77+
analysis_type: 'differential',
78+
fc_cutoff: fcCutoff,
79+
p_value_cutoff: pValueCutoff,
80+
fdr_method: 'BH',
81+
},
82+
annotation: {
83+
databases,
84+
ms1_ppm: ms1Ppm,
85+
use_sirius: useSirius,
86+
},
87+
pathway: {
88+
workflows: pathwayWorkflows,
89+
organism,
90+
},
91+
file_paths: uploadedPaths,
92+
});
93+
94+
setAnalysisId(id);
95+
96+
// Navigate to results page with SSE progress tracking
97+
router.push(`/analysis/${id}`);
98+
} catch (err) {
99+
setRunError(err instanceof Error ? err.message : 'Unknown error');
100+
setIsRunning(false);
101+
}
51102
}}
52103
/>
53104
)}

packages/frontend/src/stores/analysis-store.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ interface AnalysisState {
9696
toggleChartType: (type: string) => void;
9797
setExportFormat: (format: ExportFormat) => void;
9898

99+
// Analysis execution state
100+
analysisId: string | null;
101+
isRunning: boolean;
102+
runError: string | null;
103+
104+
// Actions - Execution
105+
setAnalysisId: (id: string | null) => void;
106+
setIsRunning: (running: boolean) => void;
107+
setRunError: (error: string | null) => void;
108+
99109
// Reset
100110
reset: () => void;
101111
}
@@ -140,6 +150,11 @@ export const useAnalysisStore = create<AnalysisState>()(
140150
chartTypes: ['Volcano', 'PCA', 'Heatmap'],
141151
exportFormat: 'PDF',
142152

153+
// Execution state
154+
analysisId: null,
155+
isRunning: false,
156+
runError: null,
157+
143158
// Navigation actions
144159
setStep: (step) =>
145160
set({ currentStep: Math.max(1, Math.min(TOTAL_STEPS, step)) }),
@@ -211,6 +226,11 @@ export const useAnalysisStore = create<AnalysisState>()(
211226
})),
212227
setExportFormat: (exportFormat) => set({ exportFormat }),
213228

229+
// Execution actions
230+
setAnalysisId: (analysisId) => set({ analysisId }),
231+
setIsRunning: (isRunning) => set({ isRunning }),
232+
setRunError: (runError) => set({ runError }),
233+
214234
// Reset
215235
reset: () =>
216236
set({
@@ -233,6 +253,9 @@ export const useAnalysisStore = create<AnalysisState>()(
233253
sigThreshold: 0.05,
234254
chartTypes: ['Volcano', 'PCA', 'Heatmap'],
235255
exportFormat: 'PDF',
256+
analysisId: null,
257+
isRunning: false,
258+
runError: null,
236259
}),
237260
}),
238261
{ name: 'MetaboFlow-Analysis' }

0 commit comments

Comments
 (0)