Skip to content

Commit e50f02b

Browse files
JamieB-gujamesmockettmarjisound
authored
Add match header URL (#15364)
This URL is what we will request to retrieve data for the match header client-side. Frontend is already sending it, so this change adds it to DCAR's schemas and models. It also adds a new schema for the JSON data returned by this endpoint, ready to be used by the header. Co-authored-by: James M <1166188+jamesmockett@users.noreply.github.com> Co-authored-by: Marjan K <15894063+marjisound@users.noreply.github.com>
1 parent 43fa25b commit e50f02b

6 files changed

Lines changed: 38 additions & 1 deletion

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { object, optional, type Output, string } from 'valibot';
2+
import { feFootballMatchSchema } from './feFootballMatchListPage';
3+
4+
export const feFootballMatchHeaderSchema = object({
5+
footballMatch: feFootballMatchSchema,
6+
competitionName: string(),
7+
liveURL: optional(string()),
8+
reportURL: optional(string()),
9+
infoURL: string(),
10+
});
11+
12+
export type FEFootballMatchHeader = Output<typeof feFootballMatchHeaderSchema>;

dotcom-rendering/src/frontend/feFootballMatchInfoPage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ export type FEFootballMatchStats = {
4545
export type FEFootballMatchInfoPage = FEFootballDataPage & {
4646
// This field name will need to get changed to matchStats in the future PRs.
4747
// Since this change needs to happen in both frontend and DCAR, and it also
48-
// needs to be backward compatible for a temprary duration, we will handle
48+
// needs to be backward compatible for a temporary duration, we will handle
4949
// that in a separate PR.
5050
footballMatch: FEFootballMatchStats;
5151
matchInfo: FEFootballMatch;
5252
group?: FEGroupSummary;
5353
competitionName: string;
5454
matchUrl: string;
55+
matchHeaderUrl: string;
5556
};

dotcom-rendering/src/frontend/schemas/feFootballMatchInfoPage.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,15 @@
495495
},
496496
"matchUrl": {
497497
"type": "string"
498+
},
499+
"matchHeaderUrl": {
500+
"type": "string"
498501
}
499502
},
500503
"required": [
501504
"competitionName",
502505
"footballMatch",
506+
"matchHeaderUrl",
503507
"matchInfo",
504508
"matchUrl"
505509
]

dotcom-rendering/src/lib/parse.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,13 @@ export const oneOf =
4646

4747
return f(parsers, []);
4848
};
49+
50+
export class URLParseError {}
51+
52+
export const safeParseURL = (s: string): Result<URLParseError, URL> => {
53+
try {
54+
return ok(new URL(s));
55+
} catch {
56+
return error(new URLParseError());
57+
}
58+
};

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { FEFootballMatchInfoPage } from '../frontend/feFootballMatchInfoPag
1717
import type { FEFootballMatchListPage } from '../frontend/feFootballMatchListPage';
1818
import type { FEFootballTablesPage } from '../frontend/feFootballTablesPage';
1919
import { Pillar } from '../lib/articleFormat';
20+
import { safeParseURL } from '../lib/parse';
2021
import { extractNAV } from '../model/extract-nav';
2122
import {
2223
validateAsCricketMatchPageType,
@@ -247,13 +248,21 @@ const parseFEFootballMatch = (
247248
);
248249
}
249250

251+
const headerUrl = safeParseURL(data.matchHeaderUrl);
252+
if (!headerUrl.ok) {
253+
throw new Error(
254+
`Failed to parse match header URL: ${data.matchHeaderUrl}`,
255+
);
256+
}
257+
250258
return {
251259
match: parsedFootballMatch.value,
252260
matchStats: parsedFootballMatchStats.value,
253261
matchInfo: matchInfo.value,
254262
competitionName: data.competitionName,
255263
group: group?.value,
256264
matchUrl: data.matchUrl,
265+
matchHeaderUrl: headerUrl.value,
257266
kind: 'FootballMatchSummary',
258267
nav: {
259268
...extractNAV(data.nav),

dotcom-rendering/src/sportDataPage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export type FootballMatchInfoPage = SportPageConfig & {
5858
group?: FootballTableSummary;
5959
competitionName: string;
6060
matchUrl: string;
61+
matchHeaderUrl: URL;
6162
kind: 'FootballMatchSummary';
6263
};
6364

0 commit comments

Comments
 (0)