Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation: Add a manage menus button to the menu selector dropdown #47005

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -234,6 +236,14 @@ function NavigationMenuSelector( {
>
{ __( 'Create new menu' ) }
</MenuItem>
{ isOffCanvasNavigationEditorEnabled && (
<ManageMenusButton
isManageMenusButtonDisabled={
isManageMenusButtonDisabled
}
isMenuItem={ true }
/>
) }
</MenuGroup>
) }
</>
Expand Down