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

Prevent saving the post before previewing in locked/read-only mode. #32341

Merged
merged 3 commits into from
Jun 2, 2021
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
12 changes: 9 additions & 3 deletions packages/editor/src/components/post-preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ export class PostPreviewButton extends Component {
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
this.previewWindow.focus();

// If we don't need to autosave the post before previewing, then we simply
// load the Preview URL in the Preview tab.
if ( ! this.props.isAutosaveable ) {
if (
// If we don't need to autosave the post before previewing, then we simply
// load the Preview URL in the Preview tab.
! this.props.isAutosaveable ||
// Do not save or overwrite the post, if the post is already locked.
this.props.isPostLocked
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: @joemcgill suggested to expose this boolean as a component prop to PostPreviewButton but in my opinion, we should never perform any create/update changes to a post which is already locked by someone else. So this should be checked in all the cases. So there's no point exposing it as a prop.

) {
this.setPreviewWindowLink( event.target.href );
return;
}
Expand Down Expand Up @@ -238,6 +242,7 @@ export default compose( [
isEditedPostSaveable,
isEditedPostAutosaveable,
getEditedPostPreviewLink,
isPostLocked,
} = select( editorStore );
const { getPostType } = select( coreStore );

Expand All @@ -256,6 +261,7 @@ export default compose( [
[ 'draft', 'auto-draft' ].indexOf(
getEditedPostAttribute( 'status' )
) !== -1,
isPostLocked: isPostLocked(),
};
} ),
withDispatch( ( dispatch ) => ( {
Expand Down