Skip to content

Commit

Permalink
Navigation Sidebar: Change the logic about which navigation gets sele…
Browse files Browse the repository at this point in the history
…cted for the sidebar (#48689)

* Navigation Sidebar: Change the logic about which navigation gets selected for the sidebar

* Move the navigation sidebar appender into the actions area of the sidebar

* Further simplification

* Fixed allowed blocks and update appender label

* Fix inserter issue

* Delay the rendering of the navigation menus

* Remove useless code

* update comment

---------

Co-authored-by: Riad Benguella <benguella@gmail.com>
  • Loading branch information
2 people authored and ntsekouras committed Mar 7, 2023
1 parent d99c758 commit c4fdeb1
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 378 deletions.
19 changes: 12 additions & 7 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,26 @@ const defaultRenderToggle = ( {
toggleProps = {},
prioritizePatterns,
} ) => {
let label;
if ( hasSingleBlockType ) {
const {
as: Wrapper = Button,
label: labelProp,
onClick,
...rest
} = toggleProps;

let label = labelProp;
if ( ! label && hasSingleBlockType ) {
label = sprintf(
// translators: %s: the name of the block when there is only one
_x( 'Add %s', 'directly add the only allowed block' ),
blockTitle
);
} else if ( prioritizePatterns ) {
} else if ( ! label && prioritizePatterns ) {
label = __( 'Add pattern' );
} else {
} else if ( ! label ) {
label = _x( 'Add block', 'Generic label for block inserter button' );
}

const { onClick, ...rest } = toggleProps;

// Handle both onClick functions from the toggle and the parent component.
function handleClick( event ) {
if ( onToggle ) {
Expand All @@ -57,7 +62,7 @@ const defaultRenderToggle = ( {
}

return (
<Button
<Wrapper
icon={ plus }
label={ label }
tooltipPosition="bottom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function ListViewBranch( props ) {
isExpanded,
parentId,
shouldShowInnerBlocks = true,
showAppender: showAppenderProp = true,
} = props;

const isContentLocked = useSelect(
Expand All @@ -117,7 +118,7 @@ function ListViewBranch( props ) {
}

// Only show the appender at the first level.
const showAppender = level === 1;
const showAppender = showAppenderProp && level === 1;

const filteredBlocks = blocks.filter( Boolean );
const blockCount = filteredBlocks.length;
Expand Down Expand Up @@ -205,6 +206,7 @@ function ListViewBranch( props ) {
isBranchSelected={ isSelectedBranch }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
showAppender={ showAppenderProp }
/>
) }
</AsyncModeProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36;
* @param {Object} props.LeafMoreMenu Optional more menu substitution.
* @param {string} props.description Optional accessible description for the tree grid component.
* @param {string} props.onSelect Optional callback to be invoked when a block is selected.
* @param {string} props.showAppender Flag to show or hide the block appender.
* @param {Object} ref Forwarded ref
*/
function OffCanvasEditor(
Expand All @@ -70,6 +71,7 @@ function OffCanvasEditor(
blocks,
showBlockMovers = false,
isExpanded = false,
showAppender = true,
LeafMoreMenu,
description = __( 'Block navigation structure' ),
onSelect,
Expand Down Expand Up @@ -234,6 +236,7 @@ function OffCanvasEditor(
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
shouldShowInnerBlocks={ shouldShowInnerBlocks }
showAppender={ showAppender }
/>
<TreeGridRow
level={ 1 }
Expand Down
223 changes: 0 additions & 223 deletions packages/edit-site/src/components/navigation-inspector/index.js

This file was deleted.

This file was deleted.

Loading

0 comments on commit c4fdeb1

Please sign in to comment.