Skip to content

Commit 7b03e24

Browse files
andrewHEguardianoliverabrahamsmarjisound
authored
Make score optional for match summaries (#13816)
* Make score optional for match summary page * fix schema * hide Lineup and substitute headings if no players * sync up with FE data model. --------- Co-authored-by: oliverabrahams <[email protected]> Co-authored-by: Marjan Kalanaki <[email protected]>
1 parent eb02aad commit 7b03e24

12 files changed

+108
-97
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,13 @@ export const InContext = () => {
103103
);
104104
};
105105
InContext.storyName = 'when placed in article context';
106+
107+
export const NoScore = () => {
108+
return (
109+
<MatchNav
110+
homeTeam={{ ...homeTeam, score: undefined, scorers: [] }}
111+
awayTeam={{ ...awayTeam, score: undefined, scorers: [] }}
112+
/>
113+
);
114+
};
115+
NoScore.storyName = 'with no scores';

dotcom-rendering/src/components/MatchNav.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { css } from '@emotion/react';
2+
import { isUndefined } from '@guardian/libs';
23
import {
34
background,
45
headlineBold20,
56
space,
67
textSans15,
78
until,
89
} from '@guardian/source/foundations';
10+
import type { FootballTeam } from '../footballMatch';
911
import { palette } from '../palette';
10-
import type { TeamType } from '../types/sport';
1112
import { Score } from './Score';
1213

14+
type Team = Pick<FootballTeam, 'name' | 'score' | 'scorers' | 'crest'>;
15+
1316
type Props = {
14-
homeTeam: Pick<TeamType, 'name' | 'score' | 'scorers' | 'crest'>;
15-
awayTeam: Pick<TeamType, 'name' | 'score' | 'scorers' | 'crest'>;
17+
homeTeam: Team;
18+
awayTeam: Team;
1619
comments?: string;
1720
};
1821

