Skip to content

Commit

Permalink
Apply @gziolo recommandations and fix a failing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
imath committed Nov 13, 2018
1 parent f22e32f commit 80ffbf6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
7 changes: 6 additions & 1 deletion packages/editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,13 @@ class MediaPlaceholder extends Component {
}

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

return {
hasUploadPermissions: select( 'core' ).hasUploadPermissions(),
hasUploadPermissions: hasUploadPermissions,
};
} );

Expand Down
12 changes: 8 additions & 4 deletions packages/editor/src/components/media-upload/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
*/
import { withSelect } from '@wordpress/data';

export function MediaUploadCheck( { hasUploadPermissions, fallback, children } ) {
const optionalFallback = fallback || null;
return hasUploadPermissions ? children : optionalFallback;
export function MediaUploadCheck( { hasUploadPermissions, fallback = null, children } ) {
return hasUploadPermissions ? children : fallback;
}

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

return {
hasUploadPermissions: select( 'core' ).hasUploadPermissions(),
hasUploadPermissions: hasUploadPermissions,
};
} )( MediaUploadCheck );
56 changes: 27 additions & 29 deletions packages/format-library/src/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { Path, SVG } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Fragment, Component } from '@wordpress/element';
import { Component } from '@wordpress/element';
import { insertObject } from '@wordpress/rich-text';
import { MediaUpload, RichTextInserterItem, MediaUploadCheck } from '@wordpress/editor';

Expand Down Expand Up @@ -47,34 +47,32 @@ export const image = {

return (
<MediaUploadCheck>
<Fragment>
<RichTextInserterItem
name={ name }
icon={ <SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><Path d="M4 16h10c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v9c0 1.1.9 2 2 2zM4 5h10v9H4V5zm14 9v2h4v-2h-4zM2 20h20v-2H2v2zm6.4-8.8L7 9.4 5 12h8l-2.6-3.4-2 2.6z" /></SVG> }
title={ __( 'Inline Image' ) }
onClick={ this.openModal }
/>
{ this.state.modal && <MediaUpload
allowedTypes={ ALLOWED_MEDIA_TYPES }
onSelect={ ( { id, url, alt, width } ) => {
this.closeModal();
onChange( insertObject( value, {
type: name,
attributes: {
className: `wp-image-${ id }`,
style: `width: ${ Math.min( width, 150 ) }px;`,
url,
alt,
},
} ) );
} }
onClose={ this.closeModal }
render={ ( { open } ) => {
open();
return null;
} }
/> }
</Fragment>
<RichTextInserterItem
name={ name }
icon={ <SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><Path d="M4 16h10c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v9c0 1.1.9 2 2 2zM4 5h10v9H4V5zm14 9v2h4v-2h-4zM2 20h20v-2H2v2zm6.4-8.8L7 9.4 5 12h8l-2.6-3.4-2 2.6z" /></SVG> }
title={ __( 'Inline Image' ) }
onClick={ this.openModal }
/>
{ this.state.modal && <MediaUpload
allowedTypes={ ALLOWED_MEDIA_TYPES }
onSelect={ ( { id, url, alt, width } ) => {
this.closeModal();
onChange( insertObject( value, {
type: name,
attributes: {
className: `wp-image-${ id }`,
style: `width: ${ Math.min( width, 150 ) }px;`,
url,
alt,
},
} ) );
} }
onClose={ this.closeModal }
render={ ( { open } ) => {
open();
return null;
} }
/> }
</MediaUploadCheck>
);
}
Expand Down

0 comments on commit 80ffbf6

Please sign in to comment.