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

Add Youtube Embed Support to the ImageCard Component #3156

Merged
merged 2 commits into from
Jan 13, 2023

Conversation

patrickpatrickpatrick
Copy link
Contributor

@patrickpatrickpatrick patrickpatrickpatrick commented Dec 23, 2022

What

New variant of image card that supports embedding a Youtube video.

More Details

ImageCardHelper modified to accept a youtube_video_id and a set of new functions for generating a Youtube embed and a placeholder link using a thumbnail of the Youtube embed.

YoutubeLinkEnhancement can accept an override class if you want an alternative class to be appended to the youtube embed that isn't gem-c-govspeak__youtube-video.

Why

As part of the new design for No. 10 organisation page we need to be able to show promotional content with embeddable videos. Promotional content currently uses the image card component, so this PR adds support for embedding specifically Youtube videos into the image card component. Youtube embed functionality already exists in govspeak, therefore we are using that to generate the embed as it already has the functionality we need.

Screenshot

Screenshot 2022-12-28 at 15 52 40

@govuk-ci govuk-ci had a problem deploying to components-gem-pr-3156 December 23, 2022 16:24 Failure
@patrickpatrickpatrick patrickpatrickpatrick marked this pull request as draft December 23, 2022 16:24
@patrickpatrickpatrick patrickpatrickpatrick changed the title create new component for youtube card New Youtube Card Component Dec 23, 2022
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 December 23, 2022 16:25 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 December 28, 2022 15:46 Inactive
@chao-xian
Copy link
Contributor

@patrickpatrickpatrick lovely work. Small thing: I'd split this commit 1d83fb6 first into one where you refactor to split the partial, and then add in the youtube bits

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 December 30, 2022 12:20 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 December 30, 2022 14:15 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 December 30, 2022 15:55 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 December 30, 2022 16:19 Inactive
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Dec 30, 2022
This is to support the upcoming YouTube card component [1] that makes
use of YouTube thumbnails.

Unlike most of the host directives in this file this one specifies the
scheme to be https. My understanding is that it was an earlier mistake
of ours not to specify schemes, since we expect any of these resources
to be https. At a later point we can migrate the others.

[1]: alphagov/govuk_publishing_components#3156
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Dec 30, 2022
This is to support the upcoming YouTube card component [1] that makes
use of YouTube thumbnails.

Unlike most of the host directives in this file this one specifies the
scheme to be https. My understanding is that it was an earlier mistake
of ours not to specify schemes, since we expect any of these resources
to be https. At a later point we can migrate the others.

[1]: alphagov/govuk_publishing_components#3156
@andysellick
Copy link
Contributor

Obviously still draft so I won't do a full review but one concern I'd like to raise. At the moment the component auditing relies on the fact that component files use the same name for themselves (i.e. the image card component has an image card template, image card scss file, etc.) in order to report accurate information, but this change looks like it might break that convention. Would it be possible to have the filenames for the various parts of this match the component names in order to preserve how the auditing works? Happy to discuss if this isn't clear.

@patrickpatrickpatrick
Copy link
Contributor Author

Obviously still draft so I won't do a full review but one concern I'd like to raise. At the moment the component auditing relies on the fact that component files use the same name for themselves (i.e. the image card component has an image card template, image card scss file, etc.) in order to report accurate information, but this change looks like it might break that convention. Would it be possible to have the filenames for the various parts of this match the component names in order to preserve how the auditing works? Happy to discuss if this isn't clear.

I believe this should be the case in the way I've implemented it. Youtube card has a youtube_card.html.erb, yotube_card.js, youtube_card.scss; Image card has a image_card.html.erb, image_card.scss and media card has a media_card.html.erb and media_card.scss.

@andysellick
Copy link
Contributor

Thanks for the offline chat @patrickpatrickpatrick I think I understand this better now. As discussed, I've plugged this branch into an application to test how the auditing responds.

The auditing isn't detecting that the image card and youtube card components contain media card, and therefore doesn't correctly report problems to do with assets (e.g. not including the media card scss). It does allow for components that contain other components, but in this case the media card is considered a partial and not a top level component - it's importing /components/media_card/media_card (the pattern for a partial) and not /components/media_card (the pattern for a separate component). Unfortunately this distinction has to be made otherwise the auditing has no way of determining the difference between a component (where it should warn about missing assets) and a partial (where it shouldn't warn about missing assets) and of course we don't want to make the media card a separate component.

There's a similar problem with the 'suggested imports for this application' functionality (which appears on the front page of the component guide inside an application).

