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

Gutenframe: Only try to select the PostLockedModal in appropriate conditions #83353

Merged
merged 1 commit into from
Oct 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -146,39 +146,40 @@ function handlePostLocked( calypsoPort ) {
const unsubscribe = subscribe( () => {
const isLocked = select( 'core/editor' ).isPostLocked();
const isLockTakeover = select( 'core/editor' ).isPostLockTakeover();
const lockedDialogButtons = document.querySelectorAll(
'div.editor-post-locked-modal__buttons > a'
);

const isPostTakeoverDialog = isLocked && ! isLockTakeover && lockedDialogButtons.length === 3;

if ( isPostTakeoverDialog ) {
//signal the parent frame to navigate to All Posts
lockedDialogButtons[ 0 ].addEventListener(
'click',
( event ) => {
event.preventDefault();
calypsoPort.postMessage( { action: 'goToAllPosts' } );
},
false
if ( isLocked && ! isLockTakeover ) {
const lockedDialogButtons = document.querySelectorAll(
'div.editor-post-locked-modal__buttons > a'
);

//overrides the all posts link just in case the user treats the link... as a link.
if ( calypsoifyGutenberg && calypsoifyGutenberg.closeUrl ) {
lockedDialogButtons[ 0 ].setAttribute( 'target', '_parent' );
lockedDialogButtons[ 0 ].setAttribute( 'href', calypsoifyGutenberg.closeUrl );
}
if ( lockedDialogButtons.length === 3 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused, my dialog just has one button:

document.querySelectorAll('div.editor-post-locked-modal__buttons > a');
NodeList [ a.components-button.is-primary ]
0: <a class="components-button is-primary" href="edit.php?post_type=post">
length: 1

Copy link
Contributor

@dsas dsas Oct 24, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It used to be three buttons, but changed to two with WordPress/gutenberg#37852, this probably needs updating. I still can't trigger it so maybe something else is outdated....I'll open an issue

Copy link
Contributor

Choose a reason for hiding this comment

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

//signal the parent frame to navigate to All Posts
lockedDialogButtons[ 0 ].addEventListener(
'click',
( event ) => {
event.preventDefault();
calypsoPort.postMessage( { action: 'goToAllPosts' } );
},
false
);

//changes the Take Over link url to add the frame-nonce
lockedDialogButtons[ 2 ].setAttribute(
'href',
addQueryArgs( lockedDialogButtons[ 2 ].getAttribute( 'href' ), {
calypsoify: 1,
'frame-nonce': getQueryArg( window.location.href, 'frame-nonce' ),
} )
);
//overrides the all posts link just in case the user treats the link... as a link.
if ( calypsoifyGutenberg && calypsoifyGutenberg.closeUrl ) {
lockedDialogButtons[ 0 ].setAttribute( 'target', '_parent' );
lockedDialogButtons[ 0 ].setAttribute( 'href', calypsoifyGutenberg.closeUrl );
}

unsubscribe();
//changes the Take Over link url to add the frame-nonce
lockedDialogButtons[ 2 ].setAttribute(
'href',
addQueryArgs( lockedDialogButtons[ 2 ].getAttribute( 'href' ), {
calypsoify: 1,
'frame-nonce': getQueryArg( window.location.href, 'frame-nonce' ),
} )
);

unsubscribe();
}
}
} );
}
Expand All @@ -192,28 +193,29 @@ function handlePostLockTakeover( calypsoPort ) {
const unsubscribe = subscribe( () => {
const isLocked = select( 'core/editor' ).isPostLocked();
const isLockTakeover = select( 'core/editor' ).isPostLockTakeover();
const allPostsButton = document.querySelector( 'div.editor-post-locked-modal__buttons > a' );

const isPostTakeoverDialog = isLocked && isLockTakeover && allPostsButton;
if ( isLocked && isLockTakeover ) {
const allPostsButton = document.querySelector( 'div.editor-post-locked-modal__buttons > a' );

if ( isPostTakeoverDialog ) {
//handle All Posts button click event
allPostsButton.addEventListener(
'click',
( event ) => {
event.preventDefault();
calypsoPort.postMessage( { action: 'goToAllPosts' } );
},
false
);
if ( allPostsButton ) {
//handle All Posts button click event
allPostsButton.addEventListener(
'click',
( event ) => {
event.preventDefault();
calypsoPort.postMessage( { action: 'goToAllPosts' } );
},
false
);

//overrides the all posts link just in case the user treats the link... as a link.
if ( calypsoifyGutenberg && calypsoifyGutenberg.closeUrl ) {
allPostsButton.setAttribute( 'target', '_parent' );
allPostsButton.setAttribute( 'href', calypsoifyGutenberg.closeUrl );
}
//overrides the all posts link just in case the user treats the link... as a link.
if ( calypsoifyGutenberg && calypsoifyGutenberg.closeUrl ) {
allPostsButton.setAttribute( 'target', '_parent' );
allPostsButton.setAttribute( 'href', calypsoifyGutenberg.closeUrl );
}

unsubscribe();
unsubscribe();
}
}
} );
}
Expand Down
Loading