Skip to content

Commit

Permalink
Disable DropZone when the editor is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 6, 2017
1 parent 657c587 commit a16ef0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions editor/components/block-drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
* External Dependencies
*/
import { connect } from 'react-redux';
import { reduce, get, find } from 'lodash';
import { reduce, get, find, flow } from 'lodash';

/**
* WordPress dependencies
*/
import { DropZone } from '@wordpress/components';
import { DropZone, withContext } from '@wordpress/components';
import { getBlockTypes } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { insertBlocks } from '../../actions';

function BlockDropZone( { index, ...props } ) {
function BlockDropZone( { index, isLocked, ...props } ) {
if ( isLocked ) {
return null;
}

const dropFiles = ( files, position ) => {
const transformation = reduce( getBlockTypes(), ( ret, blockType ) => {
if ( ret ) {
Expand Down Expand Up @@ -45,7 +49,16 @@ function BlockDropZone( { index, ...props } ) {
);
}

export default connect(
undefined,
{ insertBlocks }
export default flow(
connect(
undefined,
{ insertBlocks }
),
withContext( 'editor' )( ( settings ) => {
const { templateLock } = settings;

return {
isLocked: !! templateLock,
};
} )
)( BlockDropZone );
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`DefaultBlockAppender no block present should match snapshot 1`] = `
<div
className="editor-default-block-appender"
>
<Connect(BlockDropZone) />
<WrappedComponent />
<input
className="editor-default-block-appender__content"
onClick={[Function]}
Expand Down

0 comments on commit a16ef0c

Please sign in to comment.