From e5498b6baf11f822e9dc92410dff6fd2fa7c98d1 Mon Sep 17 00:00:00 2001 From: Oluwaseun Olorunsola Date: Tue, 4 Feb 2025 18:14:52 +0100 Subject: [PATCH] Remove unnecessary use of mailpoet_data MAILPOET-6431 --- .../js/src/mailpoet-email-editor-integration/index.ts | 11 +++++++++++ .../email-editor/src/hooks/use-preview-templates.ts | 11 ++++++++--- packages/js/email-editor/src/store/selectors.ts | 9 ++------- packages/js/email-editor/src/store/types.ts | 1 - packages/php/email-editor/README.md | 2 -- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/mailpoet/assets/js/src/mailpoet-email-editor-integration/index.ts b/mailpoet/assets/js/src/mailpoet-email-editor-integration/index.ts index 9d26a0e14d..1fd7460f3d 100644 --- a/mailpoet/assets/js/src/mailpoet-email-editor-integration/index.ts +++ b/mailpoet/assets/js/src/mailpoet-email-editor-integration/index.ts @@ -62,3 +62,14 @@ addFilter( // eslint-disable-next-line @typescript-eslint/no-unsafe-return (RichTextWithButton) => EmailSidebarExtension.bind(null, RichTextWithButton), ); + +// use mailpoet data subject if available +addFilter( + 'mailpoet_email_editor_preferred_template_title', + 'mailpoet', + (...args) => { + const [, post] = args; + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return post?.mailpoet_data?.subject || ''; // use MailPoet subject as title + }, +); diff --git a/packages/js/email-editor/src/hooks/use-preview-templates.ts b/packages/js/email-editor/src/hooks/use-preview-templates.ts index 062699dba5..14df6bc587 100644 --- a/packages/js/email-editor/src/hooks/use-preview-templates.ts +++ b/packages/js/email-editor/src/hooks/use-preview-templates.ts @@ -5,6 +5,7 @@ import { useMemo } from '@wordpress/element'; import { parse } from '@wordpress/blocks'; import { BlockInstance } from '@wordpress/blocks/index'; import { useSelect } from '@wordpress/data'; +import { applyFilters } from '@wordpress/hooks'; /** * Internal dependencies @@ -163,6 +164,11 @@ export function usePreviewTemplates( const allEmailPosts = useMemo( () => { return emailPosts?.map( ( post: EmailEditorPostType ) => { + const preferredTitle = applyFilters( + 'mailpoet_email_editor_preferred_template_title', + '', + post + ); const { postTemplateContent } = generateTemplateContent( post, allTemplates @@ -180,9 +186,8 @@ export function usePreviewTemplates( const template = { ...post, title: { - raw: post?.mailpoet_data?.subject || post.title.raw, - rendered: - post?.mailpoet_data?.subject || post.title.rendered, // use MailPoet subject as title + raw: post.title.raw, + rendered: preferredTitle || post.title.rendered, }, }; return { diff --git a/packages/js/email-editor/src/store/selectors.ts b/packages/js/email-editor/src/store/selectors.ts index 79e74dc1f9..64d32c486a 100644 --- a/packages/js/email-editor/src/store/selectors.ts +++ b/packages/js/email-editor/src/store/selectors.ts @@ -96,13 +96,8 @@ export const isEmpty = createRegistrySelector( ( select ) => (): boolean => { return true; } - const { content, mailpoet_data: mailpoetData, title } = post; - return ( - ! content.raw && - ! mailpoetData.subject && - ! mailpoetData.preheader && - ! title.raw - ); + const { content, title } = post; + return ! content.raw && ! title.raw; } ); export const hasEmptyContent = createRegistrySelector( diff --git a/packages/js/email-editor/src/store/types.ts b/packages/js/email-editor/src/store/types.ts index cd6786299f..401cc04cf7 100644 --- a/packages/js/email-editor/src/store/types.ts +++ b/packages/js/email-editor/src/store/types.ts @@ -261,7 +261,6 @@ export type MailPoetEmailPostContentExtended = { export type EmailEditorPostType = Omit< Post, 'type' > & { type: string; - mailpoet_data?: MailPoetEmailPostContentExtended; }; export type EmailContentValidationAction = { diff --git a/packages/php/email-editor/README.md b/packages/php/email-editor/README.md index 0aff55335a..362042c5d1 100644 --- a/packages/php/email-editor/README.md +++ b/packages/php/email-editor/README.md @@ -75,5 +75,3 @@ We may add, update and delete any of them. | `mailpoet_email_editor_send_preview_email` | `Array` $postData | `boolean` Result of processing. Was email sent successfully? | Allows override of the send preview mail function. Folks may choose to use custom implementation | | `mailpoet_email_editor_post_sent_status_args` | `Array` `sent` post status args | `Array` register_post_status args | Allows update of the argument for the sent post status | -## TODO -- We use `mailpoet_data` in some section of the codebase. This will be updated.