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

Inserter: Show messaging when no blocks found #4040

Merged
merged 1 commit into from
Jan 2, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions editor/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
pick,
some,
sortBy,
isEmpty,
} from 'lodash';
import { connect } from 'react-redux';

Expand Down Expand Up @@ -255,6 +256,14 @@ export class InserterMenu extends Component {
}

renderCategories( visibleBlocksByCategory ) {
if ( isEmpty( visibleBlocksByCategory ) ) {
Copy link
Member

@jorgefilipecosta jorgefilipecosta Dec 15, 2017

Choose a reason for hiding this comment

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

If the only usage of this logic is when searching it may make sense to make this verification in line 358 where we call render categories for search as it makes things more explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think that makes sense. It's a bit complicated with trying to render the result of this.getVisibleBlocksByCategory inline, since we'd need to both test its non-emptiness and pass as the argument to renderCategories (or call twice, which is wasteful).

Lodash's _.cond could handle this pretty nicely, though maybe a bit less obvious to read?

cond( [
	[ isEmpty, () => (
		<span className="editor-inserter__no-results">
			{ __( 'No blocks found' ) }
		</span>
	) ],
	[ () => true, this.renderCategories ]
] )( this.getVisibleBlocksByCategory( this.getBlockTypes() ) );

Copy link
Member

Choose a reason for hiding this comment

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

This version with lodash cond is nice, but it is not obvious to read as you pointed out. The other possibility would save getVisibleBlocksByCategory in a const before the render but this way we may be computing it without need. I did not think about the complication because of being inline. It looks like our options have their downsides are not better than the current version we have, so I think we can ignore this detail and merge as it is right now.

return (
<span className="editor-inserter__no-results">
{ __( 'No blocks found' ) }
</span>
);
}

return getCategories().map(
( category ) => this.renderCategory( category, visibleBlocksByCategory[ category.slug ] )
);
Expand Down
7 changes: 7 additions & 0 deletions editor/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ input[type="search"].editor-inserter__search {
overflow: auto;
}

.editor-inserter__no-results {
display: block;
text-align: center;
font-style: italic;
padding: 8px;
}

.editor-inserter__tabs {
display: flex;
flex-direction: column;
Expand Down