Skip to content

Track card media in data-link-name #14400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../../lib/articleFormat';
import { isMediaCard } from '../../lib/cardHelpers';
import { isWithinTwelveHours, secondsToDuration } from '../../lib/formatTime';
import { appendLinkNameMedia } from '../../lib/getDataLinkName';
import { getZIndex } from '../../lib/getZIndex';
import { DISCUSSION_ID_DATA_ATTRIBUTE } from '../../lib/useCommentCount';
import { BETA_CONTAINERS } from '../../model/enhanceCollections';
Expand Down Expand Up @@ -268,7 +269,7 @@ const getMedia = ({
}
if (mainMedia?.type === 'Video' && canPlayInline) {
return {
type: 'video',
type: 'youtube-video',
mainMedia,
} as const;
}
Expand Down Expand Up @@ -566,6 +567,11 @@ export const Card = ({
isBetaContainer,
});

const resolvedDataLinkName =
media && dataLinkName
? appendLinkNameMedia(dataLinkName, media.type)
: dataLinkName;

/**
* For opinion type cards with avatars (which aren't onwards content)
* we render the footer in a different location
Expand Down Expand Up @@ -757,7 +763,7 @@ export const Card = ({
<CardLink
linkTo={linkTo}
headlineText={headlineText}
dataLinkName={dataLinkName}
dataLinkName={resolvedDataLinkName}
isExternalLink={isExternalLink}
/>
{headlinePosition === 'outer' && (
Expand Down Expand Up @@ -899,7 +905,7 @@ export const Card = ({
/>
</Island>
)}
{media.type === 'video' && (
{media.type === 'youtube-video' && (
<>
{showVideo ? (
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@emotion/react';
import { isUndefined } from '@guardian/libs';
import { from, space } from '@guardian/source/foundations';
import type { CardImageType } from '../../../types/layout';
import type { CardMediaType } from '../../../types/layout';
import type { ImagePositionType } from './ImageWrapper';

export type GapSize = 'none' | 'tiny' | 'small' | 'medium' | 'large';
Expand All @@ -11,7 +11,7 @@ export type GapSizes = { row: GapSize; column: GapSize };
type Props = {
children: React.ReactNode;
cardBackgroundColour: string;
imageType: CardImageType | undefined;
imageType: CardMediaType | undefined;
imagePositionOnDesktop: ImagePositionType;
imagePositionOnMobile: ImagePositionType;
minWidthInPixels?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SerializedStyles } from '@emotion/react';
import { css } from '@emotion/react';
import { between, from, space, until } from '@guardian/source/foundations';
import type { CardImageType } from '../../../types/layout';
import type { CardMediaType } from '../../../types/layout';
import type { ImagePositionType, ImageSizeType } from './ImageWrapper';

const sizingStyles = css`
Expand All @@ -21,7 +21,7 @@ const flexBasisStyles = ({
isBetaContainer,
}: {
imageSize: ImageSizeType;
imageType?: CardImageType;
imageType?: CardMediaType;
isBetaContainer: boolean;
}): SerializedStyles => {
if (imageType === 'avatar') {
Expand Down Expand Up @@ -115,7 +115,7 @@ const getImageDirection = (

type Props = {
children: React.ReactNode;
imageType?: CardImageType;
imageType?: CardMediaType;
imageSize: ImageSizeType;
isBetaContainer: boolean;
imagePositionOnDesktop: ImagePositionType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SerializedStyles } from '@emotion/react';
import { css } from '@emotion/react';
import { between, from, space, until } from '@guardian/source/foundations';
import type { CardImageType } from '../../../types/layout';
import type { CardMediaType } from '../../../types/layout';

const imageFixedSize = {
tiny: 86,
Expand Down Expand Up @@ -34,7 +34,7 @@ type Props = {
children: React.ReactNode;
imageSize: ImageSizeType;
imageFixedSizes?: ImageFixedSizeOptions;
imageType?: CardImageType;
imageType?: CardMediaType;
imagePositionOnDesktop: ImagePositionType;
imagePositionOnMobile: ImagePositionType;
/**
Expand Down Expand Up @@ -173,7 +173,7 @@ export const ImageWrapper = ({
css={[
(imageType === 'slideshow' ||
imageType === 'picture' ||
imageType === 'video' ||
imageType === 'youtube-video' ||
imageType === 'loop-video') &&
isHorizontalOnDesktop &&
flexBasisStyles({
Expand Down
12 changes: 11 additions & 1 deletion dotcom-rendering/src/lib/getDataLinkName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FEFrontCardStyle } from '../frontend/feFront';
import type { RichLinkCardType } from '../types/layout';
import type { CardMediaType, RichLinkCardType } from '../types/layout';
import {
ArticleDesign,
type ArticleFormat,
Expand Down Expand Up @@ -58,6 +58,7 @@ export type Group = `${number}` | `${number}+`;
*
* @see {JSX.IntrinsicAttributes}
*/

export const getDataLinkNameCard = (
format: ArticleFormat,
group: Group,
Expand All @@ -69,3 +70,12 @@ export const getDataLinkNameCard = (
`group-${group}`,
`card-@${Math.max(index + 1, 1)}`,
].join(' | ');

type MediaType = CardMediaType | 'none';

export const appendLinkNameMedia = (
dataLinkName: string,
mediaType: MediaType,
): string => {
return `${dataLinkName} | media-${mediaType}`;
};
4 changes: 2 additions & 2 deletions dotcom-rendering/src/types/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export type RichLinkCardType =
| 'external'
| 'news';

export type CardImageType =
export type CardMediaType =
| 'picture'
| 'avatar'
| 'crossword'
| 'slideshow'
| 'video'
| 'youtube-video'
| 'loop-video'
| 'podcast';

Expand Down