From 28e2187ccc8421c854b2da230e37839d71d8c8fb Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 9 Jul 2024 12:19:04 +1000 Subject: [PATCH] Patterns: check for edited entity content property when exporting (#63227) * Because an item can either be an entity record fetched via getEntityRecord or getEditedEntityRecord check for content?.raw and content. The reason being getEditedEntityRecord calls getRawEntityRecord. getRawEntityRecord maps properties to their raw values. * Update type and add type check to keep the type linter happy Co-authored-by: ramonjd Co-authored-by: ntsekouras Co-authored-by: t-hamano Co-authored-by: youknowriad --- packages/editor/src/dataviews/actions/export-pattern.tsx | 5 ++++- packages/editor/src/dataviews/types.ts | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/dataviews/actions/export-pattern.tsx b/packages/editor/src/dataviews/actions/export-pattern.tsx index 57fb969d2ff29c..f4e5c91c7cabfa 100644 --- a/packages/editor/src/dataviews/actions/export-pattern.tsx +++ b/packages/editor/src/dataviews/actions/export-pattern.tsx @@ -22,7 +22,10 @@ function getJsonFromItem( item: Pattern ) { { __file: item.type, title: getItemTitle( item ), - content: item.content.raw, + content: + typeof item.content === 'string' + ? item.content + : item.content?.raw, syncStatus: item.wp_pattern_sync_status, }, null, diff --git a/packages/editor/src/dataviews/types.ts b/packages/editor/src/dataviews/types.ts index 02ce9964025789..9f57ecba6174aa 100644 --- a/packages/editor/src/dataviews/types.ts +++ b/packages/editor/src/dataviews/types.ts @@ -23,9 +23,7 @@ export interface TemplateOrTemplatePart extends BasePost { export interface Pattern extends BasePost { slug: string; title: { raw: string }; - content: { - raw: string; - }; + content: { raw: string } | string; wp_pattern_sync_status: string; }