Skip to content

Commit

Permalink
Code Quality: Rename patternBlock to patternPost (#57568)
Browse files Browse the repository at this point in the history
* Improve naming of pattern conversion funciton

* Rename patterBlock to patternPost
  • Loading branch information
talldan authored Jan 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a889ef0 commit 7946a0d
Showing 4 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -36,8 +36,8 @@ export const exportJSONaction = {
const json = {
__file: item.type,
title: item.title || item.name,
content: item.patternBlock.content.raw,
syncStatus: item.patternBlock.wp_pattern_sync_status,
content: item.patternPost.content.raw,
syncStatus: item.patternPost.wp_pattern_sync_status,
};
return downloadBlob(
`${ kebabCase( item.title || item.name ) }.json`,
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ export default function DuplicateMenuItem( {
<DuplicatePatternModal
onClose={ closeModal }
onSuccess={ onPatternSuccess }
pattern={ isThemePattern ? item : item.patternBlock }
pattern={ isThemePattern ? item : item.patternPost }
/>
) }
{ isModalOpen && isTemplatePart && (
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/page-patterns/grid-item.js
Original file line number Diff line number Diff line change
@@ -114,8 +114,8 @@ function GridItem( { categoryId, item, ...props } ) {
const json = {
__file: item.type,
title: item.title || item.name,
content: item.patternBlock.content.raw,
syncStatus: item.patternBlock.wp_pattern_sync_status,
content: item.patternPost.content.raw,
syncStatus: item.patternPost.wp_pattern_sync_status,
};

return downloadBlob(
39 changes: 24 additions & 15 deletions packages/edit-site/src/components/page-patterns/use-patterns.js
Original file line number Diff line number Diff line change
@@ -184,29 +184,38 @@ const selectPatterns = createSelector(
]
);

const patternBlockToPattern = ( patternBlock, categories ) => ( {
blocks: parse( patternBlock.content.raw, {
/**
* Converts a post of type `wp_block` to a 'pattern item' that more closely
* matches the structure of theme provided patterns.
*
* @param {Object} patternPost The `wp_block` record being normalized.
* @param {Map} categories A Map of user created categories.
*
* @return {Object} The normalized item.
*/
const convertPatternPostToItem = ( patternPost, categories ) => ( {
blocks: parse( patternPost.content.raw, {
__unstableSkipMigrationLogs: true,
} ),
...( patternBlock.wp_pattern_category.length > 0 && {
categories: patternBlock.wp_pattern_category.map(
...( patternPost.wp_pattern_category.length > 0 && {
categories: patternPost.wp_pattern_category.map(
( patternCategoryId ) =>
categories && categories.get( patternCategoryId )
? categories.get( patternCategoryId ).slug
: patternCategoryId
),
} ),
termLabels: patternBlock.wp_pattern_category.map( ( patternCategoryId ) =>
termLabels: patternPost.wp_pattern_category.map( ( patternCategoryId ) =>
categories?.get( patternCategoryId )
? categories.get( patternCategoryId ).label
: patternCategoryId
),
id: patternBlock.id,
name: patternBlock.slug,
syncStatus: patternBlock.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
title: patternBlock.title.raw,
type: PATTERN_TYPES.user,
patternBlock,
id: patternPost.id,
name: patternPost.slug,
syncStatus: patternPost.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
title: patternPost.title.raw,
type: patternPost.type,
patternPost,
} );

const selectUserPatterns = createSelector(
@@ -215,7 +224,7 @@ const selectUserPatterns = createSelector(
select( coreStore );

const query = { per_page: -1 };
const records = getEntityRecords(
const patternPosts = getEntityRecords(
'postType',
PATTERN_TYPES.user,
query
@@ -225,9 +234,9 @@ const selectUserPatterns = createSelector(
userPatternCategories.forEach( ( userCategory ) =>
categories.set( userCategory.id, userCategory )
);
let patterns = records
? records.map( ( record ) =>
patternBlockToPattern( record, categories )
let patterns = patternPosts
? patternPosts.map( ( record ) =>
convertPatternPostToItem( record, categories )
)
: EMPTY_PATTERN_LIST;

0 comments on commit 7946a0d

Please sign in to comment.