/** * One place page, shared by all four families. * * They differ in what fills the registry, not in what the page shows, so a * second component would be a second place to forget the same change. * * The local-versus-England comparison is the reason this page is not a list: * it is the one number a parent cannot get by reading the schools one by one, * and it is what keeps the page from reading as a name dropped into a * template. */ import Link from 'next/link'; import type { PlaceDetail, PlaceSummary } from '@/lib/places'; import { placeUrl, authoritySlug } from '@/lib/places'; import type { School } from '@/lib/types'; import { schoolUrl, formatAgeSpan } from '@/lib/utils'; import { absoluteUrl } from '@/lib/site'; import { TrackPlaceView } from './TrackPlaceView'; import styles from './PlaceView.module.css'; interface Props { detail: PlaceDetail; phase?: 'primary' | 'secondary'; englandAverage: number | null; /** Nearby places, so the page links onward instead of dead-ending. */ neighbours: PlaceSummary[]; } // Ofsted grades in the order they are reported. const OFSTED_LABELS: Array<[number, string]> = [ [1, 'Outstanding'], [2, 'Good'], [3, 'Requires improvement'], [4, 'Inadequate'], ]; /** * Column headings, taken from the site's own metric dictionary rather than * invented here — see METRIC_DEFINITIONS in backend/schemas.py, surfaced at * /api/metrics. The first cut said "RWM expected", which is jargon that * appears nowhere else on the site. */ const METRICS = { primary: { key: 'rwm_expected_pct' as const, heading: 'Reading, writing & maths', hint: '% meeting the expected standard in reading, writing and maths', unit: '%', }, secondary: { key: 'attainment_8_score' as const, heading: 'Attainment 8', hint: "Average grade across a pupil's best 8 GCSEs, including English and maths", unit: '', }, }; type PhaseKey = keyof typeof METRICS; /** All-through schools sit in both phases, matching the search filters. */ function isPhase(school: School, phase: PhaseKey): boolean { const p = (school.phase ?? '').toLowerCase(); if (p === 'all-through') return true; return phase === 'secondary' ? p.includes('secondary') || p === '16 plus' : p.includes('primary') || p.includes('middle'); } /* * GIAS spells the absence of a faith as "Does not apply", and sometimes * "None" or "Not applicable" — database answers, not English ones. The school * page and the comparison already suppress all three; this is the same rule, * so the two surfaces cannot disagree about the same school. */ const NO_FAITH = /^(none|does not apply|not applicable)$/i; /** An attribute the data does not carry. Distinct from the measure's "Not * published": four of those per row would drown the row it qualifies. */ const NO_VALUE = '—'; function faithOf(school: School): string { const denom = school.religious_denomination ?? ''; return denom && !NO_FAITH.test(denom) ? denom : NO_VALUE; } function SchoolTable({ schools, phase }: { schools: School[]; phase: PhaseKey }) { const metric = METRICS[phase]; /* * Nursery is a primary question. An all-through school renders in both * groups, and its nursery belongs to the primary reading of it — under * "Secondary schools" the column would be a fact about a different intake. */ const showNursery = phase === 'primary'; return (
| School | {/* Same class as the value cell below: one rule aligns both, so they cannot drift apart. */}{metric.heading} | {/* The measure sits second, not last. Six columns overflow a phone and .tableWrap turns that into a swipe; last would put the one number the page exists for off the screen. */}Ages | Religious character | {showNursery &&Nursery | }Constituency |
|---|---|---|---|---|---|
| {s.school_name} | {value == null ? Not published : `${Math.round(Number(value))}${metric.unit}`} | {formatAgeSpan(s.age_range) || NO_VALUE} | {faithOf(s)} | {showNursery && ({/* Undefined is a mart the pipeline has not rebuilt, and false is a school without one. Neither is a "Yes", and neither is worth two different words. */} {s.nursery_provision ? 'Yes' : NO_VALUE} | )}{s.parliamentary_constituency || NO_VALUE} |
{place.count} schools {authorities.length > 0 && ( <> {' · '} {/* Every authority, not just the largest. A quarter of outcodes and a third of towns cross a boundary: SW19 is mostly Merton but partly Wandsworth, and naming one asserts otherwise. */} {authorities.map((a, i) => ( {i > 0 && (i === authorities.length - 1 ? ' and ' : ', ')} {/* No slug means no page: City of London and the Isles of Scilly hold too few schools for one. Saying where the place is stays right; linking there would 404. */} {a.slug ? ( {a.name} ) : a.name} ))} > )}
{place.name} averages {Math.round(local)} against{' '} {Math.round(englandAverage)} across England.
)} {graded.length > 0 && (