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

Only check MediaPlaceholder allowedTypes array length if prop exists #11694

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 2 additions & 2 deletions packages/editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class MediaPlaceholder extends Component {
onHTMLDrop = noop,
multiple = false,
notices,
allowedTypes,
allowedTypes = [],
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that the prop is also used in onlyAllowsImages and onlyAllowsImages methods, should we add the default values there too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into that earlier, and I don't think changes are necessary in either of those cases. On onlyAllowsImages and onFilesUpload both, the existing logic should handle both [] and null/false/undefined/etc. (onlyAllowsImages has the checks in the media placeholder component, while onFilesUpload passes the prop value through to be checke within the mediaUpload method)

} = this.props;

const {
Expand All @@ -142,7 +142,7 @@ class MediaPlaceholder extends Component {
let instructions = labels.instructions || '';
let title = labels.title || '';
if ( ! instructions || ! title ) {
const isOneType = 1 === allowedTypes.length;
const isOneType = allowedTypes.length;
Copy link
Member

Choose a reason for hiding this comment

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

The check needs to stay :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️

const isAudio = isOneType && 'audio' === allowedTypes[ 0 ];
const isImage = isOneType && 'image' === allowedTypes[ 0 ];
const isVideo = isOneType && 'video' === allowedTypes[ 0 ];
Expand Down
17 changes: 17 additions & 0 deletions packages/editor/src/components/media-placeholder/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* External dependencies
*/
import { mount } from 'enzyme';

/**
* Internal dependencies
*/
import MediaPlaceholder from '../';

describe( 'MediaPlaceholder', () => {
it( 'renders successfully when allowedTypes property is not specified', () => {
expect( () => mount(
<MediaPlaceholder />
) ).not.toThrow();
} );
} );