@@ -131,7 +134,7 @@ const TeamNav = ({
131134
scorers,
132135
}: {
133136
name: string;
134-
score: number;
137+
score?: number;
135138
crest: string;
136139
scorers: string[];
137140
}) => (
@@ -164,13 +167,15 @@ const TeamNav = ({
164167
</div>
165168
<CrestRow>
166169
<Crest crest={crest} />
167-
<div
168-
css={css`
169-
margin-left: -${space[2]}px;
170-
`}
171-
>
172-
<Score score={score} />
173-
</div>
170+
{!isUndefined(score) && (
171+
<div
172+
css={css`
173+
margin-left: -${space[2]}px;
174+
`}
175+
>
176+
<Score score={score} />
177+
</div>
178+
)}
174179
</CrestRow>
175180
</Column>
176181
</div>

dotcom-rendering/src/components/MatchStats.tsx

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
textSans15,
99
until,
1010
} from '@guardian/source/foundations';
11+
import type { FootballTeam } from '../footballMatch';
1112
import { ArticleDesign, type ArticleFormat } from '../lib/articleFormat';
1213
import { palette as themePalette } from '../palette';
1314
import type { ColourName } from '../paletteDeclarations';
14-
import type { TeamType } from '../types/sport';
1515
import { Distribution } from './Distribution';
1616
import { Doughnut } from './Doughnut';
1717
import { GoalAttempts } from './GoalAttempts';
@@ -20,8 +20,8 @@ import { Hide } from './Hide';
2020
import { Lineup } from './Lineup';
2121

2222
type MatchStatsData = {
23-
home: TeamType;
24-
away: TeamType;
23+
home: FootballTeam;
24+
away: FootballTeam;
2525
};
2626

2727
type MatchSummaryProps = MatchStatsData & {
@@ -289,8 +289,8 @@ const DecideDoughnut = ({
289289
away,
290290
format,
291291
}: {
292-
home: TeamType;
293-
away: TeamType;
292+
home: FootballTeam;
293+
away: FootballTeam;
294294
format?: ArticleFormat;
295295
}) => {
296296
const sections = [
@@ -352,13 +352,14 @@ const DecideDoughnut = ({
352352
Some leagues do not return match stats - see
353353
https://github.com/guardian/frontend/blob/e046d4144d0001059156f402fd5cf1af29ee9f0c/sport/app/football/controllers/MatchController.scala#L23
354354
*/
355-
function teamHasStats({ shotsOff, shotsOn, fouls, corners }: TeamType) {
355+
function teamHasStats({ shotsOff, shotsOn, fouls, corners }: FootballTeam) {
356356
return !(shotsOff === 0 && shotsOn === 0 && fouls === 0 && corners === 0);
357357
}
358358

359359
export const MatchStats = (props: Props) => {
360360
const { home, away, usage } = props;
361361
const showStats = teamHasStats(home) && teamHasStats(away);
362+
const showLineups = home.players.length > 0 && away.players.length > 0;
362363

363364
const format = usage === 'Article' ? props.format : undefined;
364365
const backgroundColour =
@@ -447,54 +448,58 @@ export const MatchStats = (props: Props) => {
447448
</GridItem>
448449
</>
449450
)}
450-
<GridItem area="subtitle">
451-
<ShiftLeft format={format}>
452-
{/* Don't show the right border if this text was
451+
{showLineups && (
452+
<>
453+
<GridItem area="subtitle">
454+
<ShiftLeft format={format}>
455+
{/* Don't show the right border if this text was
453456
shifted into the left column */}
454-
<Hide when="above" breakpoint="desktop">
457+
<Hide when="above" breakpoint="desktop">
458+
<RightBorder>
459+
<H3>Lineups</H3>
460+
</RightBorder>
461+
</Hide>
462+
<Hide when="below" breakpoint="desktop">
463+
<H3>Lineups</H3>
464+
</Hide>
465+
</ShiftLeft>
466+
</GridItem>
467+
<GridItem area="home">
455468
<RightBorder>
456-
<H3>Lineups</H3>
469+
<H4>{home.name}</H4>
470+
<Lineup
471+
players={home.players.filter(
472+
(player) => !player.substitute,
473+
)}
474+
/>
475+
<br />
476+
<H4>Substitutes</H4>
477+
<Lineup
478+
players={home.players.filter(
479+
(player) => player.substitute,
480+
)}
481+
/>
482+
<br />
457483
</RightBorder>
458-
</Hide>
459-
<Hide when="below" breakpoint="desktop">
460-
<H3>Lineups</H3>
461-
</Hide>
462-
</ShiftLeft>
463-
</GridItem>
464-
<GridItem area="home">
465-
<RightBorder>
466-
<H4>{home.name}</H4>
467-
<Lineup
468-
players={home.players.filter(
469-
(player) => !player.substitute,
470-
)}
471-
/>
472-
<br />
473-
<H4>Substitutes</H4>
474-
<Lineup
475-
players={home.players.filter(
476-
(player) => player.substitute,
477-
)}
478-
/>
479-
<br />
480-
</RightBorder>
481-
</GridItem>
482-
<GridItem area="away">
483-
<H4>{away.name}</H4>
484-
<Lineup
485-
players={away.players.filter(
486-
(player) => !player.substitute,
487-
)}
488-
/>
489-
<br />
490-
<H4>Substitutes</H4>
491-
<Lineup
492-
players={away.players.filter(
493-
(player) => player.substitute,
494-
)}
495-
/>
496-
<br />
497-
</GridItem>
484+
</GridItem>
485+
<GridItem area="away">
486+
<H4>{away.name}</H4>
487+
<Lineup
488+
players={away.players.filter(
489+
(player) => !player.substitute,
490+
)}
491+
/>
492+
<br />
493+
<H4>Substitutes</H4>
494+
<Lineup
495+
players={away.players.filter(
496+
(player) => player.substitute,
497+
)}
498+
/>
499+
<br />
500+
</GridItem>
501+
</>
502+
)}
498503
</StatsGrid>
499504
</StretchBackground>
500505
);

dotcom-rendering/src/footballMatch.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export type FootballTeam = {
2929
corners: number;
3030
fouls: number;
3131
colours: string;
32-
// ToDo: this needs to be optional
33-
score: number;
32+
score?: number;
3433
crest: string;
3534
scorers: string[];
3635
};
@@ -49,7 +48,7 @@ export type FootballPlayer = {
4948
export type FootballMatch = {
5049
homeTeam: FootballTeam;
5150
awayTeam: FootballTeam;
52-
comments: string;
51+
comments?: string;
5352
};
5453

5554
type UnknownEventType = {

dotcom-rendering/src/frontend/feFootballDataPage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export type FESportPageConfig = Omit<
3030
};
3131

3232
export type FEFootballDataPage = {
33-
filters: Record<string, FEFootballCompetition[]>;
3433
nav: FENavType;
3534
editionId: EditionId;
3635
guardianBaseURL: string;

dotcom-rendering/src/frontend/feFootballMatchListPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
FECompetitionSummary,
3+
FEFootballCompetition,
34
FEFootballDataPage,
45
FERound,
56
} from './feFootballDataPage';
@@ -89,6 +90,7 @@ export type FEMatchByDateAndCompetition = {
8990
};
9091

9192
export type FEFootballMatchListPage = FEFootballDataPage & {
93+
filters: Record<string, FEFootballCompetition[]>;
9294
matchesList: FEMatchByDateAndCompetition[];
9395
nextPage?: string;
9496
previousPage?: string;

dotcom-rendering/src/frontend/feFootballMatchPage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type FEFootballTeam = {
2121
name: string;
2222
codename: string;
2323
players: FEFootballPlayer[];
24-
score: number;
24+
score?: number;
2525
scorers: string[];
2626
possession: number;
2727
shotsOn: number;
@@ -36,9 +36,9 @@ export type FEFootballMatch = {
3636
id: string;
3737
homeTeam: FEFootballTeam;
3838
awayTeam: FEFootballTeam;
39-
comments: string;
39+
comments?: string;
4040
};
4141

4242
export type FEFootballMatchPage = FEFootballDataPage & {
43-
match: FEFootballMatch;
43+
footballMatch: FEFootballMatch;
4444
};

dotcom-rendering/src/frontend/feFootballTablesPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
FECompetitionSummary,
3+
FEFootballCompetition,
34
FEFootballDataPage,
45
FERound,
56
} from './feFootballDataPage';
@@ -61,5 +62,6 @@ export type FEFootballTable = {
6162
};
6263

6364
export type FEFootballTablesPage = FEFootballDataPage & {
65+
filters: Record<string, FEFootballCompetition[]>;
6466
tables: FEFootballTable[];
6567
};

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
{
44
"type": "object",
55
"properties": {
6-
"filters": {
7-
"$ref": "#/definitions/Record<string,FEFootballCompetition[]>"
8-
},
96
"nav": {
107
"$ref": "#/definitions/FENavType"
118
},
@@ -35,7 +32,6 @@
3532
"config",
3633
"contributionsServiceUrl",
3734
"editionId",
38-
"filters",
3935
"guardianBaseURL",
4036
"isAdFreeUser",
4137
"nav",
@@ -45,6 +41,9 @@
4541
{
4642
"type": "object",
4743
"properties": {
44+
"filters": {
45+
"$ref": "#/definitions/Record<string,FEFootballCompetition[]>"
46+
},
4847
"matchesList": {
4948
"type": "array",
5049
"items": {
@@ -116,14 +115,12 @@
116115
}
117116
},
118117
"required": [
118+
"filters",
119119
"matchesList"
120120
]
121121
}
122122
],
123123
"definitions": {
124-
"Record<string,FEFootballCompetition[]>": {
125-
"type": "object"
126-
},
127124
"FENavType": {
128125
"type": "object",
129126
"properties": {
@@ -682,6 +679,9 @@
682679
"url"
683680
]
684681
},
682+
"Record<string,FEFootballCompetition[]>": {
683+
"type": "object"
684+
},
685685
"FEFootballMatch": {
686686
"anyOf": [
687687
{

0 commit comments

Comments
 (0)