Skip to content

Commit

Permalink
false value checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed May 14, 2024
1 parent 64d782a commit 6a93152
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
11 changes: 9 additions & 2 deletions packages/editor/src/components/post-actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 0 additions & 9 deletions test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down

0 comments on commit 6a93152

Please sign in to comment.