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

Blocks: Fix searching of blocks when description is non-string #44233

Merged
merged 1 commit into from Sep 19, 2022
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
3 changes: 2 additions & 1 deletion packages/blocks/src/store/selectors.js
Expand Up @@ -712,7 +712,8 @@ export function isMatchingSearchTerm( state, nameOrType, searchTerm ) {
isSearchMatch( blockType.title ) ||
some( blockType.keywords, isSearchMatch ) ||
isSearchMatch( blockType.category ) ||
isSearchMatch( blockType.description )
( typeof blockType.description === 'string' &&
isSearchMatch( blockType.description ) )
);
}

Expand Down
13 changes: 12 additions & 1 deletion packages/blocks/src/store/test/selectors.js
Expand Up @@ -605,6 +605,10 @@ describe( 'selectors', () => {
...blockTypeBase,
category,
};
const blockTypeWithNonStringDescription = {
...blockTypeBase,
description: <div>writing flow</div>,
};

const state = {
blockTypes: {
Expand All @@ -617,6 +621,10 @@ describe( 'selectors', () => {
[ 'block type', blockType ],
[ 'block type without category', blockTypeWithoutCategory ],
[ 'block type without description', blockTypeWithoutDescription ],
[
'block type with non-string description',
blockTypeWithNonStringDescription,
],
] )( 'by %s', ( label, nameOrType ) => {
it( 'should return false if not match', () => {
const result = isMatchingSearchTerm(
Expand Down Expand Up @@ -690,7 +698,10 @@ describe( 'selectors', () => {
} );
}

if ( nameOrType.description ) {
if (
nameOrType.description &&
typeof nameOrType.description === 'string'
) {
it( 'should return true if match using the description', () => {
const result = isMatchingSearchTerm(
state,
Expand Down