Fetch template content for validation properly
When editing the template, the content property might be a function or empty, and we need to build content by serializing blocks. [MAILPOET-6393]
This commit is contained in:
committed by
Aschepikov
parent
79ec5a5ffd
commit
afb183bd71
@ -38,7 +38,7 @@ export const useContentValidation = (): ContentValidationData => {
|
|||||||
editedContent:
|
editedContent:
|
||||||
mapSelect( emailEditorStore ).getEditedEmailContent(),
|
mapSelect( emailEditorStore ).getEditedEmailContent(),
|
||||||
editedTemplateContent:
|
editedTemplateContent:
|
||||||
mapSelect( emailEditorStore ).getCurrentTemplate()?.content,
|
mapSelect( emailEditorStore ).getCurrentTemplateContent(),
|
||||||
postTemplateId:
|
postTemplateId:
|
||||||
mapSelect( emailEditorStore ).getCurrentTemplate()?.id,
|
mapSelect( emailEditorStore ).getCurrentTemplate()?.id,
|
||||||
} )
|
} )
|
||||||
|
@ -9,6 +9,19 @@ import { storeName } from './constants';
|
|||||||
import { State, Feature, EmailTemplate, EmailEditorPostType } from './types';
|
import { State, Feature, EmailTemplate, EmailEditorPostType } from './types';
|
||||||
import { Post } from '@wordpress/core-data/build-types/entity-types/post';
|
import { Post } from '@wordpress/core-data/build-types/entity-types/post';
|
||||||
|
|
||||||
|
function getContentFromEntity( entity ): string {
|
||||||
|
if ( entity?.content && typeof entity.content === 'function' ) {
|
||||||
|
return entity.content( entity ) as string;
|
||||||
|
}
|
||||||
|
if ( entity?.blocks ) {
|
||||||
|
return serialize( entity.blocks );
|
||||||
|
}
|
||||||
|
if ( entity?.content ) {
|
||||||
|
return entity.content as string;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
export const isFeatureActive = createRegistrySelector(
|
export const isFeatureActive = createRegistrySelector(
|
||||||
( select ) =>
|
( select ) =>
|
||||||
( _, feature: Feature ): boolean =>
|
( _, feature: Feature ): boolean =>
|
||||||
@ -126,15 +139,7 @@ export const getEditedEmailContent = createRegistrySelector(
|
|||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
if ( record ) {
|
if ( record ) {
|
||||||
if ( record?.content && typeof record.content === 'function' ) {
|
return getContentFromEntity( record );
|
||||||
return record.content( record ) as string;
|
|
||||||
}
|
|
||||||
if ( record?.blocks ) {
|
|
||||||
return serialize( record.blocks );
|
|
||||||
}
|
|
||||||
if ( record?.content ) {
|
|
||||||
return record.content as string;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -199,11 +204,6 @@ export const getEditedPostTemplate = createRegistrySelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getTemplateContent = () => {
|
|
||||||
const template = getEditedPostTemplate();
|
|
||||||
return template?.content || '';
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getCurrentTemplate = createRegistrySelector( ( select ) => () => {
|
export const getCurrentTemplate = createRegistrySelector( ( select ) => () => {
|
||||||
const isEditingTemplate =
|
const isEditingTemplate =
|
||||||
select( editorStore ).getCurrentPostType() === 'wp_template';
|
select( editorStore ).getCurrentPostType() === 'wp_template';
|
||||||
@ -221,6 +221,14 @@ export const getCurrentTemplate = createRegistrySelector( ( select ) => () => {
|
|||||||
return getEditedPostTemplate();
|
return getEditedPostTemplate();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
export const getCurrentTemplateContent = () => {
|
||||||
|
const template = getCurrentTemplate();
|
||||||
|
if ( template ) {
|
||||||
|
return getContentFromEntity( template );
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
export const getGlobalEmailStylesPost = createRegistrySelector(
|
export const getGlobalEmailStylesPost = createRegistrySelector(
|
||||||
( select ) => () => {
|
( select ) => () => {
|
||||||
const postId = select( storeName ).getGlobalStylesPostId();
|
const postId = select( storeName ).getGlobalStylesPostId();
|
||||||
|
Reference in New Issue
Block a user