-
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 the post-taxonomies components (#…
…58446) * Editor: Use hooks instead of HoCs in the post taxonomies components * Combine filters
- Loading branch information
Showing
3 changed files
with
63 additions
and
88 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,31 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { compose } from '@wordpress/compose'; | ||
import { withSelect } from '@wordpress/data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editorStore } from '../../store'; | ||
|
||
export function PostTaxonomiesCheck( { postType, taxonomies, children } ) { | ||
const hasTaxonomies = taxonomies?.some( ( taxonomy ) => | ||
taxonomy.types.includes( postType ) | ||
); | ||
export default function PostTaxonomiesCheck( { children } ) { | ||
const hasTaxonomies = useSelect( ( select ) => { | ||
const postType = select( editorStore ).getCurrentPostType(); | ||
const taxonomies = select( coreStore ).getTaxonomies( { | ||
per_page: -1, | ||
} ); | ||
return taxonomies?.some( ( taxonomy ) => | ||
taxonomy.types.includes( postType ) | ||
); | ||
}, [] ); | ||
if ( ! hasTaxonomies ) { | ||
return null; | ||
} | ||
|
||
return children; | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => { | ||
return { | ||
postType: select( editorStore ).getCurrentPostType(), | ||
taxonomies: select( coreStore ).getTaxonomies( { per_page: -1 } ), | ||
}; | ||
} ), | ||
] )( PostTaxonomiesCheck ); |
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