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
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8c99439
Add notes to psammead-media-player stories.
Oct 28, 2019
d8153db
Update package.json, package-lock.json, CHANGELOG.md.
Oct 28, 2019
8f5ff8d
Add alt, height & width as props.
Oct 28, 2019
46fdcdb
Make alt a prop.
Oct 28, 2019
b4528b5
Update snapshots.
Oct 28, 2019
f198da6
Update PR number & link.
Oct 28, 2019
3a7308c
Remove extra white spaces.
Oct 28, 2019
221cc9c
Merge branch 'latest' into 2497-fix-prop-type-warnings
EinsteinNjoroge Oct 29, 2019
7a42260
Add default height and width values.
Oct 29, 2019
d35b560
Update snapshot.
Oct 29, 2019
04fc8c5
Merge branch '2497-fix-prop-type-warnings' of github.com:bbc/psammead…
Oct 29, 2019
def1453
Merge branch 'latest' into 2497-fix-prop-type-warnings
Oct 29, 2019
3d20b7f
Merge branch 'latest' into 2497-fix-prop-type-warnings
Oct 30, 2019
8ee2d21
Merge branch 'latest' into 2497-fix-prop-type-warnings
DenisHdz Oct 30, 2019
21fa855
Merge branch 'latest' of github.com:bbc/psammead into 2497-fix-prop-t…
Oct 31, 2019
9d76a32
Merge branch '2497-fix-prop-type-warnings' of github.com:bbc/psammead…
Oct 31, 2019
0f4378a
Merge branch 'latest' into 2497-fix-prop-type-warnings
Oct 31, 2019
2a8f24b
Update version number.
Oct 31, 2019
0f89154
Merge branch '2497-fix-prop-type-warnings' of github.com:bbc/psammead…
Oct 31, 2019
7150525
Make height & width required props. Remove alt.
Nov 1, 2019
8c796db
Combine canoncial and amp stories.
Nov 1, 2019
f583767
Merge branch 'latest' of github.com:bbc/psammead into 2497-fix-prop-t…
Nov 1, 2019
62d8c6b
Add heigth and width.
Nov 1, 2019
f57e957
Update snapshots.
Nov 1, 2019
ecc3833
Add height and width to tests.
Nov 1, 2019
78d31d9
Update snapshot.
Nov 1, 2019
09b15f3
Update README.
Nov 1, 2019
444c08e
Merge branch 'latest' of github.com:bbc/psammead into 2497-fix-prop-t…
Nov 1, 2019
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
33 changes: 17 additions & 16 deletions packages/components/psammead-media-player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# Psammead Media Player Changelog

