Skip to content

Commit

Permalink
Merge pull request #3988 from Rahmon/fix/3968
Browse files Browse the repository at this point in the history
Fix blocks when useOnce is true
  • Loading branch information
aduth authored Dec 15, 2017
2 parents 71a218f + 8a511f5 commit 5d81a0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion editor/edit-post/modes/visual-editor/inserter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { find } from 'lodash';
import { connect } from 'react-redux';
import classnames from 'classnames';

Expand All @@ -17,7 +18,7 @@ import { createBlock, BlockIcon } from '@wordpress/blocks';
*/
import { Inserter } from '../../../components';
import { insertBlock } from '../../../actions';
import { getMostFrequentlyUsedBlocks, getBlockCount } from '../../../selectors';
import { getMostFrequentlyUsedBlocks, getBlockCount, getBlocks } from '../../../selectors';

export class VisualEditorInserter extends Component {
constructor() {
Expand All @@ -40,6 +41,10 @@ export class VisualEditorInserter extends Component {
onInsertBlock( createBlock( name ) );
}

isDisabledBlock( block ) {
return block.useOnce && find( this.props.blocks, ( { name } ) => block.name === name );
}

render() {
const { blockCount, isLocked } = this.props;
const { isShowingControls } = this.state;
Expand Down Expand Up @@ -67,6 +72,7 @@ export class VisualEditorInserter extends Component {
className="editor-inserter__block"
onClick={ () => this.insertBlock( block.name ) }
label={ sprintf( __( 'Insert %s' ), block.title ) }
disabled={ this.isDisabledBlock( block ) }
icon={ (
<span className="editor-visual-editor__inserter-block-icon">
<BlockIcon icon={ block.icon } />
Expand All @@ -87,6 +93,7 @@ export default compose(
return {
mostFrequentlyUsedBlocks: getMostFrequentlyUsedBlocks( state ),
blockCount: getBlockCount( state ),
blocks: getBlocks( state ),
};
},
{ onInsertBlock: insertBlock },
Expand Down
4 changes: 4 additions & 0 deletions editor/edit-post/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
&:hover > .editor-inserter__block,
&.is-showing-controls > .editor-inserter__block {
opacity: 1;

&:disabled {
@include button-style__disabled;
}
}
}

Expand Down

0 comments on commit 5d81a0a

Please sign in to comment.