From 3a4d6c8aa041b07277437454f0da00d26107395c Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 6 Nov 2023 14:41:38 +1300 Subject: [PATCH] fix bug with adding new categories in site editor --- .../components/page-patterns/use-patterns.js | 17 +++++++++-------- .../use-pattern-details.js | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/edit-site/src/components/page-patterns/use-patterns.js b/packages/edit-site/src/components/page-patterns/use-patterns.js index 9cb6c8b998c41..10862ead87db2 100644 --- a/packages/edit-site/src/components/page-patterns/use-patterns.js +++ b/packages/edit-site/src/components/page-patterns/use-patterns.js @@ -192,7 +192,7 @@ const patternBlockToPattern = ( patternBlock, categories ) => ( { categories: patternBlock.wp_pattern_category.map( ( patternCategoryId ) => categories && categories.get( patternCategoryId ) - ? categories.get( patternCategoryId ).slug + ? categories.get( patternCategoryId ).name : patternCategoryId ), } ), @@ -211,7 +211,7 @@ const patternBlockToPattern = ( patternBlock, categories ) => ( { const selectUserPatterns = createSelector( ( select, syncStatus, search = '' ) => { - const { getEntityRecords, getIsResolving, getUserPatternCategories } = + const { getEntityRecords, getIsResolving, getPatternCategories } = select( coreStore ); const query = { per_page: -1 }; @@ -220,11 +220,13 @@ const selectUserPatterns = createSelector( PATTERN_TYPES.user, query ); - const userPatternCategories = getUserPatternCategories(); + const patternCategories = getPatternCategories(); const categories = new Map(); - userPatternCategories.forEach( ( userCategory ) => - categories.set( userCategory.id, userCategory ) - ); + patternCategories.forEach( ( category ) => { + if ( category.id ) { + categories.set( category.id, category ); + } + } ); let patterns = records ? records.map( ( record ) => patternBlockToPattern( record, categories ) @@ -249,11 +251,10 @@ const selectUserPatterns = createSelector( // to be in the category. hasCategory: () => true, } ); - return { patterns, isResolving, - categories: userPatternCategories, + categories: patternCategories, }; }, ( select ) => [ diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js index b6a5a7948ea8a..efa121768d052 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js @@ -106,7 +106,7 @@ export default function usePatternDetails( postType, postId ) { if ( record.wp_pattern_category?.length > 0 ) { const patternCategoriesMap = new Map(); patternCategories.forEach( ( userCategory ) => - patternCategories.set( userCategory.id, userCategory ) + patternCategoriesMap.set( userCategory.id, userCategory ) ); const categories = record.wp_pattern_category