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

Add notice of disabled blocks to block inserter when no results are found #17338

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
findIndex,
flow,
groupBy,
size,
isEmpty,
map,
some,
Expand All @@ -27,6 +28,7 @@ import {
PanelBody,
withSpokenMessages,
Tip,
Button,
} from '@wordpress/components';
import {
getCategories,
Expand Down Expand Up @@ -253,7 +255,7 @@ export class InserterMenu extends Component {
}

render() {
const { instanceId, onSelect, rootClientId, showInserterHelpPanel } = this.props;
const { instanceId, onSelect, rootClientId, showInserterHelpPanel, numberOfHiddenBlocks, openModal } = this.props;
const {
childItems,
hoveredItem,
Expand Down Expand Up @@ -356,7 +358,32 @@ export class InserterMenu extends Component {
</PanelBody>
) }
{ isEmpty( suggestedItems ) && isEmpty( reusableItems ) && isEmpty( itemsPerCategory ) && (
<p className="editor-inserter__no-results block-editor-inserter__no-results">{ __( 'No blocks found.' ) }</p>
<p className="editor-inserter__no-results block-editor-inserter__no-results">
{ numberOfHiddenBlocks > 0 ? __( 'No active blocks found.' ) : __( 'No blocks found.' ) }
{ numberOfHiddenBlocks > 0 && (
<>
<br />
{
sprintf(
_n(
'%1$d block is disabled.',
'%1$d blocks are disabled.',
numberOfHiddenBlocks
),
numberOfHiddenBlocks
)
}
<br />
<Button
isDefault
className="block-editor-inserter__block-manager-button"
onClick={ () => openModal( 'edit-post/manage-blocks' ) }
>
{ __( 'Manage Blocks' ) }
</Button>
</>
) }
</p>
) }
</div>
</div>
Expand Down Expand Up @@ -429,6 +456,9 @@ export default compose(
const {
getChildBlockNames,
} = select( 'core/blocks' );
const {
getPreference,
} = select( 'core/edit-post' );
Copy link
Contributor

Choose a reason for hiding this comment

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

The inserter is a generic component from the block-editor package. It can't use a selector from the core/edit-post package. I wonder if the hiddenBlocks are available in the getSettings selector of the block-editor store instead.


let destinationRootClientId = rootClientId;
if ( ! destinationRootClientId && ! clientId && ! isAppender ) {
Expand All @@ -438,12 +468,15 @@ export default compose(
}
}
const destinationRootBlockName = getBlockName( destinationRootClientId );
const hiddenBlockTypes = getPreference( 'hiddenBlockTypes' );
const numberOfHiddenBlocks = size( hiddenBlockTypes );

return {
rootChildBlocks: getChildBlockNames( destinationRootBlockName ),
items: getInserterItems( destinationRootClientId ),
showInserterHelpPanel: getSettings().showInserterHelpPanel,
destinationRootClientId,
numberOfHiddenBlocks,
};
} ),
withDispatch( ( dispatch, ownProps, { select } ) => {
Expand All @@ -457,6 +490,10 @@ export default compose(
__experimentalFetchReusableBlocks: fetchReusableBlocks,
} = dispatch( 'core/editor' );

const {
openModal,
} = dispatch( 'core/edit-post' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, we're not allowed to use actions from the core/edit-post module in this package.


// To avoid duplication, getInsertionIndex is extracted and used in two event handlers
// This breaks the withDispatch not containing any logic rule.
// Since it's a function only called when the event handlers are called,
Expand Down Expand Up @@ -516,6 +553,7 @@ export default compose(

ownProps.onSelect();
},
openModal,
};
} ),
withSpokenMessages,
Expand Down
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ $block-inserter-search-height: 38px;
}

.block-editor-inserter__no-results {
font-style: italic;
padding: 24px;
text-align: center;
line-height: 1.75;
}

.block-editor-inserter__block-manager-button {
margin-top: 24px;
}

.block-editor-inserter__child-blocks {
Expand Down