Add text information for recent category templates

MAILPOET-6331
This commit is contained in:
Oluwaseun Olorunsola
2024-12-04 15:46:28 +01:00
committed by Oluwaseun Olorunsola
parent cec952fbde
commit 2896ed45eb
3 changed files with 52 additions and 21 deletions

View File

@ -1,6 +1,4 @@
import { Button } from '@wordpress/components'; import { Button } from '@wordpress/components';
import { info } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { TemplateCategory } from '../../store'; import { TemplateCategory } from '../../store';
type Props = { type Props = {
@ -19,7 +17,6 @@ export function TemplateCategoriesListSidebar( {
<div className={ baseClassName }> <div className={ baseClassName }>
<div className={ `${ baseClassName }__categories-list` }> <div className={ `${ baseClassName }__categories-list` }>
{ templateCategories.map( ( { name, label } ) => { { templateCategories.map( ( { name, label } ) => {
const isRecentButton = name === 'recent';
return ( return (
<Button <Button
key={ name } key={ name }
@ -29,19 +26,6 @@ export function TemplateCategoriesListSidebar( {
onClick={ () => { onClick={ () => {
onClickCategory( name ); onClickCategory( name );
} } } }
showTooltip={ isRecentButton }
tooltipPosition="top"
aria-label="This is some content"
icon={ isRecentButton ? info : null }
iconPosition="right"
describedBy={
isRecentButton
? __(
'Templates created on the legacy editor will not appear here',
'mailpoet'
)
: null
}
> >
{ label } { label }
</Button> </Button>

View File

@ -1,9 +1,11 @@
import { useMemo } from '@wordpress/element'; import { useMemo, memo } from '@wordpress/element';
// @ts-expect-error No types available for this component // @ts-expect-error No types available for this component
import { BlockPreview } from '@wordpress/block-editor'; import { BlockPreview } from '@wordpress/block-editor';
import { import {
__experimentalHStack as HStack, // eslint-disable-line __experimentalHStack as HStack, // eslint-disable-line
Notice,
} from '@wordpress/components'; } from '@wordpress/components';
import { Icon, info, blockDefault } from '@wordpress/icons';
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { Async } from './async'; import { Async } from './async';
import { TemplateCategory, TemplatePreview } from '../../store'; import { TemplateCategory, TemplatePreview } from '../../store';
@ -14,7 +16,32 @@ type Props = {
selectedCategory?: TemplateCategory; selectedCategory?: TemplateCategory;
}; };
function TemplateListBox( { templates, onTemplateSelection }: Props ) { function TemplateNoResults() {
return (
<div className="block-editor-inserter__no-results">
<Icon
className="block-editor-inserter__no-results-icon"
icon={ blockDefault }
/>
<p>{ __( 'No recent templates.' ) }</p>
<p>
{ __(
'Your recent creations will appear here as soon as you begin.'
) }
</p>
</div>
);
}
function TemplateListBox( {
templates,
onTemplateSelection,
selectedCategory,
}: Props ) {
if ( selectedCategory === 'recent' && templates.length === 0 ) {
return <TemplateNoResults />;
}
return ( return (
<div className="block-editor-block-patterns-list" role="listbox"> <div className="block-editor-block-patterns-list" role="listbox">
{ templates.map( ( template ) => ( { templates.map( ( template ) => (
@ -66,6 +93,12 @@ function TemplateListBox( { templates, onTemplateSelection }: Props ) {
); );
} }
const compareProps = ( prev, next ) =>
prev.templates.length === next.templates.length &&
prev.selectedCategory === next.selectedCategory;
const MemorizedTemplateListBox = memo( TemplateListBox, compareProps );
export function TemplateList( { export function TemplateList( {
templates, templates,
onTemplateSelection, onTemplateSelection,
@ -81,9 +114,24 @@ export function TemplateList( {
return ( return (
<div className="block-editor-block-patterns-explorer__list"> <div className="block-editor-block-patterns-explorer__list">
<TemplateListBox { selectedCategory === 'recent' && (
<Notice isDismissible={ false }>
<HStack spacing={ 1 } expanded={ false } justify="start">
<Icon icon={ info } />
<p>
{ __(
'Templates created on the legacy editor will not appear here.',
'mailpoet'
) }
</p>
</HStack>
</Notice>
) }
<MemorizedTemplateListBox
templates={ filteredTemplates } templates={ filteredTemplates }
onTemplateSelection={ onTemplateSelection } onTemplateSelection={ onTemplateSelection }
selectedCategory={ selectedCategory }
/> />
</div> </div>
); );

View File

@ -35,7 +35,7 @@ function Editor() {
const WrappedEditor = applyFilters( const WrappedEditor = applyFilters(
'mailpoet_email_editor_wrap_editor_component', 'mailpoet_email_editor_wrap_editor_component',
Editor Editor
); ) as typeof Editor;
export function initialize( elementId: string ) { export function initialize( elementId: string ) {
const container = document.getElementById( elementId ); const container = document.getElementById( elementId );
@ -47,6 +47,5 @@ export function initialize( elementId: string ) {
initBlocks(); initBlocks();
initHooks(); initHooks();
const root = createRoot( container ); const root = createRoot( container );
// @ts-ignore We don't have a type for WrappedEditor.
root.render( <WrappedEditor /> ); root.render( <WrappedEditor /> );
} }