Skip to content

Commit

Permalink
Editor: Combine selectors in the 'Header' component (#68697)
Browse files Browse the repository at this point in the history
* Editor: Combine selectors in the 'Header' component
* Combine selectors in the 'InserterMenu' component

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
  • Loading branch information
Mamaduka and Mamaduka authored Jan 16, 2025
1 parent 74986ed commit 9f7d7dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
20 changes: 11 additions & 9 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ function InserterMenu(
},
ref
) {
const isZoomOutMode = useSelect(
( select ) => unlock( select( blockEditorStore ) ).isZoomOut(),
[]
);
const hasSectionRootClientId = useSelect(
( select ) =>
!! unlock( select( blockEditorStore ) ).getSectionRootClientId(),
[]
);
const { isZoomOutMode, hasSectionRootClientId } = useSelect( ( select ) => {
const { isZoomOut, getSectionRootClientId } = unlock(
select( blockEditorStore )
);

return {
isZoomOutMode: isZoomOut(),
hasSectionRootClientId: !! getSectionRootClientId(),
};
}, [] );

const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
const [ hoveredItem, setHoveredItem ] = useState( null );
Expand Down
28 changes: 12 additions & 16 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,32 @@ function Header( {
showIconLabels,
hasFixedToolbar,
hasBlockSelection,
hasSectionRootClientId,
} = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );
const {
getEditorMode,
getCurrentPostType,
isPublishSidebarOpened: _isPublishSidebarOpened,
} = select( editorStore );
const { getBlockSelectionStart, getSectionRootClientId } = unlock(
select( blockEditorStore )
);

return {
postType: getCurrentPostType(),
isTextEditor: getEditorMode() === 'text',
isPublishSidebarOpened: _isPublishSidebarOpened(),
showIconLabels: getPreference( 'core', 'showIconLabels' ),
hasFixedToolbar: getPreference( 'core', 'fixedToolbar' ),
hasBlockSelection:
!! select( blockEditorStore ).getBlockSelectionStart(),
hasBlockSelection: !! getBlockSelectionStart(),
hasSectionRootClientId: !! getSectionRootClientId(),
};
}, [] );

const canBeZoomedOut = [ 'post', 'page', 'wp_template' ].includes(
postType
);
const canBeZoomedOut =
[ 'post', 'page', 'wp_template' ].includes( postType ) &&
hasSectionRootClientId;

const disablePreviewOption = [
NAVIGATION_POST_TYPE,
Expand All @@ -107,12 +111,6 @@ function Header( {
( ! hasBlockSelection || isBlockToolsCollapsed ) ) );
const hasBackButton = useHasBackButton();

const hasSectionRootClientId = useSelect(
( select ) =>
!! unlock( select( blockEditorStore ) ).getSectionRootClientId(),
[]
);

/*
* The edit-post-header classname is only kept for backward compatibility
* as some plugins might be relying on its presence.
Expand Down Expand Up @@ -180,11 +178,9 @@ function Header( {
forceIsAutosaveable={ forceIsDirty }
/>

{ canBeZoomedOut &&
isWideViewport &&
hasSectionRootClientId && (
<ZoomOutToggle disabled={ forceDisableBlockTools } />
) }
{ isWideViewport && canBeZoomedOut && (
<ZoomOutToggle disabled={ forceDisableBlockTools } />
) }

{ ( isWideViewport || ! showIconLabels ) && (
<PinnedItems.Slot scope="core" />
Expand Down

0 comments on commit 9f7d7dc

Please sign in to comment.