Skip to content

Commit

Permalink
Merge branch 'main' into editions-crossword-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCliftonGuardian authored Nov 21, 2024
2 parents 3faaa42 + 26d523e commit 5a65b8d
Show file tree
Hide file tree
Showing 47 changed files with 486 additions and 79,728 deletions.
2,402 changes: 0 additions & 2,402 deletions dotcom-rendering/fixtures/generated/dcr-articles/Analysis.ts

This file was deleted.

2,070 changes: 0 additions & 2,070 deletions dotcom-rendering/fixtures/generated/dcr-articles/Audio.ts

This file was deleted.

2,126 changes: 0 additions & 2,126 deletions dotcom-rendering/fixtures/generated/dcr-articles/Comment.ts

This file was deleted.

4,773 changes: 0 additions & 4,773 deletions dotcom-rendering/fixtures/generated/dcr-articles/Dead.ts

This file was deleted.

2,029 changes: 0 additions & 2,029 deletions dotcom-rendering/fixtures/generated/dcr-articles/Editorial.ts

This file was deleted.

2,977 changes: 0 additions & 2,977 deletions dotcom-rendering/fixtures/generated/dcr-articles/Explainer.ts

This file was deleted.

2,550 changes: 0 additions & 2,550 deletions dotcom-rendering/fixtures/generated/dcr-articles/Feature.ts

This file was deleted.

2,070 changes: 0 additions & 2,070 deletions dotcom-rendering/fixtures/generated/dcr-articles/Gallery.ts

This file was deleted.

3,958 changes: 0 additions & 3,958 deletions dotcom-rendering/fixtures/generated/dcr-articles/Interview.ts

This file was deleted.

3,059 changes: 0 additions & 3,059 deletions dotcom-rendering/fixtures/generated/dcr-articles/Labs.ts

This file was deleted.

1,897 changes: 0 additions & 1,897 deletions dotcom-rendering/fixtures/generated/dcr-articles/Letter.ts

This file was deleted.

4,773 changes: 0 additions & 4,773 deletions dotcom-rendering/fixtures/generated/dcr-articles/Live.ts

This file was deleted.

5,866 changes: 0 additions & 5,866 deletions dotcom-rendering/fixtures/generated/dcr-articles/LiveBlogSingleContributor.ts

This file was deleted.

2,025 changes: 0 additions & 2,025 deletions dotcom-rendering/fixtures/generated/dcr-articles/MatchReport.ts

This file was deleted.

2,002 changes: 0 additions & 2,002 deletions dotcom-rendering/fixtures/generated/dcr-articles/NewsletterSignup.ts

This file was deleted.

8,207 changes: 0 additions & 8,207 deletions dotcom-rendering/fixtures/generated/dcr-articles/NumberedList.ts

This file was deleted.

9,480 changes: 0 additions & 9,480 deletions dotcom-rendering/fixtures/generated/dcr-articles/PhotoEssay.ts

This file was deleted.

1,926 changes: 0 additions & 1,926 deletions dotcom-rendering/fixtures/generated/dcr-articles/Picture.ts

This file was deleted.

2,545 changes: 0 additions & 2,545 deletions dotcom-rendering/fixtures/generated/dcr-articles/Quiz.ts

This file was deleted.

2,184 changes: 0 additions & 2,184 deletions dotcom-rendering/fixtures/generated/dcr-articles/Recipe.ts

This file was deleted.

2,399 changes: 0 additions & 2,399 deletions dotcom-rendering/fixtures/generated/dcr-articles/Review.ts

This file was deleted.

2,430 changes: 0 additions & 2,430 deletions dotcom-rendering/fixtures/generated/dcr-articles/SpecialReport.ts

This file was deleted.

2,070 changes: 0 additions & 2,070 deletions dotcom-rendering/fixtures/generated/dcr-articles/Standard.ts

This file was deleted.

2,074 changes: 0 additions & 2,074 deletions dotcom-rendering/fixtures/generated/dcr-articles/StandardWithVideo.ts

This file was deleted.

1,643 changes: 0 additions & 1,643 deletions dotcom-rendering/fixtures/generated/dcr-articles/Video.ts

This file was deleted.

26 changes: 2 additions & 24 deletions dotcom-rendering/scripts/test-data/gen-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { config } = require('../../fixtures/config');
const { configOverrides } = require('../../fixtures/config-overrides');
const { switchOverrides } = require('../../fixtures/switch-overrides');
const { validateAsArticleType } = require('../../src/model/validate');
const { enhanceArticleType } = require('../../src/types/article');

const root = resolve(__dirname, '..', '..');

