From 3491bf4463193711d724e822046dde299a4d3427 Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Sat, 21 Mar 2026 20:26:55 -0400 Subject: [PATCH] Add debug logging for branching flow --- src/components/trials/wizard/WizardInterface.tsx | 15 ++++++++++++++- .../trials/wizard/panels/WizardActionItem.tsx | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/trials/wizard/WizardInterface.tsx b/src/components/trials/wizard/WizardInterface.tsx index ce9b3ae..94f8add 100755 --- a/src/components/trials/wizard/WizardInterface.tsx +++ b/src/components/trials/wizard/WizardInterface.tsx @@ -579,11 +579,14 @@ export const WizardInterface = React.memo(function WizardInterface({ }; const handleNextStep = (targetIndex?: number) => { + console.log(`[DEBUG] handleNextStep called: targetIndex=${targetIndex}, currentStepIndex=${currentStepIndex}`); + console.log(`[DEBUG] Steps: ${steps.map((s, i) => `${i}:${s.name}`).join(' | ')}`); + // If explicit target provided (from branching choice), use it if (typeof targetIndex === "number") { // Find step by index to ensure safety if (targetIndex >= 0 && targetIndex < steps.length) { - console.log(`[WizardInterface] Manual jump to step ${targetIndex}`); + console.log(`[WizardInterface] Manual jump to step ${targetIndex} (${steps[targetIndex]?.name})`); // Log manual jump logEventMutation.mutate({ @@ -609,6 +612,8 @@ export const WizardInterface = React.memo(function WizardInterface({ return next; }); return; + } else { + console.warn(`[DEBUG] Invalid targetIndex: ${targetIndex}, steps.length=${steps.length}`); } } @@ -863,13 +868,21 @@ export const WizardInterface = React.memo(function WizardInterface({ if (parameters.nextStepId) { const nextId = String(parameters.nextStepId); const targetIndex = steps.findIndex((s) => s.id === nextId); + console.log(`[DEBUG] Branch choice: value=${parameters.value}, label=${parameters.label}`); + console.log(`[DEBUG] Target step ID: ${nextId}`); + console.log(`[DEBUG] Target index in steps array: ${targetIndex}`); + console.log(`[DEBUG] Available step IDs: ${steps.map(s => s.id).join(', ')}`); if (targetIndex !== -1) { console.log( `[WizardInterface] Choice-based jump to step ${targetIndex} (${nextId})`, ); handleNextStep(targetIndex); return; // Exit after jump + } else { + console.warn(`[DEBUG] Target step not found! nextStepId=${nextId}`); } + } else { + console.warn(`[DEBUG] No nextStepId in parameters!`, parameters); } } diff --git a/src/components/trials/wizard/panels/WizardActionItem.tsx b/src/components/trials/wizard/panels/WizardActionItem.tsx index 8fe9526..8ac25cd 100644 --- a/src/components/trials/wizard/panels/WizardActionItem.tsx +++ b/src/components/trials/wizard/panels/WizardActionItem.tsx @@ -535,6 +535,7 @@ export function WizardActionItem({ className="hover:border-primary hover:bg-primary/5 h-auto justify-start px-4 py-3 text-left" onClick={(e) => { e.preventDefault(); + console.log(`[DEBUG WizardActionItem] Choice clicked: actionId=${action.id}, value=${value}, label=${label}, nextStepId=${nextStepId}`); onExecute(action.id, { value, label, nextStepId }); // Don't call onCompleted() here - the branching logic in handleWizardResponse // will handle the jump and reset completedActionsCount