File tree Expand file tree Collapse file tree 10 files changed +75
-34
lines changed Expand file tree Collapse file tree 10 files changed +75
-34
lines changed Original file line number Diff line number Diff line change 1
- import type { FootballMatches , Regions } from '../../src/footballMatches' ;
1
+ import type { FootballMatches , Region } from '../../src/footballMatches' ;
2
2
3
- export const regions : Regions = [
3
+ export const regions : Region [ ] = [
4
4
{
5
5
name : 'England' ,
6
6
competitions : [
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ type Story = StoryObj<typeof meta>;
21
21
22
22
export const FootballCompetitionSelect = {
23
23
args : {
24
- nations : regions ,
24
+ regions,
25
25
kind : 'Result' ,
26
26
pageId : 'football/live' ,
27
27
onChange : fn ( ) ,
Original file line number Diff line number Diff line change 1
1
import { Option , Select } from '@guardian/source/react-components' ;
2
- import type { FootballMatchKind , Regions } from '../footballMatches' ;
2
+ import type { FootballMatchKind , Region } from '../footballMatches' ;
3
3
import { palette } from '../palette' ;
4
4
5
5
type Props = {
6
- nations : Regions ;
6
+ regions : Region [ ] ;
7
7
kind : FootballMatchKind ;
8
8
pageId : string ;
9
9
onChange : ( competitionTag : string ) => void ;
@@ -32,7 +32,7 @@ const getPagePath = (kind: FootballMatchKind) => {
32
32
} ;
33
33
34
34
export const FootballCompetitionSelect = ( {
35
- nations ,
35
+ regions ,
36
36
kind,
37
37
pageId,
38
38
onChange,
@@ -48,9 +48,9 @@ export const FootballCompetitionSelect = ({
48
48
} }
49
49
>
50
50
< 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 ) => (
54
54
< Option key = { competition . name } value = { competition . url } >
55
55
{ competition . name }
56
56
</ Option >
Original file line number Diff line number Diff line change 8
8
import type {
9
9
FootballMatches ,
10
10
FootballMatchKind ,
11
- Regions ,
11
+ Region ,
12
12
} from '../footballMatches' ;
13
13
import { grid } from '../grid' ;
14
14
import type { EditionId } from '../lib/edition' ;
@@ -19,7 +19,7 @@ import { FootballCompetitionSelect } from './FootballCompetitionSelect';
19
19
import { FootballMatchList } from './FootballMatchList' ;
20
20
21
21
type Props = {
22
- regions : Regions ;
22
+ regions : Region [ ] ;
23
23
guardianBaseUrl : string ;
24
24
kind : FootballMatchKind ;
25
25
initialDays : FootballMatches ;
@@ -46,7 +46,7 @@ const createTitle = (kind: FootballMatchKind, edition: EditionId) => {
46
46
} ;
47
47
48
48
export const FootballMatchesPage = ( {
49
- regions : nations ,
49
+ regions,
50
50
guardianBaseUrl,
51
51
kind,
52
52
initialDays,
@@ -103,7 +103,7 @@ export const FootballMatchesPage = ({
103
103
` }
104
104
>
105
105
< FootballCompetitionSelect
106
- nations = { nations }
106
+ regions = { regions }
107
107
kind = { kind }
108
108
pageId = { pageId }
109
109
onChange = { goToCompetitionSpecificPage }
Original file line number Diff line number Diff line change 7
7
type FootballMatchKind ,
8
8
getParserErrorMessage ,
9
9
parse ,
10
- type Regions ,
10
+ type Region ,
11
11
} from '../footballMatches' ;
12
12
import type { EditionId } from '../lib/edition' ;
13
13
import type { Result } from '../lib/result' ;
@@ -62,7 +62,7 @@ const goToCompetitionSpecificPage =
62
62
} ;
63
63
64
64
type Props = {
65
- nations : Regions ;
65
+ regions : Region [ ] ;
66
66
guardianBaseUrl : string ;
67
67
ajaxUrl : string ;
68
68
kind : FootballMatchKind ;
@@ -74,7 +74,7 @@ type Props = {
74
74
} ;
75
75
76
76
export const FootballMatchesPageWrapper = ( {
77
- nations ,
77
+ regions ,
78
78
guardianBaseUrl,
79
79
ajaxUrl,
80
80
kind,
@@ -88,7 +88,7 @@ export const FootballMatchesPageWrapper = ({
88
88
89
89
return (
90
90
< FootballMatchesPage
91
- regions = { nations }
91
+ regions = { regions }
92
92
guardianBaseUrl = { guardianBaseUrl }
93
93
kind = { kind }
94
94
initialDays = { initialDays }
Original file line number Diff line number Diff line change @@ -413,17 +413,17 @@ export const parse: (
413
413
frontendData : FEMatchByDateAndCompetition [ ] ,
414
414
) => Result < ParserError , FootballMatches > = listParse ( parseFootballDay ) ;
415
415
416
- export type Regions = Array < {
416
+ export type Region = {
417
417
name : string ;
418
418
competitions : Array < { url : string ; name : string } > ;
419
- } > ;
419
+ } ;
420
420
421
421
export type DCRFootballDataPage = {
422
422
matchesList : FootballMatches ;
423
423
kind : FootballMatchKind ;
424
424
nextPage ?: string ;
425
425
previousPage ?: string ;
426
- regions : Regions ;
426
+ regions : Region [ ] ;
427
427
nav : NavType ;
428
428
editionId : EditionId ;
429
429
guardianBaseURL : string ;
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ export const FootballDataPageLayout = ({ footballData }: Props) => {
62
62
63
63
< Island priority = "feature" defer = { { until : 'visible' } } >
64
64
< FootballMatchesPageWrapper
65
- nations = { footballData . regions }
65
+ regions = { footballData . regions }
66
66
guardianBaseUrl = { footballData . guardianBaseURL }
67
67
ajaxUrl = { footballData . config . ajaxUrl }
68
68
kind = { footballData . kind }
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import type {
6
6
import type {
7
7
DCRFootballDataPage ,
8
8
FootballMatchKind ,
9
- Regions ,
9
+ Region ,
10
10
} from '../footballMatches' ;
11
11
import { getParserErrorMessage , parse } from '../footballMatches' ;
12
12
import { Pillar } from '../lib/articleFormat' ;
@@ -32,18 +32,32 @@ const decidePageKind = (pageId: string): FootballMatchKind => {
32
32
throw new Error ( 'Could not determine football page kind' ) ;
33
33
} ;
34
34
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
+
35
47
const parseFEFootballCompetitionRegions = (
36
48
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 ) ;
47
61
} ;
48
62
49
63
const parseFEFootballData = ( data : FEFootballDataPage ) : DCRFootballDataPage => {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { FootballDataPage } from '../components/FootballDataPage';
4
4
import type {
5
5
DCRFootballDataPage ,
6
6
FootballMatchKind ,
7
- Regions ,
7
+ Region ,
8
8
} from '../footballMatches' ;
9
9
import {
10
10
ASSET_ORIGIN ,
@@ -35,7 +35,7 @@ const decideDescription = (kind: FootballMatchKind) => {
35
35
const decideTitle = (
36
36
kind : FootballMatchKind ,
37
37
pageId : string ,
38
- regions : Regions ,
38
+ regions : Region [ ] ,
39
39
) => {
40
40
const pagePath = pageId . startsWith ( '/' ) ? pageId . slice ( 1 ) : pageId ;
41
41
const competitionName = regions
You can’t perform that action at this time.
0 commit comments