Skip to content

Commit

Permalink
Navigation Menu Selector: Define the functions needed for the Navigat…
Browse files Browse the repository at this point in the history
…ionMenuSelector at a higher level so that they can be shared rather than declared twice (#46053)
  • Loading branch information
scruffian authored Nov 25, 2022
1 parent 643865b commit 92aa6c8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 44 deletions.
46 changes: 25 additions & 21 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,23 @@ function Navigation( {
}
};

const onSelectClassicMenu = async ( classicMenu ) => {
const navMenu = await convertClassicMenu(
classicMenu.id,
classicMenu.name,
'draft'
);
if ( navMenu ) {
handleUpdateMenu( navMenu.id, {
focusNavigationBlock: true,
} );
}
};

const onSelectNavigationMenu = ( menuId ) => {
handleUpdateMenu( menuId );
};

useEffect( () => {
hideClassicMenuConversionNotice();
if ( classicMenuConversionStatus === CLASSIC_MENU_CONVERSION_PENDING ) {
Expand Down Expand Up @@ -667,17 +684,17 @@ function Navigation( {
return (
<TagName { ...blockProps }>
<MenuInspectorControls
convertClassicMenu={ convertClassicMenu }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
}
createNavigationMenuIsError={ createNavigationMenuIsError }
currentMenuId={ ref }
handleUpdateMenu={ handleUpdateMenu }
isNavigationMenuMissing={ isNavigationMenuMissing }
innerBlocks={ innerBlocks }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
onCreateNew={ createUntitledEmptyNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
onSelectNavigationMenu={ onSelectNavigationMenu }
/>
{ stylingInspectorControls }
<ResponsiveWrapper
Expand Down Expand Up @@ -709,16 +726,16 @@ function Navigation( {
return (
<TagName { ...blockProps }>
<MenuInspectorControls
convertClassicMenu={ convertClassicMenu }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
}
createNavigationMenuIsError={ createNavigationMenuIsError }
handleUpdateMenu={ handleUpdateMenu }
isNavigationMenuMissing={ isNavigationMenuMissing }
innerBlocks={ innerBlocks }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
onCreateNew={ createUntitledEmptyNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
onSelectNavigationMenu={ onSelectNavigationMenu }
/>
<Warning>
{ __(
Expand Down Expand Up @@ -770,21 +787,8 @@ function Navigation( {
isResolvingCanUserCreateNavigationMenu={
isResolvingCanUserCreateNavigationMenu
}
onSelectNavigationMenu={ ( menuId ) => {
handleUpdateMenu( menuId );
} }
onSelectClassicMenu={ async ( classicMenu ) => {
const navMenu = await convertClassicMenu(
classicMenu.id,
classicMenu.name,
'draft'
);
if ( navMenu ) {
handleUpdateMenu( navMenu.id, {
focusNavigationBlock: true,
} );
}
} }
onSelectNavigationMenu={ onSelectNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
onCreateEmpty={ createUntitledEmptyNavigationMenu }
/>
</TagName>
Expand All @@ -795,17 +799,17 @@ function Navigation( {
<EntityProvider kind="postType" type="wp_navigation" id={ ref }>
<RecursionProvider uniqueId={ recursionId }>
<MenuInspectorControls
convertClassicMenu={ convertClassicMenu }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
}
createNavigationMenuIsError={ createNavigationMenuIsError }
currentMenuId={ ref }
handleUpdateMenu={ handleUpdateMenu }
isNavigationMenuMissing={ isNavigationMenuMissing }
innerBlocks={ innerBlocks }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
onCreateNew={ createUntitledEmptyNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
onSelectNavigationMenu={ onSelectNavigationMenu }
/>
{ stylingInspectorControls }
{ isEntityAvailable && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,16 @@ import NavigationMenuSelector from './navigation-menu-selector';

const WrappedNavigationMenuSelector = ( {
currentMenuId,
handleUpdateMenu,
convertClassicMenu,
onCreateNew,
createNavigationMenuIsSuccess,
createNavigationMenuIsError,
onSelectClassicMenu,
onSelectNavigationMenu,
} ) => (
<NavigationMenuSelector
currentMenuId={ currentMenuId }
onSelectNavigationMenu={ ( menuId ) => {
handleUpdateMenu( menuId );
} }
onSelectClassicMenu={ async ( classicMenu ) => {
const navMenu = await convertClassicMenu(
classicMenu.id,
classicMenu.name,
'draft'
);
if ( navMenu ) {
handleUpdateMenu( navMenu.id, {
focusNavigationBlock: true,
} );
}
} }
onSelectNavigationMenu={ onSelectNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
onCreateNew={ onCreateNew }
createNavigationMenuIsSuccess={ createNavigationMenuIsSuccess }
createNavigationMenuIsError={ createNavigationMenuIsError }
Expand All @@ -51,15 +38,15 @@ const WrappedNavigationMenuSelector = ( {
/>
);
const MenuInspectorControls = ( {
convertClassicMenu,
createNavigationMenuIsSuccess,
createNavigationMenuIsError,
currentMenuId = null,
handleUpdateMenu,
isNavigationMenuMissing,
innerBlocks,
isManageMenusButtonDisabled,
onCreateNew,
onSelectClassicMenu,
onSelectNavigationMenu,
} ) => {
const isOffCanvasNavigationEditorEnabled =
window?.__experimentalEnableOffCanvasNavigationEditor === true;
Expand All @@ -85,8 +72,10 @@ const MenuInspectorControls = ( {
</Heading>
<WrappedNavigationMenuSelector
currentMenuId={ currentMenuId }
handleUpdateMenu={ handleUpdateMenu }
convertClassicMenu={ convertClassicMenu }
onSelectClassicMenu={ onSelectClassicMenu }
onSelectNavigationMenu={
onSelectNavigationMenu
}
onCreateNew={ onCreateNew }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
Expand All @@ -110,8 +99,8 @@ const MenuInspectorControls = ( {
<>
<WrappedNavigationMenuSelector
currentMenuId={ currentMenuId }
handleUpdateMenu={ handleUpdateMenu }
convertClassicMenu={ convertClassicMenu }
onSelectClassicMenu={ onSelectClassicMenu }
onSelectNavigationMenu={ onSelectNavigationMenu }
onCreateNew={ onCreateNew }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
Expand Down

0 comments on commit 92aa6c8

Please sign in to comment.