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

Fix iframe error when accessing Add new Page on post command palette #94114

Merged
merged 4 commits into from
Sep 3, 2024
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 @@ -1075,16 +1075,16 @@ function handleAppBannerShowing( calypsoPort ) {
};
}

function handlePatterns( calypsoPort ) {
const selector = `[data-value="${ __( 'Patterns' ) }"]`;
function handleWpAdminRedirect( { calypsoPort, path, title } ) {
const selector = `[data-value="${ title }"]`;

const callback = ( e ) => {
e.preventDefault();

calypsoPort.postMessage( {
action: 'goToPatterns',
action: 'wpAdminRedirect',
payload: {
destinationUrl: '/wp-admin/site-editor.php?postType=wp_block',
destinationUrl: `/wp-admin/${ path }`,
unsavedChanges: select( 'core/editor' ).isEditedPostDirty(),
},
} );
Expand All @@ -1094,6 +1094,26 @@ function handlePatterns( calypsoPort ) {
addCommandsInputListener( selector, callback );
}

function handlePatterns( calypsoPort ) {
handleWpAdminRedirect( {
calypsoPort,
path: 'site-editor.php?postType=wp_block',
title: __( 'Patterns' ),
} );
}

function handleAddPage( calypsoPort ) {
handleWpAdminRedirect( {
calypsoPort,
path: 'post-new.php?post_type=page',
title: __( 'Add new page' ),
} );
}

function handleAddPost( calypsoPort ) {
handleWpAdminRedirect( { calypsoPort, path: 'post-new.php', title: __( 'Add new post' ) } );
}

function initPort( message ) {
if ( 'initPort' !== message.data.action ) {
return;
Expand Down Expand Up @@ -1196,6 +1216,10 @@ function initPort( message ) {
handleAppBannerShowing( calypsoPort );

handlePatterns( calypsoPort );

handleAddPage( calypsoPort );

handleAddPost( calypsoPort );
}

window.removeEventListener( 'message', initPort, false );
Expand Down
4 changes: 2 additions & 2 deletions client/gutenberg/editor/calypsoify-iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ enum WindowActions {

enum EditorActions {
GoToAllPosts = 'goToAllPosts', // Unused action in favor of CloseEditor. Maintained here to support cached scripts.
GoToPatterns = 'goToPatterns',
WpAdminRedirect = 'wpAdminRedirect',
CloseEditor = 'closeEditor',
OpenMediaModal = 'openMediaModal',
OpenCheckoutModal = 'openCheckoutModal',
Expand Down Expand Up @@ -383,7 +383,7 @@ class CalypsoifyIframe extends Component< ComponentProps, State > {
this.navigate( destinationUrl, unsavedChanges );
}

if ( EditorActions.GoToPatterns === action ) {
if ( EditorActions.WpAdminRedirect === action ) {
const { destinationUrl, unsavedChanges } = payload;

this.navigate( `https://${ this.props.siteSlug }${ destinationUrl }`, unsavedChanges );
Expand Down
Loading