fix(compare): auto-phase tab now also syncs metric to match detected phase
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 18s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 55s
Build and Push Docker Images / Build Pipeline (Meltano + dbt + Airflow) (push) Successful in 12s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 18s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 55s
Build and Push Docker Images / Build Pipeline (Meltano + dbt + Airflow) (push) Successful in 12s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s
The useEffect that auto-selects the Primary/Secondary tab was calling setComparePhase() without updating selectedMetric. When a URL carries a primary metric (e.g. metric=rwm_expected_pct) but the shortlisted schools are secondary, the tab would switch to Secondary while the metric stayed at rwm_expected_pct — which is null for all secondary schools, causing every card to show "–" and requiring a manual tab toggle to fix. Fix: after determining the phase from school data, check whether the current metric belongs to that phase's category list. If not, reset to the phase default (attainment_8_score for secondary, rwm_expected_pct for primary). A metric that already fits the phase (e.g. the URL already carried attainment_8_score) is preserved unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -118,14 +118,22 @@ export function ComparisonView({
|
|||||||
const primarySchools = selectedSchools.filter(s => classifySchool(s) === 'primary');
|
const primarySchools = selectedSchools.filter(s => classifySchool(s) === 'primary');
|
||||||
const secondarySchools = selectedSchools.filter(s => classifySchool(s) === 'secondary');
|
const secondarySchools = selectedSchools.filter(s => classifySchool(s) === 'secondary');
|
||||||
|
|
||||||
// Auto-select tab with more schools
|
// Auto-select tab with more schools and sync the metric to match the detected phase.
|
||||||
|
// This fixes the case where the URL carries a primary metric (e.g. rwm_expected_pct)
|
||||||
|
// but the shortlisted schools are secondary — the phase tab switches but the metric
|
||||||
|
// needs to follow, otherwise all secondary cards show "–" for a primary-only field.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (comparisonData && selectedSchools.length > 0) {
|
if (!comparisonData || selectedSchools.length === 0) return;
|
||||||
if (secondarySchools.length > primarySchools.length) {
|
const newPhase = secondarySchools.length > primarySchools.length ? 'secondary' : 'primary';
|
||||||
setComparePhase('secondary');
|
setComparePhase(newPhase);
|
||||||
} else {
|
// Only reset the metric when it doesn't belong to the newly detected phase.
|
||||||
setComparePhase('primary');
|
// This preserves a correct metric that came from the URL (e.g. metric=attainment_8_score).
|
||||||
}
|
const phaseCategories = newPhase === 'secondary' ? SECONDARY_CATEGORIES : PRIMARY_CATEGORIES;
|
||||||
|
const metricFitsPhase = metrics.some(
|
||||||
|
(m) => m.key === selectedMetric && phaseCategories.includes(m.category)
|
||||||
|
);
|
||||||
|
if (!metricFitsPhase) {
|
||||||
|
setSelectedMetric(newPhase === 'secondary' ? 'attainment_8_score' : 'rwm_expected_pct');
|
||||||
}
|
}
|
||||||
}, [comparisonData]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [comparisonData]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user