From c0150921335b25c77e0ef89fc65a96e9a94c61d0 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Wed, 16 Oct 2024 16:14:05 +0200 Subject: [PATCH] Reintroduce the client-side filtering of email templates We still need to filter the templates because, in some cases, the API also returns custom templates ignoring the post_type filter in the query [MAILPOET-6279] --- .../src/email-editor/engine/store/selectors.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mailpoet/assets/js/src/email-editor/engine/store/selectors.ts b/mailpoet/assets/js/src/email-editor/engine/store/selectors.ts index 1d49e7378d..77f96c9a0b 100644 --- a/mailpoet/assets/js/src/email-editor/engine/store/selectors.ts +++ b/mailpoet/assets/js/src/email-editor/engine/store/selectors.ts @@ -196,10 +196,18 @@ export const getCurrentTemplate = createRegistrySelector((select) => () => { */ export const getEmailTemplates = createRegistrySelector( (select) => () => - select(coreDataStore).getEntityRecords('postType', 'wp_template', { - per_page: -1, - post_type: 'mailpoet_email', - }), + select(coreDataStore) + .getEntityRecords('postType', 'wp_template', { + per_page: -1, + post_type: 'mailpoet_email', + }) + // We still need to filter the templates because, in some cases, the API also returns custom templates + // ignoring the post_type filter in the query + ?.filter( + (template) => + // @ts-expect-error Missing property in type + template.theme === 'mailpoet/mailpoet', + ), ); export function getEmailPostId(state: State): number {