diff --git a/packages/edit-site/src/components/style-book/categories.ts b/packages/edit-site/src/components/style-book/categories.ts index e5ed8fb6d4d255..005d1e1a9e88ea 100644 --- a/packages/edit-site/src/components/style-book/categories.ts +++ b/packages/edit-site/src/components/style-book/categories.ts @@ -13,7 +13,7 @@ import type { * @param {BlockExample[]} examples An array of block examples. * @return {CategoryExamples|undefined} An object containing the category examples. */ -export function getCategoryExamples( +export function getExamplesByCategory( categoryDefinition: StyleBookCategory, examples: BlockExample[] ): CategoryExamples | undefined { @@ -24,7 +24,7 @@ export function getCategoryExamples( if ( categoryDefinition?.subcategories?.length ) { return categoryDefinition.subcategories.reduce( ( acc, subcategoryDefinition ) => { - const subcategoryExamples = getCategoryExamples( + const subcategoryExamples = getExamplesByCategory( subcategoryDefinition, examples ); diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js index c1227f9203340c..731fa39a8107e7 100644 --- a/packages/edit-site/src/components/style-book/index.js +++ b/packages/edit-site/src/components/style-book/index.js @@ -31,7 +31,7 @@ import { ENTER, SPACE } from '@wordpress/keycodes'; import { unlock } from '../../lock-unlock'; import EditorCanvasContainer from '../editor-canvas-container'; import { STYLE_BOOK_CATEGORIES, STYLE_BOOK_IFRAME_STYLES } from './constants'; -import { getCategoryExamples } from './categories'; +import { getExamplesByCategory } from './categories'; import { getExamples } from './examples'; const { @@ -150,7 +150,6 @@ function StyleBook( { ) : ( { - const categoryDefinition = STYLE_BOOK_CATEGORIES.find( - ( _category ) => _category.slug === category - ); - const filteredExamples = getCategoryExamples( - categoryDefinition, - examples - ); + const categoryDefinition = category + ? STYLE_BOOK_CATEGORIES.find( + ( _category ) => _category.slug === category + ) + : null; + + const filteredExamples = categoryDefinition + ? getExamplesByCategory( categoryDefinition, examples ) + : { examples }; return ( { - describe( 'getCategoryExamples', () => { + describe( 'getExamplesByCategory', () => { it( 'returns theme subcategories examples', () => { const themeCategory = STYLE_BOOK_CATEGORIES.find( ( category ) => category.slug === 'theme' ); - const themeCategoryExamples = getCategoryExamples( + const themeCategoryExamples = getExamplesByCategory( themeCategory, exampleThemeBlocks );