Skip to content
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

Move AMP iframe and Psammead components to MediaLoader #11994

Merged
merged 67 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f53d5cd
AMP Iframe + externalEmbedurl constructor
amoore108 Sep 11, 2024
b49e8f5
Update urlConstructors.ts
amoore108 Sep 11, 2024
f46d0c3
Integration snapshot updates
amoore108 Sep 11, 2024
b153cb9
Test fix
amoore108 Sep 11, 2024
cfacfa5
Logic updates
amoore108 Sep 12, 2024
739c32d
Port over media `Message` component for AMP
amoore108 Sep 12, 2024
fc2e4cf
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 19, 2024
fa3d8bc
Type updates
amoore108 Sep 19, 2024
9037d90
Placeholder styling
amoore108 Sep 19, 2024
1c2d059
base tests
amoore108 Sep 19, 2024
3cd2020
Remove ArticleMediaPlayer component
amoore108 Sep 19, 2024
3b4228d
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 19, 2024
65a5d49
Migrate `PlayButton` component
amoore108 Sep 19, 2024
02b0e4a
Migrate `Guidance` component
amoore108 Sep 19, 2024
28fbb2d
Snapshot updates
amoore108 Sep 19, 2024
0e325b6
Type updates + unit snapshots
amoore108 Sep 19, 2024
b3a75e1
Simplify placeholder display state
amoore108 Sep 19, 2024
cfcd802
nextjs snapshot updates
amoore108 Sep 19, 2024
3b8e225
Fix AMP placeholder
amoore108 Sep 19, 2024
5c464be
Add missing `placeholderSrcSet` prop
amoore108 Sep 19, 2024
f5b04f9
Add correct translations for no JS messaging
amoore108 Sep 19, 2024
554a9d1
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 19, 2024
b464d33
Translation updates
amoore108 Sep 19, 2024
cac7135
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 20, 2024
ea44903
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 20, 2024
a9cfd30
noJs display fixes
amoore108 Sep 20, 2024
4fe73e3
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 23, 2024
4f3c867
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 23, 2024
8727304
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 23, 2024
060b33b
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 24, 2024
affd484
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 25, 2024
6fc2a9a
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 26, 2024
d2d9299
Some AMP layout fixes for portrait
amoore108 Sep 26, 2024
924a108
working but don't like it
amoore108 Sep 26, 2024
6ae3806
Remove nested ternary
amoore108 Sep 26, 2024
e723dca
Default orientation to 'landscape'
amoore108 Sep 26, 2024
3e141d6
More snapshot updates
amoore108 Sep 26, 2024
b713efa
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 26, 2024
68de78b
Update index.test.tsx.snap
amoore108 Sep 26, 2024
a254b49
invert `embedded` checks
amoore108 Sep 26, 2024
5de5724
Simplify landscape/portrait CSS
amoore108 Sep 27, 2024
b30ce1a
Only set aspectRatio for certain media types
amoore108 Sep 27, 2024
add8ade
More snapshot updates
amoore108 Sep 27, 2024
a7f0fdb
Add Storybook story for portrait player
amoore108 Sep 27, 2024
994be3c
noscript image fix
amoore108 Sep 27, 2024
454bf0c
Simplify audio style selection and config
amoore108 Sep 27, 2024
e6a216c
Set aspect ratio CSS for `classic` skin only
amoore108 Sep 27, 2024
61c6320
Update index.tsx
amoore108 Sep 27, 2024
2a4f226
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 30, 2024
25548b3
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 30, 2024
e2ab09b
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Sep 30, 2024
f6f9da3
Delete `AVPlayer` and `MediaPlayer` components
amoore108 Sep 30, 2024
56291a1
Move `Message` up a level
amoore108 Sep 30, 2024
786b3af
alias fix
amoore108 Sep 30, 2024
87de1e9
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Oct 1, 2024
1cf343c
Remove media iframe related for ODTV/ODAudio
amoore108 Oct 1, 2024
1ecda0a
Add AMP prop types
amoore108 Oct 1, 2024
af09561
Delete legacy `Caption`, `psammead-caption` and `psammead-play-button`
amoore108 Oct 1, 2024
de9ef51
Delete `psammead-figure`
amoore108 Oct 1, 2024
556ba6d
Delete old `getEmbedUrl` functions
amoore108 Oct 1, 2024
7370519
Update index.js
amoore108 Oct 1, 2024
e56d62f
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Oct 1, 2024
29243fd
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Oct 1, 2024
fcf14a9
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Oct 2, 2024
45da045
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Oct 2, 2024
4b89f31
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Oct 2, 2024
2e0f518
Merge branch 'latest' into amp-iframe-externalembed-constructor
amoore108 Oct 4, 2024
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
26 changes: 26 additions & 0 deletions src/app/components/MediaLoader/Amp/index.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import BASE64_PLACEHOLDER_IMAGE from '#app/components/Image/base64Placeholder';
import { css, Theme } from '@emotion/react';