<!-- prettier-ignore -->
| Version | Description |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Version | Description |
| ------- | ----------- |
| 2.1.2 | [PR#2516](https://github.com/bbc/psammead/pull/2516) Add notes to stories. Add default `alt`, `height` and `width` values |
| 2.1.1 | [PR#2532](https://github.com/bbc/psammead/pull/2532) Rename "Media Player" story to "MediaPlayer"
| 2.1.0 | [PR#2424](https://github.com/bbc/psammead/pull/2424) Add srcset to placeholder image
| 2.0.2 | [PR#2486](https://github.com/bbc/psammead/pull/2486) Talos - Bump Dependencies - @bbc/psammead-image |
| 2.0.1 | [PR#2317](https://github.com/bbc/psammead/pull/2317) Add `psammead-play-button` to Media Player placeholder |
| 2.0.0 | [PR#2434](https://github.com/bbc/psammead/pull/2434) Add `title` attribute to AV media player |
| 1.1.1-alpha.8 | [PR#2410](https://github.com/bbc/psammead/pull/2410) Update AMP story audio skin AMP placeholder image |
| 1.1.1-alpha.7 | [PR#2312](https://github.com/bbc/psammead/pull/2312) Add lang to the embed src URL in storybook examples
| 1.1.1-alpha.6 | [PR#2297](https://github.com/bbc/psammead/pull/2297) define placeholderSrc |
| 1.1.1-alpha.5 | [PR#2280](https://github.com/bbc/psammead/pull/2280) Remove `scrolling="no"` for a11y best practice |
| 1.1.1-alpha.8 | [PR#2410](https://github.com/bbc/psammead/pull/2410) Update AMP story audio skin AMP placeholder image |
| 1.1.1-alpha.7 | [PR#2312](https://github.com/bbc/psammead/pull/2312) Add lang to the embed src URL in storybook examples |
| 1.1.1-alpha.6 | [PR#2297](https://github.com/bbc/psammead/pull/2297) define placeholderSrc |
| 1.1.1-alpha.5 | [PR#2280](https://github.com/bbc/psammead/pull/2280) Remove `scrolling="no"` for a11y best practice |
| 1.1.1-alpha.4 | [PR#2281](https://github.com/bbc/psammead/pull/2281) Change allowfullscreen attribute value to valid value `allowfullscreen` |
| 1.1.1-alpha.3 | [PR#2284](https://github.com/bbc/psammead/pull/2284) Add an AV audio skin story |
| 1.1.1-alpha.2 | [PR#2247](https://github.com/bbc/psammead/pull/2247) Update article embed URLs in MediaPLayer stories |
| 1.1.1-alpha.1 | [PR#2191](https://github.com/bbc/psammead/pull/2191) Talos - Bump Dependencies |
| 1.1.0-alpha.1 | [PR#2144](https://github.com/bbc/psammead/pull/2144) Add `skin` prop |
| 1.0.1-alpha.4 | [PR#1960](https://github.com/bbc/psammead/pull/1960) Change <React.Fragment> to <> |
| 1.0.1-alpha.3 | [PR#1961](https://github.com/bbc/psammead/pull/1961) Talos - Bump Dependencies |
| 1.0.1-alpha.2 | [PR#1942](https://github.com/bbc/psammead/pull/1942) Talos - Bump React to 16.9.0 |
| 1.0.1-alpha.1 | [PR#1920](https://github.com/bbc/psammead/pull/1920) Use @testing-library-react |
| 1.0.1-alpha.0 | [PR#1842](https://github.com/bbc/psammead/pull/1842) Fix fullscreen for Firefox, Internet Explorer and Safari |
| 1.0.0-alpha.0 | [PR#1831](https://github.com/bbc/psammead/pull/1831) Create `psammead-media-player` component |
| 1.1.1-alpha.3 | [PR#2284](https://github.com/bbc/psammead/pull/2284) Add an AV audio skin story |
| 1.1.1-alpha.2 | [PR#2247](https://github.com/bbc/psammead/pull/2247) Update article embed URLs in MediaPLayer stories |
| 1.1.1-alpha.1 | [PR#2191](https://github.com/bbc/psammead/pull/2191) Talos - Bump Dependencies |
| 1.1.0-alpha.1 | [PR#2144](https://github.com/bbc/psammead/pull/2144) Add `skin` prop |
| 1.0.1-alpha.4 | [PR#1960](https://github.com/bbc/psammead/pull/1960) Change <React.Fragment> to <> |
| 1.0.1-alpha.3 | [PR#1961](https://github.com/bbc/psammead/pull/1961) Talos - Bump Dependencies |
| 1.0.1-alpha.2 | [PR#1942](https://github.com/bbc/psammead/pull/1942) Talos - Bump React to 16.9.0 |
| 1.0.1-alpha.1 | [PR#1920](https://github.com/bbc/psammead/pull/1920) Use @testing-library-react |
| 1.0.1-alpha.0 | [PR#1842](https://github.com/bbc/psammead/pull/1842) Fix fullscreen for Firefox, Internet Explorer and Safari |
| 1.0.0-alpha.0 | [PR#1831](https://github.com/bbc/psammead/pull/1831) Create `psammead-media-player` component |

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/psammead-media-player/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/psammead-media-player",
"version": "2.1.1",
"version": "2.1.2",
"description": "Provides a media player with optional placeholder",
"main": "dist/index.js",
"module": "esm/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ exports[`Media Player: Amp should render an amp-iframe with an amp-img nested in
title="Media player"
>
<amp-img
alt="Image alt"
attribution=""
height="640"
layout="fill"
placeholder="true"
src="https://foo.bar/placeholder.png"
srcset="https://bbc.com/300/cat.jpg 300w, https://bbc.com/450/cat.jpg 450w, https://bbc.com/600/cat.jpg 600w"
width="450"
/>
</amp-iframe>
</div>
Expand Down
21 changes: 19 additions & 2 deletions packages/components/psammead-media-player/src/Amp/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { string } from 'prop-types';
import { string, number } from 'prop-types';
import Helmet from 'react-helmet';
import { AmpImg } from '@bbc/psammead-image';

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

const AmpMediaPlayer = ({ src, placeholderSrc, placeholderSrcset, title }) => {
const AmpMediaPlayer = ({
src,
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

height,
width,
}) => {
return (
<>
<AmpHead />
Expand All @@ -30,6 +38,9 @@ const AmpMediaPlayer = ({ src, placeholderSrc, placeholderSrcset, title }) => {
src={placeholderSrc}
srcset={placeholderSrcset}
placeholder
alt={alt}
height={height}
width={width}
/>
</amp-iframe>
</>
Expand All @@ -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

height: number,
width: number,
};
AmpMediaPlayer.defaultProps = {
placeholderSrcset: null,
alt: 'Image alt',
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.

};

export default AmpMediaPlayer;
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ exports[`Media Player: AMP Entry renders a landscape container with an amp-ifram
title="Media player"
>
<amp-img
alt="Image alt"
attribution=""
height="640"
layout="fill"
placeholder="true"
src="http://foo.bar/placeholder.png"
width="450"
/>
</amp-iframe>
</div>
Expand Down Expand Up @@ -70,10 +73,13 @@ exports[`Media Player: AMP Entry renders a portrait container with amp-iframe an
title="Media player"
>
<amp-img
alt="Image alt"
attribution=""
height="640"
layout="fill"
placeholder="true"
src="http://foo.bar/placeholder.png"
width="450"
/>
</amp-iframe>
</div>
Expand Down Expand Up @@ -111,10 +117,13 @@ exports[`Media Player: AMP Entry renders the audio skin 1`] = `
title="Audio player"
>
<amp-img
alt="Image alt"
attribution=""
height="640"
layout="fill"
placeholder="true"
src="http://foo.bar/placeholder.png"
width="450"
/>
</amp-iframe>
</div>
Expand Down
111 changes: 70 additions & 41 deletions packages/components/psammead-media-player/src/index.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,90 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { CanonicalMediaPlayer, AmpMediaPlayer } from '.';
import { ampDecorator } from '../../../../.storybook/config';
import notes from '../README.md';

const withDuration = {
duration: '2:30',
durationSpoken: '2 minutes 30 seconds',
datetime: 'PT2M30S',
};

storiesOf('Components|MediaPlayer', module).add('Default', () => (
<CanonicalMediaPlayer
src="https://www.test.bbc.co.uk/ws/av-embeds/articles/c3wmq4d1y3wo/p01k6msp/en"
placeholderSrc="https://ichef.bbci.co.uk/news/640/cpsdevpb/4eb7/test/ba7482d0-cca8-11e8-b0bf-f33155223fc4.jpg"
service="news"
mediaInfo={{ title: 'Dog chases cat.', ...withDuration }}
/>
));

storiesOf('Components|MediaPlayer', module).add('Audio', () => (
<CanonicalMediaPlayer
src="https://www.test.bbc.co.uk/ws/av-embeds/articles/c3wmq4d1y3wo/p01k6msp/en"
placeholderSrc="https://ichef.bbci.co.uk/news/640/cpsdevpb/4eb7/test/ba7482d0-cca8-11e8-b0bf-f33155223fc4.jpg"
service="news"
mediaInfo={{ type: 'audio', title: 'Dog barks at cat.', ...withDuration }}
title="Video player"
/>
));
storiesOf('Components|Media Player', module).add(
'Default',
() => (
<CanonicalMediaPlayer
src="https://www.test.bbc.co.uk/ws/av-embeds/articles/c3wmq4d1y3wo/p01k6msp/en"
placeholderSrc="https://ichef.bbci.co.uk/news/640/cpsdevpb/4eb7/test/ba7482d0-cca8-11e8-b0bf-f33155223fc4.jpg"
service="news"
mediaInfo={{ title: 'Dog chases cat.', ...withDuration }}
title="Default Video player"
/>
),
{ notes, knobs: { escapeHTML: false } },
);

storiesOf('Components|MediaPlayer', module)
.addDecorator(ampDecorator)
.add('AMP', () => (
<AmpMediaPlayer
isAmp
src="https://www.test.bbc.co.uk/ws/av-embeds/articles/c3wmq4d1y3wo/p01k6msp/en/amp"
storiesOf('Components|Media Player', module).add(
'Audio',
() => (
<CanonicalMediaPlayer
src="https://www.test.bbc.co.uk/ws/av-embeds/articles/c3wmq4d1y3wo/p01k6msp/en"
placeholderSrc="https://ichef.bbci.co.uk/news/640/cpsdevpb/4eb7/test/ba7482d0-cca8-11e8-b0bf-f33155223fc4.jpg"
service="news"
mediaInfo={{ type: 'audio', title: 'Dog barks at cat.', ...withDuration }}
title="Video player"
/>
));

storiesOf('Components|MediaPlayer', module).add('Audio Skin', () => (
<CanonicalMediaPlayer
src="https://www.bbc.com/ws/av-embeds/media/bbc_korean_radio/liveradio/ko"
showPlaceholder={false}
skin="audio"
service="news"
title="Audio player"
/>
));
),
{ notes, knobs: { escapeHTML: false } },
);

storiesOf('Components|MediaPlayer', module)
EinsteinNjoroge marked this conversation as resolved.
Show resolved Hide resolved
.addDecorator(ampDecorator)
.add('Audio Skin AMP', () => (
<AmpMediaPlayer
isAmp
src="https://www.bbc.com/ws/av-embeds/media/bbc_korean_radio/liveradio/ko/amp"
placeholderSrc="https://news.files.bbci.co.uk/include/articles/public/images/amp_audio_placeholder.png"
.add(
'AMP',
() => (
<AmpMediaPlayer
isAmp
src="https://www.test.bbc.co.uk/ws/av-embeds/articles/c3wmq4d1y3wo/p01k6msp/en/amp"
placeholderSrc="https://ichef.bbci.co.uk/news/640/cpsdevpb/4eb7/test/ba7482d0-cca8-11e8-b0bf-f33155223fc4.jpg"
service="news"
mediaInfo={{
type: 'audio',
title: 'Dog barks at cat.',
...withDuration,
}}
title="Video player"
/>
),
{ notes, knobs: { escapeHTML: false } },
);

storiesOf('Components|Media Player', module).add(
'Audio Skin',
() => (
<CanonicalMediaPlayer
src="https://www.bbc.com/ws/av-embeds/media/bbc_korean_radio/liveradio/ko"
showPlaceholder={false}
skin="audio"
service="news"
mediaInfo={{ type: 'audio', title: 'Live show intro.' }}
title="Audio player"
/>
));
),
{ notes, knobs: { escapeHTML: false } },
);

storiesOf('Components|Media Player', module)
EinsteinNjoroge marked this conversation as resolved.
Show resolved Hide resolved
.addDecorator(ampDecorator)
.add(
'Audio Skin AMP',
() => (
<AmpMediaPlayer
isAmp
src="https://www.bbc.com/ws/av-embeds/media/bbc_korean_radio/liveradio/ko/amp"
placeholderSrc="https://news.files.bbci.co.uk/include/articles/public/images/amp_audio_placeholder.png"
skin="audio"
title="Audio player"
/>
),
{ notes, knobs: { escapeHTML: false } },
);