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

PostSyncStatus: Derive sync status inside the selector #54159

Merged
merged 2 commits into from
Sep 5, 2023
Merged
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
22 changes: 14 additions & 8 deletions packages/editor/src/components/post-sync-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,34 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis );

export default function PostSyncStatus() {
const { syncStatus, postType, meta } = useSelect( ( select ) => {
const { syncStatus, postType } = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
const meta = getEditedPostAttribute( 'meta' );

// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
const currentSyncStatus =
meta?.wp_pattern_sync_status === 'unsynced'
? 'unsynced'
: getEditedPostAttribute( 'wp_pattern_sync_status' );

return {
syncStatus: getEditedPostAttribute( 'wp_pattern_sync_status' ),
meta: getEditedPostAttribute( 'meta' ),
syncStatus: currentSyncStatus,
postType: getEditedPostAttribute( 'type' ),
};
} );

if ( postType !== 'wp_block' ) {
return null;
}
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
const currentSyncStatus =
meta?.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : syncStatus;

return (
<PanelRow className="edit-post-sync-status">
<span>{ __( 'Sync status' ) }</span>
<div>
{ currentSyncStatus === 'unsynced'
{ syncStatus === 'unsynced'
? __( 'Not synced' )
: __( 'Fully synced' ) }
</div>
Expand Down Expand Up @@ -82,7 +88,7 @@ export function PostSyncStatusModal() {
if ( postType !== 'wp_block' || ! isNewPost ) {
return null;
}
const { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis );

return (
<>
{ isModalOpen && (
Expand Down
Loading