Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Mar 4, 2020
1 parent e69f2ab commit 451d9f6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
52 changes: 46 additions & 6 deletions packages/block-library/src/navigation/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useMemo, Fragment, useRef } from '@wordpress/element';
import { useMemo, useState, Fragment, useRef } from '@wordpress/element';
import {
InnerBlocks,
InspectorControls,
Expand All @@ -27,6 +27,7 @@ import {
ToggleControl,
Toolbar,
ToolbarGroup,
SelectControl,
} from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
Expand All @@ -47,7 +48,10 @@ function Navigation( {
hasExistingNavItems,
hasResolvedPages,
isRequestingPages,
hasResolvedMenus,
isRequestingMenus,
pages,
menus,
setAttributes,
setFontSize,
updateNavItemBlocks,
Expand All @@ -58,6 +62,7 @@ function Navigation( {
//
/* eslint-disable @wordpress/no-unused-vars-before-return */
const ref = useRef();
const [ selectedMenu, setSelectedMenu ] = useState( '' );
const { selectBlock } = useDispatch( 'core/block-editor' );

const {
Expand Down Expand Up @@ -134,6 +139,7 @@ function Navigation( {
}

const hasPages = hasResolvedPages && pages && pages.length;
const hasMenus = hasResolvedMenus && menus && menus.length;

const blockClassNames = classnames( className, {
[ `items-justification-${ attributes.itemsJustification }` ]: attributes.itemsJustification,
Expand Down Expand Up @@ -170,6 +176,31 @@ function Navigation( {
{ __( 'Create from all top-level pages' ) }
</Button>

{ hasMenus && (
<>
<SelectControl
label={ __( 'Create from existing Menu' ) }
value={ selectedMenu }
onChange={ ( value ) => {
setSelectedMenu( value );
} }
options={ menus.map( ( mappedMenu ) => {
return {
label: mappedMenu.name,
value: mappedMenu.slug,
};
} ) }
/>
<Button
isSecondary
className="wp-block-navigation-placeholder__button"
onClick={ () => {} }
>
{ __( 'Create from Menu' ) }
</Button>
</>
) }

<Button
isLink
className="wp-block-navigation-placeholder__button"
Expand Down Expand Up @@ -261,11 +292,12 @@ function Navigation( {
className={ blockClassNames }
style={ blockInlineStyles }
>
{ ! hasExistingNavItems && isRequestingPages && (
<>
<Spinner /> { __( 'Loading Navigation…' ) }{ ' ' }
</>
) }
{ ! hasExistingNavItems &&
( isRequestingPages || isRequestingMenus ) && (
<>
<Spinner /> { __( 'Loading Navigation…' ) }{ ' ' }
</>
) }

<InnerBlocks
allowedBlocks={ [ 'core/navigation-link' ] }
Expand Down Expand Up @@ -295,6 +327,7 @@ export default compose( [
'getEntityRecords',
[ 'postType', 'page', filterDefaultPages ],
];
const menusSelect = [ 'core', 'getEntityRecords', [ 'root', 'menu' ] ];

return {
hasExistingNavItems: !! innerBlocks.length,
Expand All @@ -303,12 +336,19 @@ export default compose( [
'page',
filterDefaultPages
),
menus: select( 'core' ).getEntityRecords( 'root', 'menu' ),
isRequestingPages: select( 'core/data' ).isResolving(
...pagesSelect
),
isRequestingMenus: select( 'core/data' ).isResolving(
...menusSelect
),
hasResolvedPages: select( 'core/data' ).hasFinishedResolution(
...pagesSelect
),
hasResolvedMenus: select( 'core/data' ).hasFinishedResolution(
...menusSelect
),
};
} ),
withDispatch( ( dispatch, { clientId } ) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export const defaultEntities = [
transientEdits: { blocks: true },
},
{ name: 'user', kind: 'root', baseURL: '/wp/v2/users', plural: 'users' },
{ name: 'menu', kind: 'root', baseURL: '/wp/v2/menus', plural: 'menus' },
{
name: 'menu-item',
kind: 'root',
baseURL: '/wp/v2/menu-items',
plural: 'menu-items',
},
];

export const kinds = [
Expand Down

0 comments on commit 451d9f6

Please sign in to comment.