-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Use hooks instead of HoCs in 'DocumentOutline' (#59209)
Co-authored-by: Mamaduka <[email protected]> Co-authored-by: t-hamano <[email protected]>
- Loading branch information
1 parent
efe7d2e
commit 568d766
Showing
3 changed files
with
52 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
function DocumentOutlineCheck( { blocks, children } ) { | ||
const headings = blocks.filter( | ||
( block ) => block.name === 'core/heading' | ||
); | ||
export default function DocumentOutlineCheck( { children } ) { | ||
const hasHeadings = useSelect( ( select ) => { | ||
const { getGlobalBlockCount } = select( blockEditorStore ); | ||
|
||
if ( headings.length < 1 ) { | ||
return getGlobalBlockCount( 'core/heading' ) > 0; | ||
} ); | ||
|
||
if ( hasHeadings ) { | ||
return null; | ||
} | ||
|
||
return children; | ||
} | ||
|
||
export default withSelect( ( select ) => ( { | ||
blocks: select( blockEditorStore ).getBlocks(), | ||
} ) )( DocumentOutlineCheck ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
568d766
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 568d766.
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/8000518778
📝 Reported issues:
/test/e2e/specs/editor/blocks/navigation.spec.js