Expand Down Expand Up @@ -174,44 +173,23 @@ const requests = articles.map((article) => {
}

const frontendData = validateAsArticleType(frontendJson);
const dcrArticle = enhanceArticleType(frontendData);

// manual hack for Video articles
if (article.name === 'Video') {
dcrArticle.frontendData.config.source = 'TMN';
}

// Write the new DCR fixture data
const dcrContents = `${HEADER}
import type { Article } from '../../../src/types/article';
export const ${article.name}: Article = ${JSON.stringify(dcrArticle, null, 4)}
`;

const dcrTypeFile = fs.writeFile(
`${root}/fixtures/generated/dcr-articles/${article.name}.ts`,
dcrContents,
'utf8',
);

// Write the new frontend fixture data
const frontendContents = `${HEADER}
import type { FEArticleType } from '../../../src/types/frontend';
export const ${article.name}: FEArticleType = ${JSON.stringify(
frontendJson,
frontendData,
null,
4,
)}
`;

const frontendTypeFile = fs.writeFile(
return fs.writeFile(
`${root}/fixtures/generated/fe-articles/${article.name}.ts`,
frontendContents,
'utf8',
);

return Promise.all([frontendTypeFile, dcrTypeFile]);
})
.then(() => `${article.name}.ts`)
.catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/ArticleBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { ArticleRenderer } from '../lib/ArticleRenderer';
import type { EditionId } from '../lib/edition';
import { decideLanguage, decideLanguageDirection } from '../lib/lang';
import { revealStyles } from '../lib/revealStyles';
import type { TableOfContentsItem } from '../model/enhanceTableOfContents';
import { palette as themePalette } from '../palette';
import type { TableOfContentsItem } from '../types/article';
import type { Block } from '../types/blocks';
import type { ServerSideTests, Switches } from '../types/config';
import type { TagType } from '../types/tag';
Expand Down
36 changes: 29 additions & 7 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { LatestLinks } from '../LatestLinks.importable';
import { MediaDuration } from '../MediaDuration';
import { MediaMeta } from '../MediaMeta';
import { Slideshow } from '../Slideshow';
import { SlideshowCarousel } from '../SlideshowCarousel.importable';
import { Snap } from '../Snap';
import { SnapCssSandbox } from '../SnapCssSandbox';
import { StarRating } from '../StarRating/StarRating';
Expand Down Expand Up @@ -604,14 +605,35 @@ export const Card = ({
imagePositionOnDesktop={imagePositionOnDesktop}
imagePositionOnMobile={imagePositionOnMobile}
showPlayIcon={showPlayIcon}
hideImageOverlay={
media.type === 'slideshow' && isFlexibleContainer
}
>
{media.type === 'slideshow' && (
<Slideshow
images={media.slideshowImages}
imageSize={imageSize}
isDynamo={isDynamo}
/>
)}
{media.type === 'slideshow' &&
(isFlexibleContainer ? (
<div
css={css`
position: relative;
${getZIndex('card-nested-link')}
`}
>
<Island
priority="feature"
defer={{ until: 'visible' }}
>
<SlideshowCarousel
images={media.slideshowImages}
imageSize={imageSize}
/>
</Island>
</div>
) : (
<Slideshow
images={media.slideshowImages}
imageSize={imageSize}
isDynamo={isDynamo}
/>
))}
{media.type === 'avatar' && (
<AvatarContainer
imageSize={imageSize}
Expand Down
12 changes: 9 additions & 3 deletions dotcom-rendering/src/components/Card/components/ImageWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ type Props = {
imagePositionOnDesktop: ImagePositionType;
imagePositionOnMobile: ImagePositionType;
showPlayIcon: boolean;
/**
* Forces hiding the image overlay added to pictures & slideshows on hover.
* This is to allow hiding the overlay on slideshow carousels where we don't
* want it to be shown whilst retaining it for existing slideshows.
*/
hideImageOverlay?: boolean;
};

/**
Expand Down Expand Up @@ -117,6 +123,7 @@ export const ImageWrapper = ({
imagePositionOnDesktop,
imagePositionOnMobile,
showPlayIcon,
hideImageOverlay,
}: Props) => {
const isHorizontalOnDesktop =
imagePositionOnDesktop === 'left' || imagePositionOnDesktop === 'right';
Expand Down Expand Up @@ -168,9 +175,8 @@ export const ImageWrapper = ({
<>
{children}
{/* This image overlay is styled when the CardLink is hovered */}
{(imageType === 'picture' || imageType === 'slideshow') && (
<div className="image-overlay" />
)}
{(imageType === 'picture' || imageType === 'slideshow') &&
!hideImageOverlay && <div className="image-overlay" />}
{imageType === 'picture' && showPlayIcon && (
<PlayIcon
imageSize={imageSize}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ABTestAPI } from '@guardian/ab-core';
import { getCookie } from '@guardian/libs';
import { useEffect, useState } from 'react';
import type { DailyArticle } from '../lib/dailyArticleCount';
Expand All @@ -8,6 +9,69 @@ import { ExpandableMarketingCard } from './ExpandableMarketingCard';
import { ExpandableMarketingCardSwipeable } from './ExpandableMarketingCardSwipeable';
import { Hide } from './Hide';

type VariantName = 'variant-free' | 'variant-bubble' | 'variant-billionaire';
type Variant = {
heading: string;
kicker: string;
};
const variantFree: Variant = {
heading: 'Yes, this story is free',
kicker: 'Why the Guardian has no paywall',
};
const variantBubble: Variant = {
heading: 'Pop your US news bubble',
kicker: 'How the Guardian is different',
};
const variantBillionaire: Variant = {
heading: 'No billionaire approved this',
kicker: 'How the Guardian is different',
};

const getVariant = (abTestAPI: ABTestAPI | undefined): VariantName | null => {
if (!abTestAPI) {
return null;
}

const isInVariantFree = abTestAPI.isUserInVariant(
'UsaExpandableMarketingCard',
'variant-free',
);
const isInVariantBubble = abTestAPI.isUserInVariant(
'UsaExpandableMarketingCard',
'variant-bubble',
);
const isInVariantBillionaire = abTestAPI.isUserInVariant(
'UsaExpandableMarketingCard',
'variant-billionaire',
);

if (isInVariantFree) {
return 'variant-free';
}

if (isInVariantBubble) {
return 'variant-bubble';
}

if (isInVariantBillionaire) {
return 'variant-billionaire';
}

return null;
};

const getVariantCopy = (variant: VariantName): Variant => {
if (variant === 'variant-free') {
return variantFree;
}

if (variant === 'variant-bubble') {
return variantBubble;
}

return variantBillionaire;
};

const isFirstOrSecondArticle = () => {
const [dailyCount = {} as DailyArticle] = getDailyArticleCount() ?? [];
return Object.keys(dailyCount).length === 0 || dailyCount.count <= 1;
Expand Down Expand Up @@ -40,15 +104,7 @@ export const ExpandableMarketingCardWrapper = ({ guardianBaseURL }: Props) => {
const [isApplicableUser, setIsApplicableUser] = useState(false);

const abTestAPI = useAB()?.api;
const isInVariantFree = !!abTestAPI?.isUserInVariant(
'UsaExpandableMarketingCard',
'variant-free',
);
const isInVariantBubble = !!abTestAPI?.isUserInVariant(
'UsaExpandableMarketingCard',
'variant-bubble',
);
const isInEitherVariant = isInVariantFree || isInVariantBubble;
const abTestVariant = getVariant(abTestAPI);

useEffect(() => {
void isNewUSUser().then((show) => {
Expand All @@ -58,12 +114,11 @@ export const ExpandableMarketingCardWrapper = ({ guardianBaseURL }: Props) => {
});
}, []);

if (!isInEitherVariant || !isApplicableUser || isClosed) {
if (!abTestVariant || !isApplicableUser || isClosed) {
return null;
}

const heading = 'No billionaire approved this';
const kicker = 'How the Guardian is different';
const { heading, kicker } = getVariantCopy(abTestVariant);

return (
<>
Expand Down
5 changes: 4 additions & 1 deletion dotcom-rendering/src/components/FlexibleGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ export const StandardCardLayout = ({
image={showImage ? card.image : undefined}
imageLoading={imageLoading}
imagePositionOnDesktop={'left'}
supportingContent={card.supportingContent}
supportingContent={card.supportingContent?.slice(
0,
2,
)}
supportingContentAlignment="vertical"
supportingContentPosition="outer"
imageSize={'medium'}
Expand Down
42 changes: 40 additions & 2 deletions dotcom-rendering/src/components/GetMatchNav.importable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { css } from '@emotion/react';
import { isObject } from '@guardian/libs';
import { from } from '@guardian/source/foundations';
import type { SWRConfiguration } from 'swr';
import { ArticleDesign, type ArticleFormat } from '../lib/articleFormat';
Expand Down Expand Up @@ -36,6 +37,36 @@ const fallbackData = {
awayTeam: fallbackTeam,
} satisfies MatchData;

const validateMatchData = (data: unknown): data is MatchData => {
if (!isObject(data)) {
return false;
}

const homeTeam = data.homeTeam;
if (
!isObject(homeTeam) ||
typeof homeTeam.name !== 'string' ||
homeTeam.name.length === 0 ||
typeof homeTeam.score !== 'number' ||
isNaN(homeTeam.score)
) {
return false;
}

const awayTeam = data.awayTeam;
if (
!isObject(awayTeam) ||
typeof awayTeam.name !== 'string' ||
awayTeam.name.length === 0 ||
typeof awayTeam.score !== 'number' ||
isNaN(awayTeam.score)
) {
return false;
}

return true;
};

/**
* Wrapper around `MatchNav` with loading and fallback.
*
Expand Down Expand Up @@ -97,7 +128,14 @@ export const GetMatchNav = ({
);
}
}
if (data) {

if (!data) {
// this should never happen because we pass fallback data to SWR
return null;
}

const isDataValid = validateMatchData(data);
if (isDataValid) {
return (
<MatchNav
homeTeam={data.homeTeam}
Expand All @@ -107,6 +145,6 @@ export const GetMatchNav = ({
);
}

// this should never happen because we pass fallback data to SWR
// Invalid data indicates that we do not have the data for this fixture, likely because the match is old.
return null;
};
Loading

0 comments on commit 5a65b8d

Please sign in to comment.