Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3f21a5bc7 | ||
|
|
dea435a906 | ||
|
|
dd5b48e612 | ||
|
|
a88139a539 | ||
|
|
9b765125ad | ||
|
|
ccf0892a0e | ||
|
|
0450f8ecd6 | ||
|
|
27d83f9bd0 | ||
|
|
19c574edb0 |
No files matched your search
+10
-4
@@ -40,7 +40,7 @@ from .data_loader import (
|
||||
from .data_loader import get_data_info as get_db_info
|
||||
from . import flags
|
||||
from .places import build_place_index, build_place_registry, places_for_urn
|
||||
from .schemas import METRIC_DEFINITIONS, PHASE_GROUPS, RANKING_COLUMNS, SCHOOL_COLUMNS
|
||||
from .schemas import METRIC_DEFINITIONS, PHASE_GROUPS, PHASE_ORDER, RANKING_COLUMNS, SCHOOL_COLUMNS
|
||||
from .school_groups import (
|
||||
FAITH_GROUPS,
|
||||
FAITH_KEYS,
|
||||
@@ -381,6 +381,12 @@ def clean_filter_values(series: pd.Series) -> list[str]:
|
||||
)
|
||||
|
||||
|
||||
def order_phases(phases: list[str]) -> list[str]:
|
||||
"""Phases in the order a child meets them; any GIAS adds later follow, A-Z."""
|
||||
rank = {p: i for i, p in enumerate(PHASE_ORDER)}
|
||||
return sorted(phases, key=lambda p: (rank.get(p.lower(), len(rank)), p))
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# SECURITY MIDDLEWARE & HELPERS
|
||||
# =============================================================================
|
||||
@@ -937,7 +943,7 @@ async def get_schools(
|
||||
result_filters = {
|
||||
"local_authorities": clean_filter_values(schools_df["local_authority"]) if "local_authority" in schools_df.columns else [],
|
||||
"school_types": clean_filter_values(schools_df["school_type"]) if "school_type" in schools_df.columns else [],
|
||||
"phases": clean_filter_values(schools_df["phase"]) if "phase" in schools_df.columns else [],
|
||||
"phases": order_phases(clean_filter_values(schools_df["phase"])) if "phase" in schools_df.columns else [],
|
||||
"genders": clean_filter_values(schools_df.loc[_sec_mask, "gender"]) if "gender" in schools_df.columns and _sec_mask.any() else [],
|
||||
"admissions_policies": clean_filter_values(schools_df.loc[_sec_mask, "admissions_policy"]) if "admissions_policy" in schools_df.columns and _sec_mask.any() else [],
|
||||
}
|
||||
@@ -1207,8 +1213,8 @@ async def get_filter_options(request: Request):
|
||||
"faiths": [],
|
||||
}
|
||||
|
||||
# Phases: return values from data, ordered sensibly
|
||||
phases = clean_filter_values(df["phase"]) if "phase" in df.columns else []
|
||||
# Phases: the values in the data, in the order a child meets them
|
||||
phases = order_phases(clean_filter_values(df["phase"])) if "phase" in df.columns else []
|
||||
|
||||
secondary_df = df[df["attainment_8_score"].notna()] if "attainment_8_score" in df.columns else df.iloc[0:0]
|
||||
genders = clean_filter_values(secondary_df["gender"]) if "gender" in secondary_df.columns else []
|
||||
|
||||
@@ -544,6 +544,19 @@ PHASE_GROUPS: dict[str, set[str]] = {
|
||||
"all-through": {"all-through"},
|
||||
}
|
||||
|
||||
# GIAS phases in the order a child meets them, for the phase filter's options.
|
||||
# All-through spans the whole path, so it follows the stages. Lowercased, as
|
||||
# PHASE_GROUPS is, so a change of case in the GIAS label keeps its place.
|
||||
PHASE_ORDER: list[str] = [
|
||||
"nursery",
|
||||
"primary",
|
||||
"middle deemed primary",
|
||||
"middle deemed secondary",
|
||||
"secondary",
|
||||
"16 plus",
|
||||
"all-through",
|
||||
]
|
||||
|
||||
# School listing columns
|
||||
SCHOOL_COLUMNS = [
|
||||
"urn",
|
||||
|
||||
@@ -82,3 +82,25 @@ def test_grouped_phases_still_take_in_their_related_phases(client):
|
||||
|
||||
def test_an_unknown_phase_returns_nothing_rather_than_everything(client):
|
||||
assert _urns(client, "kindergarten") == []
|
||||
|
||||
|
||||
def test_filters_lists_phases_in_the_order_a_child_meets_them(client):
|
||||
# Alphabetical put "16 plus" and "All-through" first and Nursery fifth.
|
||||
# All-through spans the whole path, so it comes after the stages.
|
||||
assert client.get("/api/filters").json()["phases"] == [
|
||||
"Nursery",
|
||||
"Primary",
|
||||
"Middle deemed primary",
|
||||
"Middle deemed secondary",
|
||||
"Secondary",
|
||||
"16 plus",
|
||||
"All-through",
|
||||
]
|
||||
|
||||
|
||||
def test_an_unknown_phase_follows_the_known_ones():
|
||||
from backend.app import order_phases
|
||||
|
||||
assert order_phases(["Secondary", "Zeta", "Alpha", "Nursery"]) == [
|
||||
"Nursery", "Secondary", "Alpha", "Zeta",
|
||||
]
|
||||
@@ -286,6 +286,19 @@ test('the phase filter switches straight from secondary to primary', async ({ pa
|
||||
await expect(phase).toHaveValue('primary');
|
||||
});
|
||||
|
||||
test('the phase filter lists phases in the order a child meets them', async ({ page }) => {
|
||||
// They were alphabetical, so "16 plus" and "All-through" came before Nursery.
|
||||
const childPath = ['Nursery', 'Primary', 'Middle deemed primary',
|
||||
'Middle deemed secondary', 'Secondary', '16 plus', 'All-through'];
|
||||
await page.goto('/?search=school');
|
||||
const phase = page.getByRole('combobox', { name: 'Phase' });
|
||||
await expect(phase).toBeVisible({ timeout: 15_000 });
|
||||
const offered = (await phase.locator('option').allTextContents())
|
||||
.filter((o) => childPath.includes(o));
|
||||
expect(offered, 'no phase on offer').toContain('Primary');
|
||||
expect(offered).toEqual(childPath.filter((p) => offered.includes(p)));
|
||||
});
|
||||
|
||||
test('school type and gender switch straight to another value', async ({ page }) => {
|
||||
// Their options came from the result set, which the filter had already
|
||||
// narrowed, so with one value chosen it was the only one on offer.
|
||||
@@ -309,6 +322,19 @@ test('school type and gender switch straight to another value', async ({ page })
|
||||
* School type offers six groups a parent recognises, and Faith sits beside it.
|
||||
* Data-invariant: asserts what every returned school is, never how many.
|
||||
*/
|
||||
// Clear all once dropped the search with the filters, which sent desktop back
|
||||
// to the home page instead of to the unfiltered results.
|
||||
test('Clear all removes the filters and keeps the search', async ({ page }) => {
|
||||
await page.goto('/?search=school&phase=primary');
|
||||
const row = page.getByRole('group', { name: 'Filters', exact: true });
|
||||
await expect(schoolLinks(page).first()).toBeVisible({ timeout: 15_000 });
|
||||
await row.getByRole('button', { name: 'Clear all', exact: true }).click();
|
||||
await expect(page).not.toHaveURL(/[?&]phase=/);
|
||||
await expect(page).toHaveURL(/[?&]search=school(&|$)/);
|
||||
await expect(schoolLinks(page).first()).toBeVisible();
|
||||
await expect(row.getByRole('button', { name: 'Clear all', exact: true })).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('school type groups and the faith filter narrow to what they name', async ({ page }) => {
|
||||
await page.goto('/?search=school');
|
||||
const type = page.getByRole('combobox', { name: 'School type', exact: true });
|
||||
@@ -3260,3 +3286,26 @@ for (const width of [360, 390, 430]) {
|
||||
expect(failing).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* The header's facts row read GIAS text as booleans: "Not applicable" put a
|
||||
* "Nursery" chip on secondaries aged 11–18, and "Girls" became "Girls's
|
||||
* school". Data-invariant: the chip follows whatever the API says.
|
||||
*/
|
||||
test('a girls\' secondary header names it properly and shows Nursery only when it has one', async ({ page }) => {
|
||||
const res = await page.request.get('/api/schools?search=school&phase=secondary&gender=girls&page_size=1');
|
||||
expect(res.ok()).toBeTruthy();
|
||||
const [school] = (await res.json()).schools ?? [];
|
||||
test.skip(!school, 'no girls\' secondary in this environment');
|
||||
expect(school.gender, 'the gender filter was ignored').toBe('Girls');
|
||||
const detail = await (await page.request.get(`/api/schools/${school.urn}`)).json();
|
||||
// Without the field, the Nursery assertion below would pass vacuously.
|
||||
expect(detail.school_info).toHaveProperty('nursery_provision');
|
||||
|
||||
await page.goto(`/school/${school.urn}`);
|
||||
const header = page.locator('header', { has: page.getByRole('heading', { level: 1 }) });
|
||||
await expect(header.getByText("Girls' school", { exact: true })).toBeVisible({ timeout: 15_000 });
|
||||
await expect(header.getByText(/'s school/)).toHaveCount(0);
|
||||
await expect(header.getByText('Nursery', { exact: true }))
|
||||
.toHaveCount(detail.school_info.nursery_provision === 'Has Nursery Classes' ? 1 : 0);
|
||||
});
|
||||
@@ -361,12 +361,12 @@ describe('PlaceView school attributes', () => {
|
||||
{ urn: 1, school_name: 'Alpha Primary', phase: 'Primary',
|
||||
rwm_expected_pct: 82, attainment_8_score: null,
|
||||
age_range: '4-11', religious_denomination: 'Church of England',
|
||||
nursery_provision: true,
|
||||
nursery_provision: 'Has Nursery Classes',
|
||||
parliamentary_constituency: 'Chelmsford' } as never,
|
||||
{ urn: 2, school_name: 'Beta High', phase: 'Secondary',
|
||||
rwm_expected_pct: null, attainment_8_score: 47,
|
||||
age_range: '11-16', religious_denomination: 'Does not apply',
|
||||
nursery_provision: false,
|
||||
nursery_provision: 'No Nursery Classes',
|
||||
parliamentary_constituency: 'Witham' } as never,
|
||||
],
|
||||
averages: { rwm_expected_pct: 63, attainment_8_score: 45 },
|
||||
@@ -459,6 +459,18 @@ describe('PlaceView school attributes', () => {
|
||||
expect(cells.slice(2)).toEqual(['—', '—', '—', '—']);
|
||||
});
|
||||
|
||||
it('reads "Not applicable" as no nursery, not as a yes', () => {
|
||||
// GIAS sends text. Tested for truthiness, every value was a "Yes".
|
||||
const notApplicable: PlaceDetail = {
|
||||
...withAttributes,
|
||||
schools: [{ urn: 5, school_name: 'Epsilon Primary', phase: 'Primary',
|
||||
rwm_expected_pct: 70, nursery_provision: 'Not applicable' } as never],
|
||||
};
|
||||
const { container } = render(<PlaceView detail={notApplicable} phase="primary"
|
||||
englandAverage={61} neighbours={[]} />);
|
||||
expect(container.querySelector('tbody')!.textContent).not.toContain('Yes');
|
||||
});
|
||||
|
||||
it('gives an all-through school its nursery under primary only', () => {
|
||||
// All-through schools render in both groups. Nursery belongs to the
|
||||
// primary reading of the same school, not the secondary one.
|
||||
@@ -467,7 +479,7 @@ describe('PlaceView school attributes', () => {
|
||||
schools: [{ urn: 4, school_name: 'Delta Academy', phase: 'All-through',
|
||||
rwm_expected_pct: 66, attainment_8_score: 51,
|
||||
age_range: '4-18', religious_denomination: 'None',
|
||||
nursery_provision: true,
|
||||
nursery_provision: 'Has Nursery Classes',
|
||||
parliamentary_constituency: 'Chelmsford' } as never],
|
||||
};
|
||||
const { container } = render(<PlaceView detail={allThrough}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||
import { act, fireEvent, render, screen, within } from '@testing-library/react';
|
||||
import { HomeView } from '@/components/HomeView';
|
||||
import { FilterBar } from '@/components/FilterBar';
|
||||
import { fetchSchools } from '@/lib/api';
|
||||
@@ -175,3 +175,24 @@ describe('the results list', () => {
|
||||
expect(screen.queryByText('Search: southmead')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('the desktop Clear all', () => {
|
||||
const row = () => screen.getByRole('group', { name: 'Filters' });
|
||||
|
||||
it('removes the filters and keeps the search, rather than going home', () => {
|
||||
params = new URLSearchParams('postcode=SW196AR&radius=3&phase=primary&school_type=council&local_authority=Wandsworth');
|
||||
render(<FilterBar filters={filters} />);
|
||||
fireEvent.click(within(row()).getByRole('button', { name: 'Clear all' }));
|
||||
const pushed = push.mock.calls.at(-1)![0] as string;
|
||||
const next = new URLSearchParams(pushed.split('?')[1]);
|
||||
expect(next.get('postcode')).toBe('SW196AR');
|
||||
expect(next.get('radius')).toBe('3');
|
||||
for (const key of ['phase', 'school_type', 'local_authority']) expect(next.get(key)).toBeNull();
|
||||
});
|
||||
|
||||
it('is not offered when only a search is applied', () => {
|
||||
params = new URLSearchParams('search=southmead');
|
||||
render(<FilterBar filters={filters} />);
|
||||
expect(within(row()).queryByRole('button', { name: /^Clear/ })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* The facts row under the school name.
|
||||
*
|
||||
* nursery_provision is GIAS text, not a boolean: "Has Nursery Classes",
|
||||
* "No Nursery Classes" or "Not applicable". Tested for truthiness, every one
|
||||
* of those read as a nursery, so secondaries aged 11–18 showed "Nursery".
|
||||
*/
|
||||
|
||||
import { screen } from '@testing-library/react';
|
||||
import type { School } from '@/lib/types';
|
||||
import { primaryFixture, secondaryFixture } from '../support/schoolFixtures';
|
||||
import { renderSchoolDetail, renderSecondarySchoolDetail } from '../support/renderSchoolDetail';
|
||||
|
||||
jest.mock('@/lib/analytics', () => ({
|
||||
track: jest.fn(),
|
||||
getNavigationSource: () => 'direct',
|
||||
}));
|
||||
jest.mock('@/components/PerformanceChart', () => ({
|
||||
PerformanceChart: () => <div data-testid="performance-chart" />,
|
||||
}));
|
||||
jest.mock('@/components/SatsChart', () => ({
|
||||
__esModule: true,
|
||||
default: () => <div data-testid="sats-chart" />,
|
||||
}));
|
||||
jest.mock('@/components/AdmissionsTrendChart', () => ({
|
||||
__esModule: true,
|
||||
default: () => <div data-testid="admissions-trend-chart" />,
|
||||
}));
|
||||
jest.mock('@/components/SchoolHeroMap', () => ({
|
||||
SchoolHeroMap: () => <div data-testid="hero-map" />,
|
||||
__esModule: true,
|
||||
}));
|
||||
|
||||
function withSchool<T extends { schoolInfo: School }>(fixture: T, info: Partial<School>): T {
|
||||
return { ...fixture, schoolInfo: { ...fixture.schoolInfo, ...info } };
|
||||
}
|
||||
|
||||
describe('school header nursery chip', () => {
|
||||
it('shows Nursery when GIAS says the school has nursery classes', () => {
|
||||
renderSchoolDetail(withSchool(primaryFixture, { nursery_provision: 'Has Nursery Classes' }));
|
||||
expect(screen.getByText('Nursery', { selector: 'span' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each(['No Nursery Classes', 'Not applicable', null])(
|
||||
'hides Nursery when GIAS says %p',
|
||||
(value) => {
|
||||
renderSecondarySchoolDetail(withSchool(secondaryFixture, { nursery_provision: value }));
|
||||
expect(screen.queryByText('Nursery', { selector: 'span' })).not.toBeInTheDocument();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('school header single-sex chip', () => {
|
||||
it.each([['Girls', "Girls' school"], ['Boys', "Boys' school"]])(
|
||||
'labels a %s school with a plural possessive',
|
||||
(gender, label) => {
|
||||
renderSecondarySchoolDetail(withSchool(secondaryFixture, { gender }));
|
||||
expect(screen.getByText(label)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/'s school/)).not.toBeInTheDocument();
|
||||
},
|
||||
);
|
||||
|
||||
it('says nothing for a mixed school', () => {
|
||||
renderSecondarySchoolDetail(withSchool(secondaryFixture, { gender: 'Mixed' }));
|
||||
expect(screen.queryByText(/^(Girls|Boys|Mixed)'s? school$/)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
computeYBounds,
|
||||
formatAgeRange,
|
||||
formatAgeSpan,
|
||||
hasNurseryClasses,
|
||||
singleSexLabel,
|
||||
} from '@/lib/utils';
|
||||
|
||||
describe('formatPercentage', () => {
|
||||
@@ -346,3 +348,32 @@ describe('formatAgeRange', () => {
|
||||
expect(formatAgeRange('4-11')).toBe('Ages 4–11');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasNurseryClasses', () => {
|
||||
it('is true only for the GIAS value that means it', () => {
|
||||
// GIAS sends text, and two of its three values mean no nursery.
|
||||
expect(hasNurseryClasses('Has Nursery Classes')).toBe(true);
|
||||
expect(hasNurseryClasses('No Nursery Classes')).toBe(false);
|
||||
expect(hasNurseryClasses('Not applicable')).toBe(false);
|
||||
expect(hasNurseryClasses(null)).toBe(false);
|
||||
expect(hasNurseryClasses(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('singleSexLabel', () => {
|
||||
it('uses the plural possessive GIAS values need', () => {
|
||||
expect(singleSexLabel('Girls')).toBe("Girls' school");
|
||||
expect(singleSexLabel('Boys')).toBe("Boys' school");
|
||||
});
|
||||
|
||||
it('ignores case, as hasNurseryClasses does', () => {
|
||||
expect(singleSexLabel(' girls ')).toBe("Girls' school");
|
||||
expect(singleSexLabel('BOYS')).toBe("Boys' school");
|
||||
});
|
||||
|
||||
it('returns null for a mixed or unknown school', () => {
|
||||
expect(singleSexLabel('Mixed')).toBeNull();
|
||||
expect(singleSexLabel(null)).toBeNull();
|
||||
expect(singleSexLabel(undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -377,31 +377,13 @@ export function FilterBar({
|
||||
updateURL({ ...cleared, [key]: value });
|
||||
};
|
||||
|
||||
// Every filter at once, keeping the search and its distance: what "Clear
|
||||
// all" means beside the applied filters, where the search is not one of them.
|
||||
// Every filter at once, keeping the search and its distance. The search is
|
||||
// what the results answer, not a filter on them: clearing it too used to
|
||||
// send desktop back to the home page.
|
||||
const handleClearFilterValues = () => {
|
||||
updateURL(Object.fromEntries(FILTER_KEYS.map((k) => [k, ""])));
|
||||
};
|
||||
|
||||
const handleClearFilters = () => {
|
||||
setOmniValue("");
|
||||
pendingQueryRef.current = "";
|
||||
startTransition(() => {
|
||||
router.push(pathname);
|
||||
});
|
||||
};
|
||||
|
||||
const hasActiveFilters =
|
||||
currentSearch ||
|
||||
currentLA ||
|
||||
currentType ||
|
||||
currentFaith ||
|
||||
currentPhase ||
|
||||
currentPostcode ||
|
||||
currentGender ||
|
||||
currentAdmissionsPolicy ||
|
||||
currentHasSixthForm;
|
||||
|
||||
/*
|
||||
* A filter's options come from the full lists, not from the results: the
|
||||
* results have already been narrowed by that filter, so scoping to them
|
||||
@@ -844,14 +826,14 @@ export function FilterBar({
|
||||
/>
|
||||
</button>
|
||||
|
||||
{hasActiveFilters && (
|
||||
{appliedCount > 0 && (
|
||||
<button
|
||||
onClick={handleClearFilters}
|
||||
onClick={handleClearFilterValues}
|
||||
className={`btn btn-tertiary ${styles.clearButton}`}
|
||||
type="button"
|
||||
disabled={isPending}
|
||||
>
|
||||
Clear
|
||||
Clear all
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -79,7 +79,11 @@
|
||||
font-family: var(--font-display);
|
||||
}
|
||||
|
||||
/* 44px, the MOBILE.md touch-target minimum: the 24px icon and its padding
|
||||
came to 40, and the phone filter sheet journey caught it. */
|
||||
.closeButton {
|
||||
min-width: 2.75rem;
|
||||
min-height: 2.75rem;
|
||||
padding: 0.5rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
|
||||
@@ -13,7 +13,7 @@ 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 { schoolUrl, formatAgeSpan, hasNurseryClasses } from '@/lib/utils';
|
||||
import { absoluteUrl } from '@/lib/site';
|
||||
import { TrackPlaceView } from './TrackPlaceView';
|
||||
import styles from './PlaceView.module.css';
|
||||
@@ -131,9 +131,10 @@ function SchoolTable({ schools, phase }: { schools: School[]; phase: PhaseKey })
|
||||
{showNursery && (
|
||||
<td className={styles.attr}>
|
||||
{/* 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}
|
||||
"No Nursery Classes" or "Not applicable" is a school
|
||||
without one. None is a "Yes", and none is worth a
|
||||
different word. */}
|
||||
{hasNurseryClasses(s.nursery_provision) ? 'Yes' : NO_VALUE}
|
||||
</td>
|
||||
)}
|
||||
<td className={styles.attrWide}>
|
||||
|
||||
@@ -21,7 +21,7 @@ import { useRouter } from 'next/navigation';
|
||||
import { useComparison } from '@/hooks/useComparison';
|
||||
import { SchoolHeroMap, type SchoolHeroMapHandle } from '../SchoolHeroMap';
|
||||
import type { School, SchoolResult, SchoolCensus } from '@/lib/types';
|
||||
import { formatAgeRange, isProposedToClose } from '@/lib/utils';
|
||||
import { formatAgeRange, hasNurseryClasses, isProposedToClose, singleSexLabel } from '@/lib/utils';
|
||||
import type { NavItem } from '@/lib/schoolSections';
|
||||
import { track, getNavigationSource } from '@/lib/analytics';
|
||||
import styles from './SchoolDetailShell.module.css';
|
||||
@@ -122,7 +122,7 @@ export function SchoolDetailShell({
|
||||
return () => window.removeEventListener('keydown', onKey);
|
||||
}, [sectionsOpen]);
|
||||
|
||||
// The chrome needs only these four. The section-shape flags are computed
|
||||
// The chrome needs only these few. The section-shape flags are computed
|
||||
// once on the server (lib/schoolSections) and consumed by the section
|
||||
// composers; recomputing them here would duplicate that work for values
|
||||
// this component never renders.
|
||||
@@ -130,6 +130,7 @@ export function SchoolDetailShell({
|
||||
const phase = schoolInfo.phase ?? '';
|
||||
const isAllThrough = phase.toLowerCase() === 'all-through';
|
||||
const hasLocation = schoolInfo.latitude != null && schoolInfo.longitude != null;
|
||||
const singleSex = singleSexLabel(schoolInfo.gender);
|
||||
|
||||
const handleComparisonToggle = () => {
|
||||
if (isInComparison) {
|
||||
@@ -214,13 +215,11 @@ export function SchoolDetailShell({
|
||||
{isAllThrough && (
|
||||
<span className={styles.metaItem}>All-through (primary & secondary)</span>
|
||||
)}
|
||||
{schoolInfo.gender && schoolInfo.gender !== 'Mixed' && (
|
||||
<span className={styles.metaItem}>{schoolInfo.gender}'s school</span>
|
||||
)}
|
||||
{singleSex && <span className={styles.metaItem}>{singleSex}</span>}
|
||||
{schoolInfo.age_range && (
|
||||
<span className={styles.metaItem}>{formatAgeRange(schoolInfo.age_range)}</span>
|
||||
)}
|
||||
{schoolInfo.nursery_provision && (
|
||||
{hasNurseryClasses(schoolInfo.nursery_provision) && (
|
||||
<span className={styles.metaItem}>Nursery</span>
|
||||
)}
|
||||
{schoolInfo.has_sixth_form && (
|
||||
|
||||
@@ -20,7 +20,8 @@ export interface School {
|
||||
religious_denomination: string | null;
|
||||
age_range: string | null;
|
||||
has_sixth_form?: boolean | null;
|
||||
nursery_provision?: boolean | null;
|
||||
/** GIAS text; read it through hasNurseryClasses(). */
|
||||
nursery_provision?: string | null;
|
||||
status?: string | null; // GIAS establishment status ("Open" / "Open, but proposed to close")
|
||||
|
||||
// Address
|
||||
|
||||
@@ -99,6 +99,26 @@ export function formatAgeRange(ageRange: string | null | undefined): string {
|
||||
return /^\d+–\d+$/.test(span) ? `Ages ${span}` : span;
|
||||
}
|
||||
|
||||
/**
|
||||
* GIAS NurseryProvision is text: "Has Nursery Classes", "No Nursery Classes"
|
||||
* or "Not applicable". Only the first means a nursery, so never test the raw
|
||||
* value for truthiness.
|
||||
*/
|
||||
export function hasNurseryClasses(value: string | null | undefined): boolean {
|
||||
return value?.trim().toLowerCase() === 'has nursery classes';
|
||||
}
|
||||
|
||||
/**
|
||||
* "Girls' school" / "Boys' school" for a single-sex school, null otherwise.
|
||||
* GIAS genders are plural, so the possessive is a bare apostrophe.
|
||||
*/
|
||||
export function singleSexLabel(gender: string | null | undefined): string | null {
|
||||
const g = gender?.trim().toLowerCase();
|
||||
if (g === 'girls') return "Girls' school";
|
||||
if (g === 'boys') return "Boys' school";
|
||||
return null;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Number Formatting
|
||||
// ============================================================================
|
||||
|
||||
Reference in new issue
Block a user