Skip to content

Commit

Permalink
Patterns: Add handling of sync status to the wp-admin patterns list p…
Browse files Browse the repository at this point in the history
…age (#52346)
  • Loading branch information
glendaviesnz authored Jul 6, 2023
1 parent f6efbc2 commit 00cfeee
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function ImportForm( { instanceId, onUpload } ) {
case 'Invalid JSON file':
uiMessage = __( 'Invalid JSON file' );
break;
case 'Invalid Reusable block JSON file':
uiMessage = __( 'Invalid Reusable block JSON file' );
case 'Invalid Pattern JSON file':
uiMessage = __( 'Invalid Pattern JSON file' );
break;
default:
uiMessage = __( 'Unknown error' );
Expand Down
4 changes: 1 addition & 3 deletions packages/list-reusable-blocks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
const showNotice = () => {
const notice = document.createElement( 'div' );
notice.className = 'notice notice-success is-dismissible';
notice.innerHTML = `<p>${ __(
'Reusable block imported successfully!'
) }</p>`;
notice.innerHTML = `<p>${ __( 'Pattern imported successfully!' ) }</p>`;

const headerEnd = document.querySelector( '.wp-header-end' );
if ( ! headerEnd ) {
Expand Down
2 changes: 2 additions & 0 deletions packages/list-reusable-blocks/src/utils/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ async function exportReusableBlock( id ) {
} );
const title = post.title.raw;
const content = post.content.raw;
const syncStatus = post.wp_pattern_sync_status;
const fileContent = JSON.stringify(
{
__file: 'wp_block',
title,
content,
syncStatus,
},
null,
2
Expand Down
10 changes: 8 additions & 2 deletions packages/list-reusable-blocks/src/utils/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ async function importReusableBlock( file ) {
! parsedContent.title ||
! parsedContent.content ||
typeof parsedContent.title !== 'string' ||
typeof parsedContent.content !== 'string'
typeof parsedContent.content !== 'string' ||
( parsedContent.syncStatus &&
typeof parsedContent.syncStatus !== 'string' )
) {
throw new Error( 'Invalid Reusable block JSON file' );
throw new Error( 'Invalid Pattern JSON file' );
}
const postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );
const reusableBlock = await apiFetch( {
Expand All @@ -38,6 +40,10 @@ async function importReusableBlock( file ) {
title: parsedContent.title,
content: parsedContent.content,
status: 'publish',
meta:
parsedContent.syncStatus === 'unsynced'
? { wp_pattern_sync_status: parsedContent.syncStatus }
: undefined,
},
method: 'POST',
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test.describe( 'Managing reusable blocks', () => {

// Wait for the success notice.
await expect(
page.locator( 'text=Reusable block imported successfully!' )
page.locator( 'text=Pattern imported successfully!' )
).toBeVisible();

// Refresh the page.
Expand Down

0 comments on commit 00cfeee

Please sign in to comment.