2026-03-23 22:32:33 +00:00
|
|
|
/**
|
|
|
|
|
* SchoolRow Component
|
2026-03-29 08:57:06 +01:00
|
|
|
* Four-line row for primary school search results
|
2026-03-24 09:27:22 +00:00
|
|
|
*
|
2026-04-13 13:59:26 +01:00
|
|
|
* Line 1: School name · Ofsted badge (framework-aware)
|
2026-03-29 08:57:06 +01:00
|
|
|
* Line 2: School type · Age range · Denomination · Gender
|
2026-04-13 13:59:26 +01:00
|
|
|
* Line 3: Reading, Writing & Maths % · trend arrow · vs-national delta · Pupils
|
|
|
|
|
* Line 4: Local authority · Distance
|
2026-03-23 22:32:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type { School } from '@/lib/types';
|
2026-07-20 20:39:16 +01:00
|
|
|
import { formatPercentage, calculateTrend, getPhaseStyle, schoolUrl, buildOfstedListBadge, formatAgeRange, isProposedToClose, isSpecialSchool } from '@/lib/utils';
|
2026-03-23 22:32:33 +00:00
|
|
|
import styles from './SchoolRow.module.css';
|
|
|
|
|
|
|
|
|
|
interface SchoolRowProps {
|
|
|
|
|
school: School;
|
|
|
|
|
isLocationSearch?: boolean;
|
|
|
|
|
isInCompare?: boolean;
|
|
|
|
|
onAddToCompare?: (school: School) => void;
|
|
|
|
|
onRemoveFromCompare?: (urn: number) => void;
|
2026-04-13 13:59:26 +01:00
|
|
|
nationalAvgRwm?: number | null;
|
2026-03-23 22:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SchoolRow({
|
|
|
|
|
school,
|
|
|
|
|
isLocationSearch,
|
|
|
|
|
isInCompare = false,
|
|
|
|
|
onAddToCompare,
|
|
|
|
|
onRemoveFromCompare,
|
2026-04-13 13:59:26 +01:00
|
|
|
nationalAvgRwm,
|
2026-03-23 22:32:33 +00:00
|
|
|
}: SchoolRowProps) {
|
|
|
|
|
const trend = calculateTrend(school.rwm_expected_pct, school.prev_rwm_expected_pct);
|
2026-04-01 15:47:51 +01:00
|
|
|
const phase = getPhaseStyle(school.phase);
|
2026-04-13 13:59:26 +01:00
|
|
|
const ofstedBadge = buildOfstedListBadge(school);
|
2026-03-23 22:32:33 +00:00
|
|
|
|
2026-04-13 13:59:26 +01:00
|
|
|
const showGender = school.gender && school.gender.toLowerCase() !== 'mixed';
|
|
|
|
|
const showDenomination =
|
|
|
|
|
school.religious_denomination &&
|
|
|
|
|
school.religious_denomination !== 'Does not apply';
|
|
|
|
|
|
2026-07-20 22:09:32 +01:00
|
|
|
// A placeholder all-zero row (every subject 0 — a special/suppressed
|
|
|
|
|
// signature, matching SchoolDetailView's ks2Placeholder) isn't a real score,
|
|
|
|
|
// so its figure is hidden. A genuine 0% combined (some pupils met individual
|
|
|
|
|
// subjects but not all three) is NOT all-zero and stays shown.
|
2026-07-20 21:58:13 +01:00
|
|
|
const rwmPlaceholder =
|
|
|
|
|
school.rwm_expected_pct === 0 &&
|
|
|
|
|
(school.reading_expected_pct ?? 0) === 0 &&
|
|
|
|
|
(school.writing_expected_pct ?? 0) === 0 &&
|
|
|
|
|
(school.maths_expected_pct ?? 0) === 0;
|
2026-07-20 22:09:32 +01:00
|
|
|
// The school's OWN figure and its year-over-year trend are same-school
|
|
|
|
|
// measures — shown whenever there's a real value, special schools included.
|
|
|
|
|
const showRwmValue = school.rwm_expected_pct != null && !rwmPlaceholder;
|
|
|
|
|
// The vs-England delta is a mainstream benchmark: additionally dropped for
|
|
|
|
|
// special schools / PRUs / AP, whose pupils aren't measured against it fairly.
|
2026-04-13 13:59:26 +01:00
|
|
|
const rwmDelta =
|
2026-07-20 22:09:32 +01:00
|
|
|
showRwmValue && !isSpecialSchool(school) && nationalAvgRwm != null
|
2026-07-20 20:39:16 +01:00
|
|
|
? Math.round((school.rwm_expected_pct as number) - nationalAvgRwm)
|
2026-04-13 13:59:26 +01:00
|
|
|
: null;
|
2026-03-23 22:32:33 +00:00
|
|
|
|
|
|
|
|
const handleCompareClick = () => {
|
|
|
|
|
if (isInCompare) {
|
|
|
|
|
onRemoveFromCompare?.(school.urn);
|
|
|
|
|
} else {
|
|
|
|
|
onAddToCompare?.(school);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-04-01 15:47:51 +01:00
|
|
|
<div className={`${styles.row} ${phase.key ? styles[`phase${phase.key}`] : ''} ${isInCompare ? styles.rowInCompare : ''}`}>
|
2026-03-29 08:57:06 +01:00
|
|
|
{/* Left: four content lines */}
|
2026-03-24 09:27:22 +00:00
|
|
|
<div className={styles.rowContent}>
|
2026-03-23 22:32:33 +00:00
|
|
|
|
2026-03-29 08:57:06 +01:00
|
|
|
{/* Line 1: School name + Ofsted badge */}
|
2026-03-24 09:27:22 +00:00
|
|
|
<div className={styles.line1}>
|
2026-03-29 14:15:06 +01:00
|
|
|
<a href={schoolUrl(school.urn, school.school_name)} className={styles.schoolName}>
|
2026-03-24 09:27:22 +00:00
|
|
|
{school.school_name}
|
|
|
|
|
</a>
|
2026-04-13 13:59:26 +01:00
|
|
|
<span className={`${styles.ofstedBadge} ${styles[ofstedBadge.cssClass]}`}>
|
|
|
|
|
{ofstedBadge.label}
|
|
|
|
|
</span>
|
2026-03-23 22:32:33 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-29 08:57:06 +01:00
|
|
|
{/* Line 2: Context tags */}
|
2026-03-24 09:27:22 +00:00
|
|
|
<div className={styles.line2}>
|
2026-04-01 15:47:51 +01:00
|
|
|
{phase.label && (
|
|
|
|
|
<span className={`${styles.phaseLabel} ${styles[`phaseLabel${phase.key}`]}`}>
|
|
|
|
|
{phase.label}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2026-07-02 09:22:33 +01:00
|
|
|
{school.school_type && <span className={styles.attr}>{school.school_type}</span>}
|
|
|
|
|
{school.age_range && <span className={styles.attr}>{formatAgeRange(school.age_range)}</span>}
|
|
|
|
|
{showDenomination && <span className={styles.attr}>{school.religious_denomination}</span>}
|
|
|
|
|
{showGender && <span className={styles.attr}>{school.gender}</span>}
|
2026-07-08 22:05:55 +01:00
|
|
|
{isProposedToClose(school) && (
|
|
|
|
|
<span className={`${styles.attr} ${styles.attrClosing}`}>⚠ Proposed to close</span>
|
|
|
|
|
)}
|
2026-03-29 08:57:06 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Line 3: Key stats */}
|
|
|
|
|
<div className={styles.line3}>
|
2026-04-13 13:59:26 +01:00
|
|
|
<span className={styles.stat}>
|
|
|
|
|
<strong className={styles.statValue}>
|
2026-07-20 22:09:32 +01:00
|
|
|
{showRwmValue ? formatPercentage(school.rwm_expected_pct, 0) : '—'}
|
2026-04-13 13:59:26 +01:00
|
|
|
</strong>
|
2026-07-20 22:09:32 +01:00
|
|
|
{showRwmValue && school.prev_rwm_expected_pct != null && (
|
2026-04-13 13:59:26 +01:00
|
|
|
<span
|
|
|
|
|
className={`${styles.trend} ${styles[`trend${trend.charAt(0).toUpperCase() + trend.slice(1)}`]}`}
|
|
|
|
|
title={`Previous year: ${formatPercentage(school.prev_rwm_expected_pct)}`}
|
|
|
|
|
>
|
|
|
|
|
{trend === 'up' && (
|
|
|
|
|
<svg viewBox="0 0 16 16" fill="none" width="9" height="9" aria-label="Trend up">
|
|
|
|
|
<path d="M8 3L14 10H2L8 3Z" fill="currentColor" />
|
|
|
|
|
</svg>
|
|
|
|
|
)}
|
|
|
|
|
{trend === 'down' && (
|
|
|
|
|
<svg viewBox="0 0 16 16" fill="none" width="9" height="9" aria-label="Trend down">
|
|
|
|
|
<path d="M8 13L2 6H14L8 13Z" fill="currentColor" />
|
|
|
|
|
</svg>
|
|
|
|
|
)}
|
|
|
|
|
{trend === 'stable' && (
|
|
|
|
|
<svg viewBox="0 0 16 16" fill="none" width="9" height="9" aria-label="Trend stable">
|
|
|
|
|
<rect x="2" y="7" width="12" height="2" rx="1" fill="currentColor" />
|
|
|
|
|
</svg>
|
|
|
|
|
)}
|
2026-03-24 09:27:22 +00:00
|
|
|
</span>
|
2026-04-13 13:59:26 +01:00
|
|
|
)}
|
|
|
|
|
<span className={styles.statLabel}>Reading, Writing & Maths</span>
|
|
|
|
|
{rwmDelta != null && (
|
|
|
|
|
<span
|
|
|
|
|
className={
|
|
|
|
|
rwmDelta >= 2
|
|
|
|
|
? styles.vsNational
|
|
|
|
|
: rwmDelta <= -2
|
|
|
|
|
? styles.vsNationalNeg
|
|
|
|
|
: styles.vsNationalFlat
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{rwmDelta >= 2
|
|
|
|
|
? `+${rwmDelta} pts vs national`
|
|
|
|
|
: rwmDelta <= -2
|
|
|
|
|
? `${rwmDelta} pts vs national`
|
|
|
|
|
: '≈ national avg'}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
2026-03-24 09:27:22 +00:00
|
|
|
|
|
|
|
|
{school.total_pupils != null && (
|
|
|
|
|
<span className={styles.stat}>
|
|
|
|
|
<strong className={styles.statValue}>{school.total_pupils.toLocaleString()}</strong>
|
|
|
|
|
<span className={styles.statLabel}>pupils</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-29 08:57:06 +01:00
|
|
|
{/* Line 4: Location + distance */}
|
|
|
|
|
<div className={styles.line4}>
|
2026-03-24 09:27:22 +00:00
|
|
|
{school.local_authority && (
|
|
|
|
|
<span>{school.local_authority}</span>
|
|
|
|
|
)}
|
2026-03-23 22:32:33 +00:00
|
|
|
{isLocationSearch && school.distance != null && (
|
|
|
|
|
<span className={styles.distanceBadge}>
|
2026-03-23 22:39:50 +00:00
|
|
|
{school.distance.toFixed(1)} mi
|
2026-03-23 22:32:33 +00:00
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-24 09:27:22 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Right: actions, vertically centred */}
|
|
|
|
|
<div className={styles.rowActions}>
|
2026-03-29 14:15:06 +01:00
|
|
|
<a href={schoolUrl(school.urn, school.school_name)} className="btn btn-tertiary btn-sm">
|
2026-03-24 09:27:22 +00:00
|
|
|
View
|
|
|
|
|
</a>
|
|
|
|
|
{(onAddToCompare || onRemoveFromCompare) && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleCompareClick}
|
2026-03-25 20:28:03 +00:00
|
|
|
className={isInCompare ? 'btn btn-active btn-sm' : 'btn btn-secondary btn-sm'}
|
2026-03-24 09:27:22 +00:00
|
|
|
>
|
2026-03-25 20:28:03 +00:00
|
|
|
{isInCompare ? '✓ Comparing' : '+ Compare'}
|
2026-03-24 09:27:22 +00:00
|
|
|
</button>
|
2026-03-23 22:32:33 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|