Not sure what to do about this - we don't want to make the media card its own component, but image card and youtube card rely on the assets from media card. Some options:

  • this could be solved both by an adjustment in this PR and a change to the auditing but I'd have to look into how it works, can't guarantee anything
  • could the image card and youtube card import the relevant Sass directly? I'm not sure, there might be a problem of duplication
  • totally crazy idea: what if there was just one component, but depending on what you pass it, it works either as the image card or the youtube card? You'd keep the helpers almost as they are, but the component would figure out which was being called then include the relevant partial (image card or youtube card). The Sass could be combined again and the whole problem could be avoided.

(I think this will be ultimately solved by the work being done where components include their own assets, but that's a little while off yet unfortunately)

@patrickpatrickpatrick
Copy link
Contributor Author

Thanks for the offline chat @patrickpatrickpatrick I think I understand this better now. As discussed, I've plugged this branch into an application to test how the auditing responds.

The auditing isn't detecting that the image card and youtube card components contain media card, and therefore doesn't correctly report problems to do with assets (e.g. not including the media card scss). It does allow for components that contain other components, but in this case the media card is considered a partial and not a top level component - it's importing /components/media_card/media_card (the pattern for a partial) and not /components/media_card (the pattern for a separate component). Unfortunately this distinction has to be made otherwise the auditing has no way of determining the difference between a component (where it should warn about missing assets) and a partial (where it shouldn't warn about missing assets) and of course we don't want to make the media card a separate component.

There's a similar problem with the 'suggested imports for this application' functionality (which appears on the front page of the component guide inside an application).

Not sure what to do about this - we don't want to make the media card its own component, but image card and youtube card rely on the assets from media card. Some options:

  • this could be solved both by an adjustment in this PR and a change to the auditing but I'd have to look into how it works, can't guarantee anything
  • could the image card and youtube card import the relevant Sass directly? I'm not sure, there might be a problem of duplication
  • totally crazy idea: what if there was just one component, but depending on what you pass it, it works either as the image card or the youtube card? You'd keep the helpers almost as they are, but the component would figure out which was being called then include the relevant partial (image card or youtube card). The Sass could be combined again and the whole problem could be avoided.

(I think this will be ultimately solved by the work being done where components include their own assets, but that's a little while off yet unfortunately)

I think of those options, the later option might be the best solution here. The reason I implemented this way was to reduce the amount of logic required by just being to call the specific card that we want to use directly, but this way I could I always put that logic in the helper. Will get to implementing it!

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 3, 2023 15:56 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 3, 2023 16:07 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 3, 2023 16:24 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 4, 2023 14:42 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 4, 2023 16:05 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 10, 2023 10:57 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 10, 2023 11:23 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 10, 2023 16:00 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 11, 2023 16:34 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 11, 2023 16:49 Inactive
Copy link
Contributor

@andysellick andysellick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this all looks good now, good job. One conflict to fix and might be worth squashing some of the commits together, but otherwise good 👍

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 12, 2023 09:42 Inactive
@patrickpatrickpatrick patrickpatrickpatrick changed the title New Youtube Card Component Add Youtube Embed Support to the ImageCard Component Jan 12, 2023
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 12, 2023 09:54 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 12, 2023 10:00 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3156 January 12, 2023 11:31 Inactive
As part of the redesign for the Number 10 organisation page we want to
be able to embed Youtube videos in the image card component.

This commit adds a youtube_video_id parameter to the ImageCardHelper as
well as several functions for generating a youtube link  using a thumbnail
of the given youtube video. This link will replaced by the embed if the
JS is able to run.

Now we have added a Youtube embed to the image card, we need to add some
tests to the image_card spec. This makes sure that we are adding the
data attribute required for the javascript to work and also that the
fallback link is correctly generated from the helper.

We don't test the embed itself because we are simply running the
YoutubeLinkEnhancement module without modifications. This already has
tests written for it.

In this commit, we have also have added the functionality
for turning a link to Youtube into an embed in the image card to
image_card.js. This function uses the existing YoutubeLinkEnhancement
module from Govspeak. There was only one minor modification needed to
be made to YoutubeLinkEnhancement for this to work, which was to allow
specifying a class to be appended to the Youtube embed.

Have also added the data-attribute required for the ImageCard js
module to be initialised in the image card partial if youtube_video_id
has been passed to it.
When a user has JS/cookies disabled, the Youtube embed in image card
will not be generated. Instead the user will see the link to the Youtube
video. This comprises of a thumbnail of the video as well as a text
description of the video. To make it more clear that the link is going
to Youtube, we have overlaid on top of the thumbnail a Youtube icon. To
make it clear that the user has focused the link to the Youtube video,
focus style has been added to the text of the link when the link is
focused.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants