From 6a931520d9699447be3d38a80c61772dccb572e9 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 ++++++- .../post-actions/export-pattern-action.native.js | 4 ++++ test/native/setup.js | 9 --------- 4 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 packages/editor/src/components/post-actions/export-pattern-action.native.js 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..deeac4314f653f 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( diff --git a/packages/editor/src/components/post-actions/export-pattern-action.native.js b/packages/editor/src/components/post-actions/export-pattern-action.native.js new file mode 100644 index 00000000000000..b09f5a034a5525 --- /dev/null +++ b/packages/editor/src/components/post-actions/export-pattern-action.native.js @@ -0,0 +1,4 @@ +// Client-zip is meant to be used in a browser and is therefore released as an ES6 module only, +// in order for the native build to succeed we are importing a null action and avoiding importing +// the non working in native context client-zip module. +export const exportPatternAsJSONAction = null; diff --git a/test/native/setup.js b/test/native/setup.js index 270df09ab9a4de..4fd511f38e91b1 100644 --- a/test/native/setup.js +++ b/test/native/setup.js @@ -270,15 +270,6 @@ jest.mock( 'react-native/Libraries/Components/Switch/Switch', () => { }; } ); -/** - * client-zip is meant to be used in a browser and is therefore released as an ES6 module only, - * in order to use it in node environment, we need to mock it. - * See: https://github.com/Touffy/client-zip/issues/28 - */ -jest.mock( 'client-zip', () => ( { - downloadZip: jest.fn(), -} ) ); - jest.mock( '@wordpress/compose', () => { return { ...jest.requireActual( '@wordpress/compose' ),