Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: JavaScript error when pattern category is unregistered #67063

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function mapUserPattern(
id: userPattern.id,
type: INSERTER_PATTERN_TYPES.user,
title: userPattern.title.raw,
categories: userPattern.wp_pattern_category.map( ( catId ) => {
categories: userPattern.wp_pattern_category?.map( ( catId ) => {
const category = __experimentalUserPatternCategories.find(
( { id } ) => id === catId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const selectPatterns = createSelector(
categoryId,
hasCategory: ( item, currentCategory ) => {
if ( item.type === PATTERN_TYPES.user ) {
return item.wp_pattern_category.some(
return item.wp_pattern_category?.some(
carolinan marked this conversation as resolved.
Show resolved Hide resolved
( catId ) =>
userPatternCategories.find(
( cat ) => cat.id === catId
Expand All @@ -173,7 +173,7 @@ const selectPatterns = createSelector(
return (
userPatternCategories?.length &&
( ! item.wp_pattern_category?.length ||
! item.wp_pattern_category.some( ( catId ) =>
! item.wp_pattern_category?.some( ( catId ) =>
userPatternCategories.find(
( cat ) => cat.id === catId
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function usePatternCategories() {
// If the pattern has no categories, add it to uncategorized.
if (
! pattern.wp_pattern_category?.length ||
! pattern.wp_pattern_category.some( ( catId ) =>
! pattern.wp_pattern_category?.some( ( catId ) =>
userPatternCategories.find( ( cat ) => cat.id === catId )
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getTermLabels( pattern, categories ) {

return categories.user
?.filter( ( category ) =>
pattern.wp_pattern_category.includes( category.id )
pattern.wp_pattern_category?.includes( category.id )
)
.map( ( category ) => category.label );
}
Expand Down
Loading