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 Jun 2, 2021
1 parent eefff53 commit f101c23
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 @@ -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
) {
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

0 comments on commit f101c23

Please sign in to comment.