Skip to content

Commit

Permalink
Navigation: Add a manage menus button to the menu selector dropdown (#…
Browse files Browse the repository at this point in the history
…47005)

Co-authored-by: Ben Dwyer <ben@escruffian.com>
  • Loading branch information
scruffian and Ben Dwyer authored Jan 12, 2023
1 parent 0a06e03 commit 7c0f2dd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
37 changes: 24 additions & 13 deletions packages/block-library/src/navigation/edit/manage-menus-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';
import { Button } from '@wordpress/components';
import { Button, MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

const ManageMenusButton = ( { className = '', disabled } ) => (
<Button
variant="link"
disabled={ disabled }
className={ className }
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
);
const ManageMenusButton = ( {
className = '',
disabled,
isMenuItem = false,
} ) => {
let ComponentName = Button;
if ( isMenuItem ) {
ComponentName = MenuItem;
}

return (
<ComponentName
variant="link"
disabled={ disabled }
className={ className }
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</ComponentName>
);
};

export default ManageMenusButton;
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const ExperimentControls = ( props ) => {
onCreateNew,
onSelectClassicMenu,
onSelectNavigationMenu,
isManageMenusButtonDisabled,
} = props;

return (
Expand All @@ -88,6 +89,7 @@ const ExperimentControls = ( props ) => {
}
createNavigationMenuIsError={ createNavigationMenuIsError }
actionLabel={ actionLabel }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
/>
</HStack>
<ExperimentMainContent { ...props } />
Expand Down Expand Up @@ -116,6 +118,7 @@ const DefaultControls = ( props ) => {
createNavigationMenuIsSuccess={ createNavigationMenuIsSuccess }
createNavigationMenuIsError={ createNavigationMenuIsError }
actionLabel={ actionLabel }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
/>
<ManageMenusButton disabled={ isManageMenusButtonDisabled } />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useEffect, useMemo, useState } from '@wordpress/element';
*/
import useNavigationMenu from '../use-navigation-menu';
import useNavigationEntities from '../use-navigation-entities';
import ManageMenusButton from './manage-menus-button';

function NavigationMenuSelector( {
currentMenuId,
Expand All @@ -30,6 +31,7 @@ function NavigationMenuSelector( {
createNavigationMenuIsSuccess,
createNavigationMenuIsError,
toggleProps = {},
isManageMenusButtonDisabled,
} ) {
const isOffCanvasNavigationEditorEnabled =
window?.__experimentalEnableOffCanvasNavigationEditor === true;
Expand Down Expand Up @@ -237,6 +239,14 @@ function NavigationMenuSelector( {
>
{ __( 'Create new menu' ) }
</MenuItem>
{ isOffCanvasNavigationEditorEnabled && (
<ManageMenusButton
isManageMenusButtonDisabled={
isManageMenusButtonDisabled
}
isMenuItem={ true }
/>
) }
</MenuGroup>
) }
</>
Expand Down

0 comments on commit 7c0f2dd

Please sign in to comment.