Skip to content

Commit 4a040b4

Browse files
Copilotankurrera
andcommitted
Add comprehensive debug logging and visibility for reactive data flow
Co-authored-by: ankurrera <186232326+ankurrera@users.noreply.github.com>
1 parent 8e5f7b6 commit 4a040b4

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

src/components/system/RadarChart.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ const RadarChart = () => {
171171

172172
const ctx = canvas.getContext("2d");
173173
if (!ctx) return;
174+
175+
// Debug logging: Log radar re-renders
176+
if (process.env.NODE_ENV === 'development') {
177+
console.log('[Radar Chart] Re-rendering with data:', {
178+
dataPoints: data.length,
179+
timestamp: new Date().toISOString(),
180+
sampleMetrics: data.slice(0, 3).map(d => ({ label: d.label, value: d.value })),
181+
});
182+
}
174183

175184
const centerX = canvas.width / 2;
176185
const centerY = canvas.height / 2;
@@ -295,6 +304,22 @@ const RadarChart = () => {
295304
<div className="text-xs uppercase tracking-[0.2em]" style={titleStyle}>PHYSICAL BALANCE</div>
296305
</div>
297306

307+
{/* Debug Panel - Only in Development */}
308+
{process.env.NODE_ENV === 'development' && (
309+
<div className="mb-4 p-3 bg-blue-50 border border-blue-200 rounded text-xs">
310+
<div className="font-semibold text-blue-900 mb-2">🔍 Debug Info</div>
311+
<div className="space-y-1 text-blue-700">
312+
<div>Radar Points: {data.length}</div>
313+
<div>Core Metrics: {coreMetrics.length}</div>
314+
<div>Total Contributing Skills: {coreMetrics.reduce((sum, m) => sum + m.contributions.length, 0)}</div>
315+
<div>Non-Zero Metrics: {coreMetrics.filter(m => m.xp > 0).length}</div>
316+
<div className="text-blue-500 text-[10px] mt-2">
317+
Click metrics to see contributors
318+
</div>
319+
</div>
320+
</div>
321+
)}
322+
298323
{isLoading ? (
299324
<div className="flex items-center justify-center h-[400px]">
300325
<div className="w-8 h-8 border-2 border-gray-300 border-t-gray-600 rounded-full animate-spin" />

src/hooks/useCoreMetrics.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,46 @@ export function useCoreMetrics(): UseCoreMetricsResult {
150150

151151
// Compute all Core Metrics (this is the main calculation)
152152
const coreMetrics = useMemo(() => {
153-
return computeAllCoreMetrics(skillContributions, characteristicContributions);
153+
const metrics = computeAllCoreMetrics(skillContributions, characteristicContributions);
154+
155+
// Debug logging: Log recomputation of metrics
156+
if (process.env.NODE_ENV === 'development') {
157+
console.log('[Core Metrics] Recomputed from skills:', {
158+
skillCount: skillContributions.length,
159+
charCount: characteristicContributions.length,
160+
metricsCount: metrics.length,
161+
totalXP: metrics.reduce((sum, m) => sum + m.xp, 0),
162+
timestamp: new Date().toISOString(),
163+
});
164+
}
165+
166+
return metrics;
154167
}, [skillContributions, characteristicContributions]);
155168

156169
// Get radar chart data (clamped to MAX_METRIC_XP)
157170
const radarData = useMemo(() => {
158-
return getRadarChartData(coreMetrics);
171+
const data = getRadarChartData(coreMetrics);
172+
173+
// Debug logging: Verify radar data matches core metrics
174+
if (process.env.NODE_ENV === 'development') {
175+
console.log('[Radar Data] Updated:', {
176+
radarPoints: data.length,
177+
coreMetricsCount: coreMetrics.length,
178+
match: data.length === coreMetrics.length,
179+
sampleMetric: data[0]?.label,
180+
sampleValue: data[0]?.value,
181+
});
182+
183+
// Assert that radar data length matches core metrics length
184+
if (data.length !== coreMetrics.length) {
185+
console.error('[CRITICAL] Radar data length mismatch!', {
186+
expected: coreMetrics.length,
187+
actual: data.length,
188+
});
189+
}
190+
}
191+
192+
return data;
159193
}, [coreMetrics]);
160194

161195
// Calculate aggregate stats

src/hooks/useSkills.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export const useSkills = () => {
108108
return data as Skill;
109109
},
110110
onSuccess: () => {
111+
if (process.env.NODE_ENV === 'development') {
112+
console.log('[Skills CRUD] Skill created - invalidating queries');
113+
}
111114
queryClient.invalidateQueries({ queryKey: ['skills'] });
112115
toast.success('Skill created successfully!');
113116
},
@@ -134,6 +137,9 @@ export const useSkills = () => {
134137
return data as Skill;
135138
},
136139
onSuccess: () => {
140+
if (process.env.NODE_ENV === 'development') {
141+
console.log('[Skills CRUD] Skill updated - invalidating queries');
142+
}
137143
queryClient.invalidateQueries({ queryKey: ['skills'] });
138144
toast.success('Skill updated successfully!');
139145
},
@@ -157,6 +163,9 @@ export const useSkills = () => {
157163
if (error) throw error;
158164
},
159165
onSuccess: () => {
166+
if (process.env.NODE_ENV === 'development') {
167+
console.log('[Skills CRUD] Skill deleted - invalidating queries');
168+
}
160169
queryClient.invalidateQueries({ queryKey: ['skills'] });
161170
toast.success('Skill deleted successfully');
162171
},

0 commit comments

Comments
 (0)