Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocks when useOnce is true #3988

Merged
merged 2 commits into from Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion editor/edit-post/modes/visual-editor/inserter.js
@@ -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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: some (Array#some) would be more appropriate than find (Array#find) only because we care that it exists (boolean), and have no intent to use the found value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I still commit in this branch to do that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I still commit in this branch to do that?

I'm not sure how forked branches work when a merge has already been done upstream†, but at the very least you'd still need to create a new pull request if you feel compelled to make the change.

† I'm kinda curious though if committing to your branch would allow for a new pull request 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a commit but nothing got happen here. I think I need to create a new pull request... xD

}

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
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