Skip to content

Commit

Permalink
Remove hotfixes for title.rendered from navigation block code
Browse files Browse the repository at this point in the history
#52758 fixes the response from the fallback-navigation endpoint that did not have title.raw in the response, meaning we had to sometimes rely on title.rendered. This removes the extra 'or' statements that were added as hot fixes. The ones that still rely on title.rendered are due to the value needing to be checked within an object, or somewhere that the title property is not rendered via react.
  • Loading branch information
jeryj committed Jul 20, 2023
1 parent 093cd3d commit ea4afb5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const MainContent = ( {
? sprintf(
/* translators: %s: The name of a menu. */
__( 'Structure for navigation menu: %s' ),
navigationMenu?.title?.rendered || __( 'Untitled menu' )
navigationMenu?.title || __( 'Untitled menu' )
)
: __(
'You have not yet created any menus. Displaying a list of your Pages'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ import useNavigationMenu from '../use-navigation-menu';
import useNavigationEntities from '../use-navigation-entities';

function buildMenuLabel( title, id, status ) {
if ( ! title?.rendered ) {
if ( ! title ) {
/* translators: %s is the index of the menu in the list of menus. */
return sprintf( __( '(no title %s)' ), id );
}

if ( status === 'publish' ) {
return decodeEntities( title?.rendered );
return decodeEntities( title );
}

return sprintf(
// translators: %1s: title of the menu; %2s: status of the menu (draft, pending, etc.).
__( '%1$s (%2$s)' ),
decodeEntities( title?.rendered ),
decodeEntities( title ),
status
);
}
Expand Down Expand Up @@ -72,7 +72,11 @@ function NavigationMenuSelector( {
const menuChoices = useMemo( () => {
return (
navigationMenus?.map( ( { id, title, status }, index ) => {
const label = buildMenuLabel( title, index + 1, status );
const label = buildMenuLabel(
title.rendered,
index + 1,
status
);

return {
value: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ function useDuplicateNavigationMenu() {
useDispatch( noticesStore );

const handleDuplicate = async ( navigationMenu ) => {
const menuTitle =
navigationMenu?.title?.rendered || navigationMenu?.slug;
const menuTitle = navigationMenu?.title || navigationMenu?.slug;

try {
const savedRecord = await saveEntityRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import { unlock } from '../../lock-unlock';

// Copied from packages/block-library/src/navigation/edit/navigation-menu-selector.js.
function buildMenuLabel( title, id, status ) {
if ( ! title?.rendered ) {
if ( ! title ) {
/* translators: %s is the index of the menu in the list of menus. */
return sprintf( __( '(no title %s)' ), id );
}

if ( status === 'publish' ) {
return decodeEntities( title?.rendered );
return decodeEntities( title );
}

return sprintf(
// translators: %1s: title of the menu; %2s: status of the menu (draft, pending, etc.).
__( '%1$s (%2$s)' ),
decodeEntities( title?.rendered ),
decodeEntities( title ),
status
);
}
Expand Down Expand Up @@ -124,7 +124,7 @@ export default function SidebarNavigationScreenNavigationMenus() {
withChevron
icon={ navigation }
>
{ buildMenuLabel( title, index + 1, status ) }
{ buildMenuLabel( title.rendered, index + 1, status ) }
</NavMenuItem>
) ) }
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function TemplatePartNavigationMenu( { id } ) {
upperCase={ true }
weight={ 500 }
>
{ title?.rendered || title || __( 'Navigation' ) }
{ title || __( 'Navigation' ) }
</Heading>
<NavigationMenuEditor navigationMenuId={ id } />
</>
Expand Down

0 comments on commit ea4afb5

Please sign in to comment.