Skip to content

Commit

Permalink
Add post locked check in isEditedPostSaveable.
Browse files Browse the repository at this point in the history
So that we can prevent saving if the post is locked.

We also prevent disabling Preview button when the post is not saveable. This is ripple effect of adding isPostLocked check in `isEditedPostSaveable` selector. We can safely remove this check on `Preview` button, because #32341 will prevent any save actions under the hood.
  • Loading branch information
desaiuditd committed Feb 9, 2024
1 parent 8f0dbd2 commit 9d4260d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/editor/src/components/post-preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export default function PostPreviewButton( {
role,
onPreview,
} ) {
const { postId, currentPostLink, previewLink, isSaveable, isViewable } =
useSelect( ( select ) => {
const { postId, currentPostLink, previewLink, isViewable } = useSelect(
( select ) => {
const editor = select( editorStore );
const core = select( coreStore );

Expand All @@ -119,10 +119,11 @@ export default function PostPreviewButton( {
postId: editor.getCurrentPostId(),
currentPostLink: editor.getCurrentPostAttribute( 'link' ),
previewLink: editor.getEditedPostPreviewLink(),
isSaveable: editor.isEditedPostSaveable(),
isViewable: postType?.viewable ?? false,
};
}, [] );
},
[]
);

const { __unstableSaveForPreview } = useDispatch( editorStore );

Expand Down Expand Up @@ -168,7 +169,6 @@ export default function PostPreviewButton( {
className={ className || 'editor-post-preview' }
href={ href }
target={ targetId }
disabled={ ! isSaveable }
onClick={ openPreviewWindow }
role={ role }
>
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ export function isEditedPostSaveable( state ) {
return false;
}

if ( isPostLocked( state ) ) {
return false;
}

// TODO: Post should not be saveable if not dirty. Cannot be added here at
// this time since posts where meta boxes are present can be saved even if
// the post is not dirty. Currently this restriction is imposed at UI, but
Expand Down

0 comments on commit 9d4260d

Please sign in to comment.