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
scruffian and youknowriad authored Mar 3, 2023
1 parent 0016e83 commit 666574b
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 361 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 @@ -240,6 +242,7 @@ function OffCanvasEditor(
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
shouldShowInnerBlocks={ shouldShowInnerBlocks }
showAppender={ showAppender }
/>
<TreeGridRow
level={ 1 }
Expand Down
191 changes: 0 additions & 191 deletions packages/edit-site/src/components/navigation-inspector/index.js

This file was deleted.

This file was deleted.

Loading

1 comment on commit 666574b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 666574b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4323377671
📝 Reported issues:

Please sign in to comment.