Skip to content

Commit 7efbc10

Browse files
committed
Refine logic for displaying publish button in email editor
Adjust conditions to ensure proper handling of template edits, post entity changes, and draft states.
1 parent 3561eae commit 7efbc10

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

packages/js/email-editor/src/hacks/publish-save.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,32 @@ function NextPublishSlot( { children }: NextButtonSlotPropType ) {
4040

4141
export function PublishSave() {
4242
const observerRef = useRef< MutationObserver | null >( null );
43-
const { hasNonPostEntityChanges, isEditedPostDirty, currentPost } =
43+
const { hasNonPostEntityChanges, isEditedPostDirty, isEditingTemplate } =
4444
useSelect(
4545
( select ) => ( {
4646
hasNonPostEntityChanges:
4747
// @ts-expect-error hasNonPostEntityChanges is not typed in @types/wordpress__editor
4848
select( editorStore ).hasNonPostEntityChanges(),
4949
isEditedPostDirty: select( editorStore ).isEditedPostDirty(),
50-
currentPost: select( editorStore ).getCurrentPost(),
50+
isEditingTemplate:
51+
select( editorStore ).getCurrentPostType() ===
52+
'wp_template',
5153
} ),
5254
[]
5355
);
5456

55-
// Check the post status
56-
const isDraftPost = currentPost.status === 'draft';
57-
58-
// Display original button when there are changes to save except for draft
59-
// For draft, there is an extra save button to save as draft
60-
// Also display original button when the post is in draft status
57+
// Display the original publish button when:
58+
// - The user is editing a template (regardless of detected changes).
59+
// - There are changes outside of the post (e.g., in a linked template).
60+
// - There are changes in the post together with changes outside of it.
61+
//
62+
// Do not display the button when:
63+
// - There are only changes in the post content with no related entity changes.
64+
// Draft posts have their own "Save as draft" button.
6165
const displayOriginalPublishButton =
62-
( hasNonPostEntityChanges || isEditedPostDirty ) && ! isDraftPost;
66+
isEditingTemplate ||
67+
hasNonPostEntityChanges ||
68+
( isEditedPostDirty && hasNonPostEntityChanges );
6369

6470
const toggleElementVisible = useCallback(
6571
( element: Element, visible: boolean ) => {

0 commit comments

Comments
 (0)