Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable Blocks: Support importing and exporting reusable blocks #9788

Merged
merged 8 commits into from
Sep 14, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ class ImportForm extends Component {
return;
}

this.setState( { isLoading: false, error: error.message } );
let uiMessage;
switch ( error.message ) {
case 'Invalid JSON file':
uiMessage = __( 'Invalid JSON file' );
break;
case 'Invalid Reusable Block JSON file':
uiMessage = __( 'Invalid Reusable Block JSON file' );
break;
default:
uiMessage = __( 'Unknow error' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "Unknow" -> "Unknown"

}

this.setState( { isLoading: false, error: uiMessage } );
} );
}

Expand Down
5 changes: 2 additions & 3 deletions packages/list-reusable-blocks/src/utils/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { isString } from 'lodash';
* WordPress dependencies
*/
import apiFetch from '@wordpress/api-fetch';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -26,7 +25,7 @@ async function importReusableBlock( file ) {
try {
parsedContent = JSON.parse( fileContent );
} catch ( e ) {
throw new Error( __( 'Invalid JSON file' ) );
throw new Error( 'Invalid JSON file' );
}
if (
parsedContent.__file !== 'wp_block' ||
Expand All @@ -35,7 +34,7 @@ async function importReusableBlock( file ) {
! isString( parsedContent.title ) ||
! isString( parsedContent.content )
) {
throw new Error( __( 'Invalid Reusable Block JSON file' ) );
throw new Error( 'Invalid Reusable Block JSON file' );
}
const postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );
const reusableBlock = await apiFetch( {
Expand Down