From b1ff735ce4f470dc06abc82304b0e545b055f250 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 9 Jan 2020 14:49:12 +0000 Subject: [PATCH] Updates to handle empty menus and selecting menus --- packages/block-library/src/navigation/edit.js | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index b354ae1d7e004b..1e2fadda32a110 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -9,6 +9,7 @@ import classnames from 'classnames'; */ import { useMemo, + useState, Fragment, } from '@wordpress/element'; import { @@ -29,7 +30,7 @@ import { Spinner, Toolbar, ToolbarGroup, - SelectControl, + SelectControl, } from '@wordpress/components'; import { compose } from '@wordpress/compose'; @@ -50,9 +51,10 @@ function Navigation( { menus, fontSize, hasExistingNavItems, + isRequestingPages, hasResolvedPages, - isRequestingPages, isRequestingMenus, + hasResolvedMenus, setAttributes, setFontSize, updateNavItemBlocks, @@ -60,6 +62,9 @@ function Navigation( { // // HOOKS // + + const [ selectedMenu, setSelectedMenu ] = useState( '' ); + /* eslint-disable @wordpress/no-unused-vars-before-return */ const { TextColor } = __experimentalUseColors( [ { name: 'textColor', property: 'color' } ], @@ -112,6 +117,7 @@ function Navigation( { } const hasPages = hasResolvedPages && pages && pages.length; + const hasMenus = hasResolvedMenus && menus && menus.length; const blockClassNames = classnames( 'wp-block-navigation', { [ `items-justification-${ attributes.itemsJustification }` ]: attributes.itemsJustification, @@ -143,21 +149,29 @@ function Navigation( { { __( 'Create from all top-level pages' ) } - { menus && menus.length && ( - - { - - } } - options={ menus.map( ( menu ) => { - return { - label: menu.name, - value: menu.slug, - }; - } ) } - /> + { hasMenus && ( + <> + { + setSelectedMenu( value ); + } } + options={ menus.map( ( menu ) => { + return { + label: menu.name, + value: menu.slug, + }; + } ) } + /> + + ) }