Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Fix prop type warnings #2516

Merged
merged 28 commits into from
Nov 4, 2019
Merged

Fix prop type warnings #2516

merged 28 commits into from
Nov 4, 2019

Conversation

Bopchy
Copy link
Contributor

@Bopchy Bopchy commented Oct 28, 2019

Resolves #2497

Overall change: Add notes to psammead-media-player stories. Fix prop type warnings.

Code changes:

  • Add notes to psammead-media-player stories.
  • Fix prop type warnings.

  • I have assigned myself to this PR and the corresponding issues
  • Automated jest tests added (for new features) or updated (for existing features)
  • This PR requires manual testing

@Bopchy Bopchy self-assigned this Oct 28, 2019
@Bopchy Bopchy added the ws-home Tasks for the WS Home Team label Oct 29, 2019
@Bopchy Bopchy marked this pull request as ready for review October 29, 2019 10:20
@Bopchy
Copy link
Contributor Author

Bopchy commented Oct 29, 2019

This PR hasn't fixed - Warning: Failed prop type: The prop widthis marked as required inAmpImg, but its value is undefined. and Warning: Failed prop type: The propheightis marked as required inAmpImg, but its value is undefined.

Considered making height & width props optional in psammead-image (see #2523), however this will require AmpImg in psammead-image/src/index.amp.jsx to always be used within a container with specified height or width so that AMP can use the correct ratio for scaling the images

UPDATE - Closed #2523 and instead provided a default value for the height and width

@Bopchy Bopchy mentioned this pull request Oct 29, 2019
3 tasks
ghost
ghost previously requested changes Oct 29, 2019
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Screenshot 2019-10-29 at 19 08 45

Still seeing warnings while running `test:unit`

@ghost ghost dismissed their stale review October 29, 2019 16:15

I was running an out of date version of the branch.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Looks great.

@@ -41,9 +52,15 @@ AmpMediaPlayer.propTypes = {
placeholderSrc: string.isRequired,
placeholderSrcset: string,
title: string.isRequired,
alt: string,
Copy link

Choose a reason for hiding this comment

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

Should this be a required prop?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the width and height are required in the AmpImg component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the alt, width and height as optional props because the <AmpMediaPlayer /> seems to work without them - as it's getting the height and width from the StyledVideoContainer and StyledAudioContainer

Comment on lines 62 to 63
height: 640,
width: 450,
Copy link

Choose a reason for hiding this comment

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

Where are we getting this values from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Provided random default values as I was not sure where to get the specific height and width

Copy link

Choose a reason for hiding this comment

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

Let's have null as the default values. The same thing we have on psammead-image component

Copy link
Contributor Author

@Bopchy Bopchy Oct 30, 2019

Choose a reason for hiding this comment

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

When height and width are null, the error changes to Warning: Failed prop type: The prop height is marked as required in AmpImg, but its value is null.. React doesn't allow required props to be null. Found this issue on that - facebook/react#3163

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the width and height should be required since they are in the AmpImg component. Can you double-check this with @RayNjeri, please?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this. I think height and width should be required props here and not given arbitrary default values.

Given the width and height are only used before the AMP runtime fetches the image, can we compute values matching the aspect ratio based on portrait, see how we do https://github.com/bbc/psammead/blob/7b7d4eb86022e7edbfa37bd1a43c4d1633f6f967/packages/components/psammead-media-player/src/index.jsx#L11 and pass these in?

If it doesn't look straightforward I'm happy if you want to create a separate issue for the articles pod to implement that and we live with the warnings for now.

placeholderSrc,
placeholderSrcset,
title,
alt,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need a new alt prop, it can be hardcoded to "" on L41 for consistency with #2476

Comment on lines 62 to 63
height: 640,
width: 450,
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this. I think height and width should be required props here and not given arbitrary default values.

Given the width and height are only used before the AMP runtime fetches the image, can we compute values matching the aspect ratio based on portrait, see how we do https://github.com/bbc/psammead/blob/7b7d4eb86022e7edbfa37bd1a43c4d1633f6f967/packages/components/psammead-media-player/src/index.jsx#L11 and pass these in?

If it doesn't look straightforward I'm happy if you want to create a separate issue for the articles pod to implement that and we live with the warnings for now.

@Bopchy
Copy link
Contributor Author

Bopchy commented Nov 1, 2019

Added a height and width of 16 or 9 depending on if portrait == true or not

@Bopchy Bopchy requested a review from jamesdonoh November 4, 2019 10:22
Copy link
Contributor

@jamesdonoh jamesdonoh left a comment

Choose a reason for hiding this comment

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

Thanks for the changes.

@sareh sareh merged commit c7fe403 into latest Nov 4, 2019
@sareh sareh deleted the 2497-fix-prop-type-warnings branch November 4, 2019 12:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ws-articles Tasks for the WS Articles Team ws-home Tasks for the WS Home Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix psammead-media-player prop types warnings
8 participants