Skip to content

Commit

Permalink
Fix: Impossible to drag & drop blocks if the user has no permission t…
Browse files Browse the repository at this point in the history
…o upload files
  • Loading branch information
jorgefilipecosta committed May 29, 2019
1 parent bb24bbe commit 56fc5b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
38 changes: 18 additions & 20 deletions packages/block-editor/src/components/block-drop-zone/index.js
Expand Up @@ -19,11 +19,6 @@ import { Component } from '@wordpress/element';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';

/**
* Internal dependencies
*/
import MediaUploadCheck from '../media-upload/check';

const parseDropEvent = ( event ) => {
let result = {
srcRootClientId: null,
Expand Down Expand Up @@ -111,23 +106,20 @@ class BlockDropZone extends Component {
}

render() {
const { isLockedAll, index } = this.props;
const { hasUploadPermissions, isLockedAll, index } = this.props;
if ( isLockedAll ) {
return null;
}
const isAppender = index === undefined;

return (
<MediaUploadCheck>
<DropZone
className={ classnames( 'editor-block-drop-zone block-editor-block-drop-zone', {
'is-appender': isAppender,
} ) }
onFilesDrop={ this.onFilesDrop }
onHTMLDrop={ this.onHTMLDrop }
onDrop={ this.onDrop }
/>
</MediaUploadCheck>
<DropZone
className={ classnames( 'editor-block-drop-zone block-editor-block-drop-zone', {
'is-appender': isAppender,
} ) }
onHTMLDrop={ this.onHTMLDrop }
onDrop={ this.onDrop }
onFilesDrop={ hasUploadPermissions ? this.onFilesDrop : undefined }
/>
);
}
}
Expand Down Expand Up @@ -156,11 +148,17 @@ export default compose(
};
} ),
withSelect( ( select, { rootClientId } ) => {
const { getClientIdsOfDescendants, getTemplateLock, getBlockIndex } = select( 'core/block-editor' );
return {
isLockedAll: getTemplateLock( rootClientId ) === 'all',
const {
getBlockIndex,
getClientIdsOfDescendants,
getSettings,
getTemplateLock,
} = select( 'core/block-editor' );
return {
getBlockIndex,
getClientIdsOfDescendants,
hasUploadPermissions: !! getSettings().__experimentalMediaUpload,
isLockedAll: getTemplateLock( rootClientId ) === 'all',
};
} ),
withFilters( 'editor.BlockDropZone' )
Expand Down
8 changes: 6 additions & 2 deletions packages/components/src/drop-zone/index.js
Expand Up @@ -58,10 +58,14 @@ class DropZoneComponent extends Component {
}

render() {
const { className, label } = this.props;
const { className, label, onFilesDrop, onHTMLDrop, onDrop } = this.props;
const { isDraggingOverDocument, isDraggingOverElement, position, type } = this.state;
const classes = classnames( 'components-drop-zone', className, {
'is-active': isDraggingOverDocument || isDraggingOverElement,
'is-active': ( isDraggingOverDocument || isDraggingOverElement ) && (
( type === 'file' && onFilesDrop ) ||
( type === 'html' && onHTMLDrop ) ||
( type === 'default' && onDrop )
),
'is-dragging-over-document': isDraggingOverDocument,
'is-dragging-over-element': isDraggingOverElement,
'is-close-to-top': position && position.y === 'top',
Expand Down

0 comments on commit 56fc5b7

Please sign in to comment.