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

Remove actions from SidebarNavigationScreenWrapper #48935

Merged
merged 1 commit into from
Mar 8, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { __ } from '@wordpress/i18n';
import { useCallback, useMemo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import {
BlockEditorProvider,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { BlockEditorProvider } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';

/**
Expand All @@ -17,7 +14,6 @@ import { createBlock } from '@wordpress/blocks';
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import { useHistory } from '../routes';
import NavigationMenuContent from './navigation-menu-content';
import SidebarButton from '../sidebar-button';
import { NavigationMenuLoader } from './loader';
import { unlock } from '../../private-apis';
import { store as editSiteStore } from '../../store';
Expand All @@ -43,11 +39,6 @@ function SidebarNavigationScreenWrapper( { children, actions } ) {
);
}

const prioritizedInserterBlocks = [
'core/navigation-link/page',
'core/navigation-link',
];

export default function SidebarNavigationScreenNavigationMenus() {
const history = useHistory();
const { navigationMenus, hasResolvedNavigationMenus, storedSettings } =
Expand Down Expand Up @@ -104,18 +95,6 @@ export default function SidebarNavigationScreenNavigationMenus() {
},
[ history ]
);
const orderInitialBlockItems = useCallback( ( items ) => {
items.sort( ( { id: aName }, { id: bName } ) => {
// Sort block items according to `prioritizedInserterBlocks`.
let aIndex = prioritizedInserterBlocks.indexOf( aName );
let bIndex = prioritizedInserterBlocks.indexOf( bName );
// All other block items should come after that.
if ( aIndex < 0 ) aIndex = prioritizedInserterBlocks.length;
if ( bIndex < 0 ) bIndex = prioritizedInserterBlocks.length;
return aIndex - bIndex;
} );
return items;
}, [] );

if ( hasResolvedNavigationMenus && ! hasNavigationMenus ) {
return (
Expand All @@ -132,31 +111,15 @@ export default function SidebarNavigationScreenNavigationMenus() {
</SidebarNavigationScreenWrapper>
);
}
const { PrivateInserter } = unlock( blockEditorPrivateApis );

return (
<BlockEditorProvider
settings={ storedSettings }
value={ blocks }
onChange={ noop }
onInput={ noop }
>
<SidebarNavigationScreenWrapper
actions={
<PrivateInserter
rootClientId={ blocks[ 0 ].clientId }
position="bottom right"
isAppender
selectBlockOnInsert={ false }
shouldDirectInsert={ false }
__experimentalIsQuick
toggleProps={ {
as: SidebarButton,
label: __( 'Add menu item' ),
} }
orderInitialBlockItems={ orderInitialBlockItems }
/>
}
>
<SidebarNavigationScreenWrapper>
<div className="edit-site-sidebar-navigation-screen-navigation-menus__content">
<NavigationMenuContent
rootClientId={ blocks[ 0 ].clientId }
Expand Down