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 new ManageMenusButton component #45782

Merged
merged 4 commits into from
Nov 15, 2022
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
35 changes: 17 additions & 18 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Platform,
useMemo,
} from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import {
__experimentalOffCanvasEditor as OffCanvasEditor,
InspectorControls,
Expand Down Expand Up @@ -69,6 +68,7 @@ import useConvertClassicToBlockMenu, {
import useCreateNavigationMenu from './use-create-navigation-menu';
import { useInnerBlocks } from './use-inner-blocks';
import { detectColors } from './utils';
import ManageMenusButton from './manage-menus-button';

function Navigation( {
attributes,
Expand Down Expand Up @@ -655,19 +655,6 @@ function Navigation( {
</InspectorControls>
);

const ManageMenusButton = ( { buttonClassName = '' } ) => (
<Button
variant="link"
disabled={ ! hasManagePermissions || ! hasResolvedNavigationMenus }
className={ buttonClassName }
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_navigation',
} ) }
>
{ __( 'Manage menus' ) }
</Button>
);

// If the block has inner blocks, but no menu id, then these blocks are either:
// - inserted via a pattern.
// - inserted directly via Code View (or otherwise).
Expand Down Expand Up @@ -703,6 +690,9 @@ function Navigation( {
/>
);

const isManageMenusButtonDisabled =
! hasManagePermissions || ! hasResolvedNavigationMenus;

if ( hasUnsavedBlocks && ! isCreatingNavigationMenu ) {
return (
<TagName { ...blockProps }>
Expand Down Expand Up @@ -738,7 +728,9 @@ function Navigation( {
<WrappedNavigationMenuSelector
currentMenuId={ ref }
/>
<ManageMenusButton />
<ManageMenusButton
disabled={ isManageMenusButtonDisabled }
/>
</>
) }
</PanelBody>
Expand Down Expand Up @@ -800,7 +792,9 @@ function Navigation( {
<WrappedNavigationMenuSelector
currentMenuId={ null }
/>
<ManageMenusButton />
<ManageMenusButton
disabled={ isManageMenusButtonDisabled }
/>
</>
) }
</PanelBody>
Expand Down Expand Up @@ -911,7 +905,9 @@ function Navigation( {
<WrappedNavigationMenuSelector
currentMenuId={ ref }
/>
<ManageMenusButton />
<ManageMenusButton
disabled={ isManageMenusButtonDisabled }
/>
</>
) }
</PanelBody>
Expand Down Expand Up @@ -941,7 +937,10 @@ function Navigation( {
/>
) }
{ isOffCanvasNavigationEditorEnabled && (
<ManageMenusButton className="wp-block-navigation-manage-menus-button" />
<ManageMenusButton
disabled={ isManageMenusButtonDisabled }
className="wp-block-navigation-manage-menus-button"
/>
) }
</InspectorControls>
) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';
import { Button } 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>
);

export default ManageMenusButton;