Skip to content

Commit

Permalink
Navigation: Add a new ManageMenusButton component (#45782)
Browse files Browse the repository at this point in the history
* Navigation: Add a new ManageMenusButton component

* add missing file

* refactor the disabled state to a variable

* remove memo
  • Loading branch information
scruffian authored Nov 15, 2022
1 parent 2baf211 commit 370c7c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
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
21 changes: 21 additions & 0 deletions packages/block-library/src/navigation/edit/manage-menus-button.js
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;

0 comments on commit 370c7c0

Please sign in to comment.