From a4afd42e3910c28b308d2046874fabd5d1896dd1 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 14 May 2024 17:53:51 +0100 Subject: [PATCH] false value checks --- .../editor/src/components/post-actions/actions.js | 11 +++++++++-- .../components/post-actions/export-pattern-action.js | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/post-actions/actions.js b/packages/editor/src/components/post-actions/actions.js index 4887a3031a7e07..8ab7435c475a82 100644 --- a/packages/editor/src/components/post-actions/actions.js +++ b/packages/editor/src/components/post-actions/actions.js @@ -687,7 +687,10 @@ const duplicatePostAction = { }; const isTemplatePartRevertable = ( item ) => { - const hasThemeFile = item.templatePart.has_theme_file; + if ( ! item ) { + return false; + } + const hasThemeFile = item.templatePart?.has_theme_file; return canDeleteOrReset( item ) && hasThemeFile; }; @@ -1020,8 +1023,12 @@ export const deletePatternAction = { id: 'delete-pattern', label: __( 'Delete' ), isEligible: ( item ) => { + if ( ! item ) { + return false; + } const isTemplatePart = item.type === TEMPLATE_PART_POST_TYPE; - const hasThemeFile = isTemplatePart && item.templatePart.has_theme_file; + const hasThemeFile = + isTemplatePart && item.templatePart?.has_theme_file; return canDeleteOrReset( item ) && ! hasThemeFile; }, hideModalHeader: true, diff --git a/packages/editor/src/components/post-actions/export-pattern-action.js b/packages/editor/src/components/post-actions/export-pattern-action.js index 16d03150bc5cff..7b344e2c42a77c 100644 --- a/packages/editor/src/components/post-actions/export-pattern-action.js +++ b/packages/editor/src/components/post-actions/export-pattern-action.js @@ -36,7 +36,12 @@ export const exportPatternAsJSONAction = { id: 'export-pattern', label: __( 'Export as JSON' ), supportsBulk: true, - isEligible: ( item ) => item.type === PATTERN_TYPES.user, + isEligible: ( item ) => { + if ( ! item.type ) { + return false; + } + return item.type === PATTERN_TYPES.user + }, callback: async ( items ) => { if ( items.length === 1 ) { return downloadBlob(