Skip to content

Commit

Permalink
Simplify title
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 committed Oct 14, 2020
1 parent d426ab0 commit 45e658c
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { useDispatch, useSelect } from '@wordpress/data';
import { __experimentalNavigationItem as NavigationItem } from '@wordpress/components';
import { getPathAndQueryString } from '@wordpress/url';

const EXTRACTORS_TITLE = {
'taxonomy-category': ( entity ) => entity.name,
default: ( entity ) => entity?.title?.rendered,
};
const getEntityTitle = ( kind, entity ) =>
'taxonomy' === kind ? entity.name : entity?.title?.rendered;

export default function NavigationEntityItems( { kind, name, query = {} } ) {
const entities = useSelect(
Expand Down Expand Up @@ -36,15 +34,12 @@ export default function NavigationEntityItems( { kind, name, query = {} } ) {

return entities.map( ( entity ) => {
const key = `content-${ getPathAndQueryString( entity.link ) }`;
const titleExtractor =
EXTRACTORS_TITLE[ `${ kind }-${ name }` ] ||
EXTRACTORS_TITLE.default;

return (
<NavigationItem
key={ key }
item={ key }
title={ titleExtractor( entity ) }
title={ getEntityTitle( kind, entity ) }
onClick={ () => onActivateItem( entity ) }
/>
);
Expand Down

0 comments on commit 45e658c

Please sign in to comment.