Skip to content

Commit c89db03

Browse files
Football data pages - league selector ordering (#13608)
* rename nations to regions throughout * add sorting
1 parent d62bb5a commit c89db03

10 files changed

+75
-34
lines changed

dotcom-rendering/fixtures/manual/footballData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { FootballMatches, Regions } from '../../src/footballMatches';
1+
import type { FootballMatches, Region } from '../../src/footballMatches';
22

3-
export const regions: Regions = [
3+
export const regions: Region[] = [
44
{
55
name: 'England',
66
competitions: [

dotcom-rendering/src/components/FootballCompetitionSelect.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Story = StoryObj<typeof meta>;
2121

2222
export const FootballCompetitionSelect = {
2323
args: {
24-
nations: regions,
24+
regions,
2525
kind: 'Result',
2626
pageId: 'football/live',
2727
onChange: fn(),

dotcom-rendering/src/components/FootballCompetitionSelect.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Option, Select } from '@guardian/source/react-components';
2-
import type { FootballMatchKind, Regions } from '../footballMatches';
2+
import type { FootballMatchKind, Region } from '../footballMatches';
33
import { palette } from '../palette';
44

55
type Props = {
6-
nations: Regions;
6+
regions: Region[];
77
kind: FootballMatchKind;
88
pageId: string;
99
onChange: (competitionTag: string) => void;
@@ -32,7 +32,7 @@ const getPagePath = (kind: FootballMatchKind) => {
3232
};
3333

3434
export const FootballCompetitionSelect = ({
35-
nations,
35+
regions,
3636
kind,
3737
pageId,
3838
onChange,
@@ -48,9 +48,9 @@ export const FootballCompetitionSelect = ({
4848
}}
4949
>
5050
<Option value={getPagePath(kind)}>{allLabel(kind)}</Option>
51-
{nations.map((nation) => (
52-
<optgroup label={nation.name} key={nation.name}>
53-
{nation.competitions.map((competition) => (
51+
{regions.map((region) => (
52+
<optgroup label={region.name} key={region.name}>
53+
{region.competitions.map((competition) => (
5454
<Option key={competition.name} value={competition.url}>
5555
{competition.name}
5656
</Option>

dotcom-rendering/src/components/FootballMatchesPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import type {
99
FootballMatches,
1010
FootballMatchKind,
11-
Regions,
11+
Region,
1212
} from '../footballMatches';
1313
import { grid } from '../grid';
1414
import type { EditionId } from '../lib/edition';
@@ -19,7 +19,7 @@ import { FootballCompetitionSelect } from './FootballCompetitionSelect';
1919
import { FootballMatchList } from './FootballMatchList';
2020

2121
type Props = {
22-
regions: Regions;
22+
regions: Region[];
2323
guardianBaseUrl: string;
2424
kind: FootballMatchKind;
2525
initialDays: FootballMatches;
@@ -46,7 +46,7 @@ const createTitle = (kind: FootballMatchKind, edition: EditionId) => {
4646
};
4747

4848
export const FootballMatchesPage = ({
49-
regions: nations,
49+
regions,
5050
guardianBaseUrl,
5151
kind,
5252
initialDays,
@@ -103,7 +103,7 @@ export const FootballMatchesPage = ({
103103
`}
104104
>
105105
<FootballCompetitionSelect
106-
nations={nations}
106+
regions={regions}
107107
kind={kind}
108108
pageId={pageId}
109109
onChange={goToCompetitionSpecificPage}

dotcom-rendering/src/components/FootballMatchesPageWrapper.importable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type FootballMatchKind,
88
getParserErrorMessage,
99
parse,
10-
type Regions,
10+
type Region,
1111
} from '../footballMatches';
1212
import type { EditionId } from '../lib/edition';
1313
import type { Result } from '../lib/result';
@@ -62,7 +62,7 @@ const goToCompetitionSpecificPage =
6262
};
6363

6464
type Props = {
65-
nations: Regions;
65+
regions: Region[];
6666
guardianBaseUrl: string;
6767
ajaxUrl: string;
6868
kind: FootballMatchKind;
@@ -74,7 +74,7 @@ type Props = {
7474
};
7575

7676
export const FootballMatchesPageWrapper = ({
77-
nations,
77+
regions,
7878
guardianBaseUrl,
7979
ajaxUrl,
8080
kind,
@@ -88,7 +88,7 @@ export const FootballMatchesPageWrapper = ({
8888

8989
return (
9090
<FootballMatchesPage
91-
regions={nations}
91+
regions={regions}
9292
guardianBaseUrl={guardianBaseUrl}
9393
kind={kind}
9494
initialDays={initialDays}

dotcom-rendering/src/footballMatches.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,17 @@ export const parse: (
413413
frontendData: FEMatchByDateAndCompetition[],
414414
) => Result<ParserError, FootballMatches> = listParse(parseFootballDay);
415415

416-
export type Regions = Array<{
416+
export type Region = {
417417
name: string;
418418
competitions: Array<{ url: string; name: string }>;
419-
}>;
419+
};
420420

421421
export type DCRFootballDataPage = {
422422
matchesList: FootballMatches;
423423
kind: FootballMatchKind;
424424
nextPage?: string;
425425
previousPage?: string;
426-
regions: Regions;
426+
regions: Region[];
427427
nav: NavType;
428428
editionId: EditionId;
429429
guardianBaseURL: string;

dotcom-rendering/src/layouts/FootballDataPageLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const FootballDataPageLayout = ({ footballData }: Props) => {
6262

6363
<Island priority="feature" defer={{ until: 'visible' }}>
6464
<FootballMatchesPageWrapper
65-
nations={footballData.regions}
65+
regions={footballData.regions}
6666
guardianBaseUrl={footballData.guardianBaseURL}
6767
ajaxUrl={footballData.config.ajaxUrl}
6868
kind={footballData.kind}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { sortRegionsFunction } from './handler.footballDataPage.web';
2+
3+
describe('sortRegionsFunction', () => {
4+
it('should return Regions in expected order', () => {
5+
const regions = [
6+
{
7+
name: 'English',
8+
competitions: [],
9+
},
10+
{
11+
name: 'Internationals',
12+
competitions: [],
13+
},
14+
{
15+
name: 'Unknown',
16+
competitions: [],
17+
},
18+
];
19+
20+
const expectedNameOrder = ['Unknown', 'Internationals', 'English'];
21+
22+
const sortedRegions = regions.sort(sortRegionsFunction);
23+
expect(sortedRegions.map((region) => region.name)).toEqual(
24+
expectedNameOrder,
25+
);
26+
});
27+
});

dotcom-rendering/src/server/handler.footballDataPage.web.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
import type {
77
DCRFootballDataPage,
88
FootballMatchKind,
9-
Regions,
9+
Region,
1010
} from '../footballMatches';
1111
import { getParserErrorMessage, parse } from '../footballMatches';
1212
import { Pillar } from '../lib/articleFormat';
@@ -32,18 +32,32 @@ const decidePageKind = (pageId: string): FootballMatchKind => {
3232
throw new Error('Could not determine football page kind');
3333
};
3434

35+
const regionsPriority = [
36+
'Internationals',
37+
'English',
38+
'European',
39+
'Scottish',
40+
'Rest of world',
41+
];
42+
43+
export const sortRegionsFunction = (a: Region, b: Region): number => {
44+
return regionsPriority.indexOf(a.name) - regionsPriority.indexOf(b.name);
45+
};
46+
3547
const parseFEFootballCompetitionRegions = (
3648
competitionRegions: Record<string, FEFootballCompetition[]>,
37-
): Regions => {
38-
return Object.entries(competitionRegions).map(([key, competition]) => {
39-
return {
40-
name: key,
41-
competitions: competition.map((comp) => ({
42-
url: comp.url,
43-
name: comp.name,
44-
})),
45-
};
46-
});
49+
): Region[] => {
50+
return Object.entries(competitionRegions)
51+
.map(([key, competition]) => {
52+
return {
53+
name: key,
54+
competitions: competition.map((comp) => ({
55+
url: comp.url,
56+
name: comp.name,
57+
})),
58+
};
59+
})
60+
.sort(sortRegionsFunction);
4761
};
4862

4963
const parseFEFootballData = (data: FEFootballDataPage): DCRFootballDataPage => {

dotcom-rendering/src/server/render.footballDataPage.web.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FootballDataPage } from '../components/FootballDataPage';
44
import type {
55
DCRFootballDataPage,
66
FootballMatchKind,
7-
Regions,
7+
Region,
88
} from '../footballMatches';
99
import {
1010
ASSET_ORIGIN,
@@ -35,7 +35,7 @@ const decideDescription = (kind: FootballMatchKind) => {
3535
const decideTitle = (
3636
kind: FootballMatchKind,
3737
pageId: string,
38-
regions: Regions,
38+
regions: Region[],
3939
) => {
4040
const pagePath = pageId.startsWith('/') ? pageId.slice(1) : pageId;
4141
const competitionName = regions

0 commit comments

Comments
 (0)