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

Patterns: Add handling of sync status to the wp-admin patterns list page #52346

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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