diff --git a/packages/block-library/src/latest-posts/edit.js b/packages/block-library/src/latest-posts/edit.js index c7ca39a6cd09bb..07eb43f5bad171 100644 --- a/packages/block-library/src/latest-posts/edit.js +++ b/packages/block-library/src/latest-posts/edit.js @@ -18,7 +18,6 @@ import { Spinner, ToggleControl, ToolbarGroup, - FormTokenField, } from '@wordpress/components'; import apiFetch from '@wordpress/api-fetch'; import { addQueryArgs } from '@wordpress/url'; @@ -112,7 +111,13 @@ class LatestPostsEdit extends Component { } ), {} ); - + const categorySuggestions = categoriesList.reduce( + ( accumulator, category ) => ( { + ...accumulator, + [ category.name ]: category, + } ), + {} + ); const selectCategories = ( tokens ) => { // Categories that are already will be objects, while new additions will be strings (the name). // allCategories nomalizes the array so that they are all objects. @@ -243,21 +248,11 @@ class LatestPostsEdit extends Component { onNumberOfItemsChange={ ( value ) => setAttributes( { postsToShow: value } ) } + categorySuggestions={ categorySuggestions } + onCategoryChange={ selectCategories } + selectedCategories={ categories } /> - { categoriesList.length > 0 && ( - ( { - id: item.id, - value: item.name || item.value, - } ) ) - } - suggestions={ Object.keys( suggestions ) } - onChange={ selectCategories } - /> - ) } + { postLayout === 'grid' && ( ), onCategoryChange && ( - ( { + id: item.id, + value: item.name || item.value, + } ) ) + } + suggestions={ Object.keys( categorySuggestions ) } onChange={ onCategoryChange } - { ...MOBILE_CONTROL_PROPS } + maxSuggestions={ MAX_CATEGORIES_SUGGESTIONS } /> ), + onNumberOfItemsChange && (