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

Remove checks for store existance in withSelect HOCs for media components #11903

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 3 additions & 6 deletions packages/editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const InsertFromURLPopover = ( { src, onChange, onSubmit, onClose } ) => (
</URLPopover>
);

class MediaPlaceholder extends Component {
export class MediaPlaceholder extends Component {
constructor() {
super( ...arguments );
this.state = {
Expand Down Expand Up @@ -258,13 +258,10 @@ class MediaPlaceholder extends Component {
}

const applyWithSelect = withSelect( ( select ) => {
let hasUploadPermissions = false;
if ( undefined !== select( 'core' ) ) {
hasUploadPermissions = select( 'core' ).hasUploadPermissions();
}
const { hasUploadPermissions } = select( 'core' );

return {
hasUploadPermissions: hasUploadPermissions,
hasUploadPermissions: hasUploadPermissions(),
};
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { mount } from 'enzyme';
/**
* Internal dependencies
*/
import MediaPlaceholder from '../';
import { MediaPlaceholder } from '../';

jest.mock( '../../media-upload/check', () => () => null );

describe( 'MediaPlaceholder', () => {
it( 'renders successfully when allowedTypes property is not specified', () => {
expect( () => mount(
<MediaPlaceholder />
<MediaPlaceholder hasUploadPermissions={ false } />
) ).not.toThrow();
} );
} );
7 changes: 2 additions & 5 deletions packages/editor/src/components/media-upload/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ export function MediaUploadCheck( { hasUploadPermissions, fallback = null, child
}

export default withSelect( ( select ) => {
let hasUploadPermissions = false;
if ( undefined !== select( 'core' ) ) {
hasUploadPermissions = select( 'core' ).hasUploadPermissions();
}
const { hasUploadPermissions } = select( 'core' );

return {
hasUploadPermissions: hasUploadPermissions,
hasUploadPermissions: hasUploadPermissions(),
};
} )( MediaUploadCheck );