Skip to content

Commit

Permalink
Hide empty menus
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 committed Nov 20, 2020
1 parent 4cfe6ba commit 937e4cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { MENU_TEMPLATES, MENU_TEMPLATES_PAGES } from '../constants';

export default function TemplatesPagesMenu( { templates } ) {
const defaultTemplate = templates?.find( ( { slug } ) => slug === 'page' );
const specificTemplates = templates?.filter( ( { slug } ) =>
slug.startsWith( 'page-' )
);
const specificTemplates =
templates?.filter( ( { slug } ) => slug.startsWith( 'page-' ) ) ?? [];

return (
<NavigationMenu
menu={ MENU_TEMPLATES_PAGES }
title={ __( 'Pages' ) }
parentMenu={ MENU_TEMPLATES }
isEmpty={ ! defaultTemplate && specificTemplates.length === 0 }
>
<NavigationGroup title={ _x( 'Specific', 'specific templates' ) }>
{ map( specificTemplates, ( template ) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ import {
} from '../constants';

export default function TemplatesPostsMenu( { templates } ) {
const generalTemplates = templates?.filter( ( { slug } ) =>
TEMPLATES_POSTS.includes( slug )
);
const specificTemplates = templates?.filter( ( { slug } ) =>
slug.startsWith( 'post-' )
);
const generalTemplates =
templates?.filter( ( { slug } ) => TEMPLATES_POSTS.includes( slug ) ) ??
[];
const specificTemplates =
templates?.filter( ( { slug } ) => slug.startsWith( 'post-' ) ) ?? [];

return (
<NavigationMenu
menu={ MENU_TEMPLATES_POSTS }
title={ __( 'Posts' ) }
parentMenu={ MENU_TEMPLATES }
isEmpty={
generalTemplates.length === 0 && specificTemplates.length === 0
}
>
<NavigationGroup title={ _x( 'Specific', 'specific templates' ) }>
{ map( specificTemplates, ( template ) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ export default function TemplatesMenu() {
<NavigationItem
navigateToMenu={ MENU_TEMPLATES_PAGES }
title={ __( 'Pages' ) }
hideIfTargetMenuEmpty
/>
<NavigationItem
navigateToMenu={ MENU_TEMPLATES_POSTS }
title={ __( 'Posts' ) }
hideIfTargetMenuEmpty
/>
<TemplatesPostsMenu templates={ templates } />
<TemplatesPagesMenu templates={ templates } />
Expand Down

0 comments on commit 937e4cf

Please sign in to comment.