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 fallback image for the course card images #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hinakhadim
Copy link
Contributor

When there is no image for course, then the screen shows alt text with broken image icon. This PR fixes it by adding an error image url. The Error image needs to be added in edx-platform with name no_course_image.png. This works perfectly with even tutor-indigo or any theme you want to set using tutor.

Before:

Screenshot 2024-04-22 at 6 07 58 PM

After:

If the image exists in theme:

Screenshot 2024-04-22 at 6 44 25 PM

If the image with name no_course_image.png won't exist, then it will show the alt text with broken image icon.

Impact:

  1. It will enhance user experience
  2. It'll maintain consistency of the course card layout
  3. Easy to implement with tutor-indigo theme or any customizable theme. Just need to add image with that name.

@hinakhadim hinakhadim requested a review from a team as a code owner April 22, 2024 13:54
const { bannerImgSrc } = reduxHooks.useCardCourseData(cardId);
const { homeUrl } = reduxHooks.useCardCourseRunData(cardId);
const { isVerified } = reduxHooks.useCardEnrollmentData(cardId);
const { disableCourseTitle } = useActionDisabledState(cardId);
const handleImageClicked = reduxHooks.useTrackCourseEvent(courseImageClicked, cardId, homeUrl);
const wrapperClassName = `pgn__card-wrapper-image-cap overflow-visible ${orientation}`;
const fallbackImageSrc = `${getConfig().LMS_BASE_URL}/theming/asset/images/no_course_image.png`;
Copy link
Contributor

@justinhynes justinhynes Apr 23, 2024

Choose a reason for hiding this comment

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

Is the no_course_image.png asset included by default as part of edx-platform? I was trying to check now and I can't find any assets in the master branch with this name, but maybe I am missing it.

Copy link
Contributor

@justinhynes justinhynes Apr 23, 2024

Choose a reason for hiding this comment

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

Ah, re-reading your description now, I believe you're saying that the Open edX operator must provide an asset with this name for this feature to work?

I'm a little nervous that this feature would be a bit hard to discover. I think it would be better for operators if there were some standard theme-agnostic placeholder images available in edx-platform that we're referencing.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is precedent for hosting a filler image in the MFE itself in case of absence:

I'm not saying I prefer this, architecturally speaking, but it would be a more immediate fix than adding placeholder images to edx-platform.

Also, I don't think hard-cording a reference to an image that needs to be provided as part of a comprehensive theme (something that's likely going away in the future), is the right thing to do here. If we're hard-coding something, it needs to be part of the vanilla edx-platform theme.

@justinhynes
Copy link
Contributor

Hi @mphilbrick211 -- Is this something that would need product eyes from Axim?

Copy link
Contributor

@justinhynes justinhynes left a comment

Choose a reason for hiding this comment

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

Blocking momentarily while it is determined if we need further feedback from Axim product folks.

@mphilbrick211
Copy link

Hi @mphilbrick211 -- Is this something that would need product eyes from Axim?

Thanks for flagging, @justinhynes - will check with Jenna now.

@jmakowski1123
Copy link

This is a good fix, thanks! Will this default image work for any instance? I noted you mentioned it works with the indigo theme, will it work for anyone using tutor?

This has product approval.

@hinakhadim
Copy link
Contributor Author

Yes, it works with indigo theme because in indigo theme, no_course_image.png is added. It won't work for anyone else using tutor without indigo theme because the image won't exist. Anyone who want to make this thing work has to add the image with no_course_image.png name in tutor theme package or edx-platform (directly).

@justinhynes
Copy link
Contributor

@hinakhadim What is the behavior if the asset doesn't exist in an alternate theme? Does it fallback to the current behavior (showing a broken image?) or something worse (hopefully not an error?)

@hinakhadim
Copy link
Contributor Author

@hinakhadim What is the behavior if the asset doesn't exist in an alternate theme? Does it fallback to the current behavior (showing a broken image?) or something worse (hopefully not an error?)

Yes, it fallback to the current behavior (showing a broken image). I've tested with image not existing then it didn't throw error and showed the current behavior.

const { bannerImgSrc } = reduxHooks.useCardCourseData(cardId);
const { homeUrl } = reduxHooks.useCardCourseRunData(cardId);
const { isVerified } = reduxHooks.useCardEnrollmentData(cardId);
const { disableCourseTitle } = useActionDisabledState(cardId);
const handleImageClicked = reduxHooks.useTrackCourseEvent(courseImageClicked, cardId, homeUrl);
const wrapperClassName = `pgn__card-wrapper-image-cap overflow-visible ${orientation}`;
const fallbackImageSrc = `${getConfig().LMS_BASE_URL}/theming/asset/images/no_course_image.png`;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is precedent for hosting a filler image in the MFE itself in case of absence:

