From cfbd8a9673821eac307fdec0f54deded8a83d93c Mon Sep 17 00:00:00 2001 From: Max Duval Date: Tue, 16 Jan 2024 10:04:40 +0000 Subject: [PATCH] refactor(YoutubeAtom): no reliance on elementId the uniqueId only needs to be truly unique on the client-side which can be simply achieved with an increasing integer update tests to use regular expression matching --- dotcom-rendering/src/components/Card/Card.tsx | 3 -- .../YoutubeAtom/YoutubeAtom.stories.tsx | 28 ------------------- .../YoutubeAtom/YoutubeAtom.test.tsx | 9 ------ .../components/YoutubeAtom/YoutubeAtom.tsx | 23 +++++++++------ .../YoutubeBlockComponent.importable.tsx | 3 -- .../YoutubeBlockComponent.stories.tsx | 7 ----- dotcom-rendering/src/lib/renderElement.tsx | 1 - 7 files changed, 15 insertions(+), 59 deletions(-) diff --git a/dotcom-rendering/src/components/Card/Card.tsx b/dotcom-rendering/src/components/Card/Card.tsx index af4e2f53b65..2d3cb2dfc66 100644 --- a/dotcom-rendering/src/components/Card/Card.tsx +++ b/dotcom-rendering/src/components/Card/Card.tsx @@ -474,9 +474,6 @@ export const Card = ({ > { return (
{ return (
{
{
{
{
{
Scroll down...
{
Scroll down...
{ return (
{ />
{ return (
{ adTargeting={adTargeting} /> { adTargeting={adTargeting} /> {
Scroll down...
{ return (
{ return (
{ return (
{ return (
{ return (
{ return (
{
{
⬇️
{
⬇️
{ return (
{ />
{ return (
{ abTestParticipations={{}} /> { abTestParticipations={{}} /> { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { value={{ renderingTarget: 'Web', darkModeAvailable: false }} > { abTestParticipations={{}} /> (false); const [isClosed, setIsClosed] = useState(false); const [pauseVideo, setPauseVideo] = useState(false); + const [uniqueId, setUniqueId] = useState(); + + useEffect(() => { + index ??= 0; + index++; + setUniqueId(`${videoId}-${index}`); + }, [videoId]); - const uniqueId = `${videoId}-${elementId}`; const enableIma = imaEnabled && !!adTargeting && @@ -152,7 +159,7 @@ export const YoutubeAtom = ({ return ( - {loadPlayer && consentState && adTargeting && ( + {loadPlayer && consentState && adTargeting && !!uniqueId && ( )} {showPlaceholder && ( - + )} diff --git a/dotcom-rendering/src/components/YoutubeBlockComponent.importable.tsx b/dotcom-rendering/src/components/YoutubeBlockComponent.importable.tsx index c3527a6f2b8..954a099d4c2 100644 --- a/dotcom-rendering/src/components/YoutubeBlockComponent.importable.tsx +++ b/dotcom-rendering/src/components/YoutubeBlockComponent.importable.tsx @@ -13,7 +13,6 @@ import { YoutubeAtom } from './YoutubeAtom/YoutubeAtom'; type Props = { id: string; - elementId: string; mediaTitle?: string; altText?: string; assetId: string; @@ -89,7 +88,6 @@ const getLargestImageSize = ( export const YoutubeBlockComponent = ({ id, - elementId, assetId, mediaTitle, altText, @@ -200,7 +198,6 @@ export const YoutubeBlockComponent = ({ return (
{ assetId="d2Q5bXvEgMg" mediaTitle="Prince Harry and Meghan's 'bombshell' plans explained – video" id="c2b8a51c-cb3d-41e7-bb79-1d9a091d0c28" - elementId="5ab531a2-f6ea-499d-b274-191114c8628c" expired={false} stickyVideos={false} /> @@ -83,7 +82,6 @@ export const Vertical = () => { assetId="d2Q5bXvEgMg" mediaTitle="Prince Harry and Meghan's 'bombshell' plans explained – video" id="c2b8a51c-cb3d-41e7-bb79-1d9a091d0c28" - elementId="5ab531a2-f6ea-499d-b274-191114c8628c" expired={false} height={259} width={460} @@ -118,7 +116,6 @@ export const Expired = () => { assetId="d2Q5bXvEgMg" mediaTitle="Prince Harry and Meghan's 'bombshell' plans explained – video" id="c2b8a51c-cb3d-41e7-bb79-1d9a091d0c28" - elementId="5ab531a2-f6ea-499d-b274-191114c8628c" expired={true} overrideImage="https://i.guim.co.uk/img/media/49565a29c6586fe6b748926e0be96c5e9c90473c/0_0_4981_2989/500.jpg?quality=85&auto=format&fit=max&s=17c70ec70002ea34886fd6c2605cd81e" height={259} @@ -154,7 +151,6 @@ export const WithOverlayImage = () => { assetId="d2Q5bXvEgMg" mediaTitle="Prince Harry and Meghan's 'bombshell' plans explained – video" id="c2b8a51c-cb3d-41e7-bb79-1d9a091d0c28" - elementId="5ab531a2-f6ea-499d-b274-191114c8628c" expired={false} duration={333} overrideImage="https://i.guim.co.uk/img/media/49565a29c6586fe6b748926e0be96c5e9c90473c/0_0_4981_2989/500.jpg?quality=85&auto=format&fit=max&s=17c70ec70002ea34886fd6c2605cd81e" @@ -191,7 +187,6 @@ export const WithPosterImage = () => { assetId="d2Q5bXvEgMg" mediaTitle="Prince Harry and Meghan's 'bombshell' plans explained – video" id="c2b8a51c-cb3d-41e7-bb79-1d9a091d0c28" - elementId="5ab531a2-f6ea-499d-b274-191114c8628c" expired={false} duration={333} posterImage={[ @@ -249,7 +244,6 @@ export const WithPosterAndOverlayImage = () => { assetId="d2Q5bXvEgMg" mediaTitle="Prince Harry and Meghan's 'bombshell' plans explained – video" id="c2b8a51c-cb3d-41e7-bb79-1d9a091d0c28" - elementId="5ab531a2-f6ea-499d-b274-191114c8628c" expired={false} overrideImage="https://i.guim.co.uk/img/media/49565a29c6586fe6b748926e0be96c5e9c90473c/0_0_4981_2989/500.jpg?quality=85&auto=format&fit=max&s=17c70ec70002ea34886fd6c2605cd81e" duration={333} @@ -308,7 +302,6 @@ export const WithShowMainVideoFlagOff = () => { assetId="d2Q5bXvEgMg" mediaTitle="Prince Harry and Meghan's 'bombshell' plans explained – video" id="c2b8a51c-cb3d-41e7-bb79-1d9a091d0c28" - elementId="5ab531a2-f6ea-499d-b274-191114c8628c" expired={false} overrideImage="https://i.guim.co.uk/img/media/49565a29c6586fe6b748926e0be96c5e9c90473c/0_0_4981_2989/500.jpg?quality=85&auto=format&fit=max&s=17c70ec70002ea34886fd6c2605cd81e" duration={333} diff --git a/dotcom-rendering/src/lib/renderElement.tsx b/dotcom-rendering/src/lib/renderElement.tsx index e9c328d3d59..2b14b99afcc 100644 --- a/dotcom-rendering/src/lib/renderElement.tsx +++ b/dotcom-rendering/src/lib/renderElement.tsx @@ -743,7 +743,6 @@ export const renderElement = ({ hideCaption={hideCaption} isMainMedia={isMainMedia} id={element.id} - elementId={element.elementId} assetId={element.assetId} expired={element.expired} overrideImage={element.overrideImage}