From a975c2708ec4ebbf6dc2cfb1cfd2eec79dc9e756 Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 8 Jul 2024 17:17:54 +1000 Subject: [PATCH 1/2] 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. --- packages/editor/src/dataviews/actions/export-pattern.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/dataviews/actions/export-pattern.tsx b/packages/editor/src/dataviews/actions/export-pattern.tsx index 917b284ade1a2c..d2ff169fd0debe 100644 --- a/packages/editor/src/dataviews/actions/export-pattern.tsx +++ b/packages/editor/src/dataviews/actions/export-pattern.tsx @@ -22,7 +22,7 @@ function getJsonFromItem( item: Pattern ) { { __file: item.type, title: getItemTitle( item ), - content: item.content.raw, + content: item.content?.raw || item.content, syncStatus: item.wp_pattern_sync_status, }, null, From d5cb57e346c7b7c7f1101867cc323726947dd0eb Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 9 Jul 2024 11:19:18 +1000 Subject: [PATCH 2/2] Update type and add type check to keep the type linter happy --- 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 d2ff169fd0debe..ac58d7c2c22060 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 || item.content, + 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; }