I'm not saying I prefer this, architecturally speaking, but it would be a more immediate fix than adding placeholder images to edx-platform.

Also, I don't think hard-cording a reference to an image that needs to be provided as part of a comprehensive theme (something that's likely going away in the future), is the right thing to do here. If we're hard-coding something, it needs to be part of the vanilla edx-platform theme.

@hinakhadim
Copy link
Contributor Author

@arbrandes agree to your point.

import emptyCourseSVG from 'assets/empty-course.svg'; 

This image is looking weird to fix the broken image.
image (2)

If you can share other alternative, then i'll really appreciate it.

@arbrandes
Copy link
Contributor

If you can share other alternative, then i'll really appreciate it.

Apologies, I didn't mean to say we should use that image. We'll need to create a new one that works for this use case.

@hinakhadim
Copy link
Contributor Author

Sure. Can you please mention the team who will take care of this?

@arbrandes
Copy link
Contributor

Good question. I guess I was expecting you'd be able to submit the one in Indigo here, but of course, that is presuming a lot. :)

If that's not the case, then it's just something we'll have to add to the community backlog for somebody to pick up (including, possibly, Axim itself, but I can't promise we'll have the capacity soon).

@hinakhadim
Copy link
Contributor Author

Good question. I guess I was expecting you'd be able to submit the one in Indigo here, but of course, that is presuming a lot. :)

If that's not the case, then it's just something we'll have to add to the community backlog for somebody to pick up (including, possibly, Axim itself, but I can't promise we'll have the capacity soon).

We have included this image in indigo theme and add its link here in fallbackImgSrc variable. I know it makes us dependent on edx-platform but user can replace that image from theme and can use his own image (user is not restricted) .
Other option is that we can include that image here in this MFE and import it like import FallbackCourseImg from 'assets/no_course_img.png';. But, in this user must has to use that image (user is restricted). Otherwise, he has to change image by forking this repo. I am thinking from this perspective.

What are your thoughts on this regarding architecture considering future updates in LMS and MFE and user independence? (As studio/CMS also moved to MFE)

@arbrandes
Copy link
Contributor

Other option is that we can include that image here in this MFE and import it like import FallbackCourseImg from 'assets/no_course_img.png';. But, in this user must has to use that image (user is restricted). Otherwise, he has to change image by forking this repo. I am thinking from this perspective.

Good point. This means we should make the image overridable via brand-openedx, or, as mentioned earlier, we make the image available as part of the default Open edX theme in edx-platform, so that users don't have to have indigo installed for this to work.

I prefer the first option, as it decouples the UI from the backend a little bit more. But it would be best if the image were provided as an SVG, as opposed to a PNG, if at all possible.

@hinakhadim
Copy link
Contributor Author

Awesome. Including image in brand-openedx seems the best option because users can fork brand-openedx for image replacement instead of learner-dashboard mfe. I am able to include png image and that is working fine. If I import svg image, I am getting the following error:

Module not found: Can't resolve 'react' in '/openedx/brand-openedx/paragon/images'
brand-openedx/paragon/images/no_course_image.svg

@jsnwesson
Copy link
Contributor

@hinakhadim unless I'm misunderstanding how brand-openedx is being used here, I don't see an SVG version of no_course_image in the repo, so that might explain why it's failing to import? https://github.com/openedx/brand-openedx/tree/master/paragon/images

@hinakhadim
Copy link
Contributor Author

hinakhadim commented May 22, 2024

@hinakhadim unless I'm misunderstanding how brand-openedx is being used here, I don't see an SVG version of no_course_image in the repo, so that might explain why it's failing to import? https://github.com/openedx/brand-openedx/tree/master/paragon/images

@jsnwesson I added that image in cloned brand-openedx (one in png format and one in svg format). I then use that brand-openedx using module.config.js. I imported that image in learner-dashboard as:

import FallbackImageSrc from '@edx/brand/paragon/images/no_course_image.png';

// use it like

<img
        className="pgn__card-image-cap show"
        src={!hasImageError ? bannerImgSrc : FallbackImageSrc}
        alt={formatMessage(messages.bannerAlt)}
        onError={() => {
          if (!hasImageError) { setHasImageError(true); }
        }}
/>

The above works fine and loaded the image. But when I try to use .svg image, I got the error Module not found: Can't resolve 'react' in '/openedx/brand-openedx/paragon/images'. I tried importing svg image like this:

import FallbackImageSrc from '@edx/brand/paragon/images/no_course_image.svg';     OR
import * as FallbackImageSrc from '@edx/brand/paragon/images/no_course_image.svg';

@deborahgu deborahgu added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc.
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

7 participants