Skip to content

Commit

Permalink
Remove checks for store existance in withSelect HOCs for media compon…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
gziolo committed Nov 15, 2018
1 parent 0006987 commit 60f90f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
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 );

0 comments on commit 60f90f1

Please sign in to comment.