Skip to content

Commit

Permalink
fix bug with adding new categories in site editor
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Nov 6, 2023
1 parent 3815ce3 commit 4b3f7d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions packages/edit-site/src/components/page-patterns/use-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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
),
} ),
Expand All @@ -210,7 +210,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 };
Expand All @@ -219,11 +219,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 )
Expand All @@ -248,11 +250,10 @@ const selectUserPatterns = createSelector(
// to be in the category.
hasCategory: () => true,
} );

return {
patterns,
isResolving,
categories: userPatternCategories,
categories: patternCategories,
};
},
( select ) => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b3f7d5

Please sign in to comment.