export default {
ampIframeWrapper: ({ palette }: Theme) =>
css({
position: 'relative',
overflow: 'hidden',
backgroundColor: palette.LUNAR,
height: '100%',
}),
ampIframePlaceholder: ({ mq }: Theme) =>
css({
backgroundImage: `url(${BASE64_PLACEHOLDER_IMAGE})`,
backgroundPosition: 'center center',
backgroundRepeat: ' no-repeat',
backgroundSize: '60px 17px',

[mq.GROUP_2_MIN_WIDTH]: {
backgroundSize: ' 77px 22px',
},
[mq.GROUP_4_MIN_WIDTH]: {
backgroundSize: ' 93px 27px',
},
}),
};
38 changes: 38 additions & 0 deletions src/app/components/MediaLoader/Amp/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import {
act,
render,
} from '#app/components/react-testing-library-with-providers';
import Amp from './index';

const mockAmpIframeUrl = 'https://www.bbc.com/news/av-embeds/123456789';

describe('Amp', () => {
it('should render an amp-iframe with the correct attributes', async () => {
let container;

await act(async () => {
({ container } = render(<Amp src={mockAmpIframeUrl} />));
});

const ampIframe = (container as unknown as HTMLElement).querySelector(
'amp-iframe',
);

expect(ampIframe).toBeInTheDocument();
});

it('should render amp-iframe placeholder', async () => {
let container;

await act(async () => {
({ container } = render(<Amp src={mockAmpIframeUrl} />));
});

const ampImg = (container as unknown as HTMLElement).querySelector(
'amp-iframe > div',
);

expect(ampImg).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
/** @jsx jsx */

import { jsx } from '@emotion/react';
import { Helmet } from 'react-helmet';
import ImagePlaceholder from '#psammead/psammead-image-placeholder/src';
import Message from '../Message';
import styles from './index.styles';

const AmpHead = () => (
<Helmet>
Expand All @@ -13,39 +15,51 @@ const AmpHead = () => (
</Helmet>
);

const AmpMediaPlayer = ({
type Props = {
src?: string;
placeholderSrc?: string;
placeholderSrcset?: string;
title?: string;
noJsMessage?: string;
};

const AmpMediaLoader = ({
src,
placeholderSrc,
placeholderSrcset = null,
placeholderSrcset,
title,
noJsMessage,
service,
}) => {
}: Props) => {
return (
<>
<div css={styles.ampIframeWrapper}>
<AmpHead />
<amp-iframe
sandbox="allow-scripts allow-same-origin"
layout="fill"
// @ts-expect-error - 'scrolling' does not exist in type
scrolling="no"
frameborder="0"
src={src}
title={title}
allowfullscreen="allowfullscreen"
data-e2e="media-player"
>
<ImagePlaceholder ratio={56.25} placeholder="" />
<div
data-e2e="image-placeholder"
// @ts-expect-error - 'placeholder' does not exist in type. This is used by AMP to show a placeholder image while the iframe is loading
placeholder=""
css={styles.ampIframePlaceholder}
amoore108 marked this conversation as resolved.
Show resolved Hide resolved
/>
<noscript>
<Message
service={service}
message={noJsMessage}
placeholderSrc={placeholderSrc}
placeholderSrcset={placeholderSrcset}
/>
</noscript>
</amp-iframe>
</>
</div>
);
};

export default AmpMediaPlayer;
export default AmpMediaLoader;
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

exports[`Media Message matches media message snapshot 1`] = `
.emotion-0 {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.emotion-2 {
font-family: Helmet,Freesans,Helvetica,Arial,sans-serif;
font-weight: 400;
font-family: ReithSans,Helvetica,Arial,sans-serif;
font-style: normal;
font-weight: 400;
font-size: 0.9375rem;
line-height: 1.125rem;
width: 100%;
Expand All @@ -25,47 +17,53 @@ exports[`Media Message matches media message snapshot 1`] = `
background-color: rgba(34, 34, 34, 0.75);
}

@media (min-width: 20rem) and (max-width: 37.4375rem) {
.emotion-0 {
font-size: 0.9375rem;
line-height: 1.125rem;
}
}

@media (min-width: 37.5rem) {
.emotion-2 {
.emotion-0 {
font-size: 0.875rem;
line-height: 1.125rem;
}
}

@media screen and (-ms-high-contrast: active) {
.emotion-2 {
@media screen and (forced-colors: active) {
.emotion-0 {
background-color: transparent;
}
}

.emotion-4 {
.emotion-1 {
display: block;
font-weight: normal;
bottom: 0;
position: absolute;
padding: 0.5rem;
}

@media screen and (-ms-high-contrast: active) {
.emotion-4 {
background-color: window;
@media (min-width: 25rem) {
.emotion-1 {
padding: 1rem;
}
}

@media (min-width: 25rem) {
.emotion-4 {
padding: 1rem;
@media screen and (forced-colors: active) {
.emotion-1 {
background-color: window;
}
}

<div>
<div
class="emotion-0 emotion-1"
>
<div>
<div
class="emotion-2 emotion-3"
class="emotion-0"
>
<strong
class="emotion-4 emotion-5"
class="emotion-1"
>
Контент більше не доступний
</strong>
Expand Down
44 changes: 44 additions & 0 deletions src/app/components/MediaLoader/Message/index.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { css, Theme } from '@emotion/react';

const NOJS_BACKGROUND_COLOUR = 'rgba(34, 34, 34, 0.75)';

export default {
messageWrapper: ({ fontVariants, fontSizes, palette, mq }: Theme) =>
css({
...fontVariants.sansRegular,
...fontSizes.longPrimer,
width: '100%',
height: '100%',
position: 'absolute',
top: 0,
left: 0,
border: `0.0625rem solid transparent`,
color: palette.WHITE,
backgroundColor: NOJS_BACKGROUND_COLOUR,

[mq.FORCED_COLOURS]: {
backgroundColor: 'transparent',
},
}),
message: ({ spacings, mq }: Theme) =>
css({
display: 'block',
fontWeight: 'normal',
bottom: 0,
position: 'absolute',
padding: `${spacings.FULL}rem`,
[mq.GROUP_2_MIN_WIDTH]: {
padding: `${spacings.DOUBLE}rem`,
},
[mq.FORCED_COLOURS]: {
backgroundColor: 'window',
},
}),
messageImage: () =>
css({
position: 'absolute',
inset: 0,
width: '100%',
height: '100%',
}),
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';
import { render } from '../../../../components/react-testing-library-with-providers';
import { render } from '#app/components/react-testing-library-with-providers';
import Message from './index';

describe('Media Message', () => {
it('should display the media message', () => {
const { getByText } = render(
<Message
service="news"
message="Please enable Javascript or try a different browser"
placeholderSrc="http://foo.bar/placeholder.png"
placeholderSrcset="http://foo.bar/placeholder.png"
Expand All @@ -20,7 +19,7 @@ describe('Media Message', () => {

it('matches media message snapshot', () => {
const { container } = render(
<Message message="Контент більше не доступний" service="ukrainian" />,
<Message message="Контент більше не доступний" />,
);
expect(container).toMatchSnapshot();
});
Expand Down
33 changes: 33 additions & 0 deletions src/app/components/MediaLoader/Message/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @jsx jsx */

import { jsx } from '@emotion/react';
import styles from './index.styles';

type Props = {
message?: string;
placeholderSrc?: string;
placeholderSrcset?: string;
};

const Message = ({
message = '',
placeholderSrc = '',
placeholderSrcset = '',
}: Props) => (
<div>
{placeholderSrc && (
<img
alt=""
src={placeholderSrc}
srcSet={placeholderSrcset}
aria-hidden="true"
css={styles.messageImage}
/>
)}
<div css={styles.messageWrapper}>
<strong css={styles.message}>{message}</strong>
</div>
</div>
);

export default Message;
Loading
Loading