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 13, 2023
1 parent 105356f commit 3a4d6c8
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 @@ -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
),
} ),
Expand All @@ -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 };
Expand All @@ -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 )
Expand All @@ -249,11 +251,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 3a4d6c8

Please sign in to comment.