Skip to content

Commit

Permalink
Prevent saving the post before previewing in locked/read-only mode. (#…
Browse files Browse the repository at this point in the history
…32341)

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

* Fix nit, remove extra comment.
  • Loading branch information
desaiuditd authored and youknowriad committed Jun 7, 2021
1 parent 1a8057b commit e7d6fe4
Showing 1 changed file with 9 additions and 3 deletions.
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 @@ -159,9 +159,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
) {
this.setPreviewWindowLink( event.target.href );
return;
}
Expand Down Expand Up @@ -232,6 +236,7 @@ export default compose( [
isEditedPostSaveable,
isEditedPostAutosaveable,
getEditedPostPreviewLink,
isPostLocked,
} = select( 'core/editor' );
const { getPostType } = select( 'core' );

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

0 comments on commit e7d6fe4

Please sign in to comment.