Fix an edge case where it might be possible for email content to have similar post-slug

MAILPOET-5949
This commit is contained in:
Oluwaseun Olorunsola
2024-12-05 17:10:06 +01:00
committed by Oluwaseun Olorunsola
parent 16e4346d07
commit fb5166ab7c
4 changed files with 8 additions and 3 deletions

View File

@ -47,8 +47,7 @@ export function SelectTemplateModal( {
const hasTemplates = templates?.length > 0; const hasTemplates = templates?.length > 0;
const handleTemplateSelection = ( template: TemplatePreview ) => { const handleTemplateSelection = ( template: TemplatePreview ) => {
const templateIsPostContent = const templateIsPostContent = template.type === 'mailpoet_email';
template.template.type === 'mailpoet_email';
const postContent = template.template as unknown as EmailEditorPostType; const postContent = template.template as unknown as EmailEditorPostType;

View File

@ -46,7 +46,7 @@ function TemplateListBox( {
<div className="block-editor-block-patterns-list" role="listbox"> <div className="block-editor-block-patterns-list" role="listbox">
{ templates.map( ( template ) => ( { templates.map( ( template ) => (
<div <div
key={ template.slug } key={ `${ template.slug }_${ template.id }` }
className="block-editor-block-patterns-list__list-item" className="block-editor-block-patterns-list__list-item"
> >
<div <div

View File

@ -100,6 +100,7 @@ export function usePreviewTemplates( customEmailContent = '' ) {
); );
return { return {
id: template.id,
slug: template.slug, slug: template.slug,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
previewContentParsed: parsedTemplate, previewContentParsed: parsedTemplate,
@ -109,11 +110,13 @@ export function usePreviewTemplates( customEmailContent = '' ) {
: contentPatternBlocks, : contentPatternBlocks,
template, template,
category: 'basic', // TODO: This will be updated once template category is implemented category: 'basic', // TODO: This will be updated once template category is implemented
type: template.type,
}; };
} ), } ),
emailPosts?.map( ( post: EmailEditorPostType ) => { emailPosts?.map( ( post: EmailEditorPostType ) => {
const parsedPostContent = parse( post.content?.raw ); const parsedPostContent = parse( post.content?.raw );
return { return {
id: post.id,
slug: post.slug, slug: post.slug,
previewContentParsed: parsedPostContent, previewContentParsed: parsedPostContent,
emailParsed: parsedPostContent, emailParsed: parsedPostContent,
@ -128,6 +131,7 @@ export function usePreviewTemplates( customEmailContent = '' ) {
email_theme_css: '', email_theme_css: '',
}, },
category: 'recent', category: 'recent',
type: post.type,
}; };
} ) as unknown as TemplatePreview[], } ) as unknown as TemplatePreview[],
]; ];

View File

@ -225,11 +225,13 @@ export type EmailTemplatePreview = Omit<
}; };
export type TemplatePreview = { export type TemplatePreview = {
id: string;
slug: string; slug: string;
previewContentParsed: BlockInstance[]; previewContentParsed: BlockInstance[];
emailParsed: BlockInstance[]; emailParsed: BlockInstance[];
template: EmailTemplatePreview; template: EmailTemplatePreview;
category?: TemplateCategory; category?: TemplateCategory;
type: string;
}; };
export type TemplateCategory = 'recent' | 'basic'; export type TemplateCategory = 'recent' | 'basic';