Skip to content

Commit

Permalink
Editor: Don't use selector shortcuts for the taxonomy queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 2, 2025
1 parent c9b2569 commit 726e0b3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import { store as editorStore } from '../../store';
function MaybeCategoryPanel() {
const hasNoCategory = useSelect( ( select ) => {
const postType = select( editorStore ).getCurrentPostType();
const { canUser, getEntityRecord, getTaxonomy } = select( coreStore );
const categoriesTaxonomy = getTaxonomy( 'category' );
const { canUser, getEntityRecord } = select( coreStore );
const categoriesTaxonomy = getEntityRecord(
'root',
'taxonomy',
'category'
);
const defaultCategoryId = canUser( 'read', {
kind: 'root',
name: 'site',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ const TagsPanel = () => {
const MaybeTagsPanel = () => {
const { hasTags, isPostTypeSupported } = useSelect( ( select ) => {
const postType = select( editorStore ).getCurrentPostType();
const tagsTaxonomy = select( coreStore ).getTaxonomy( 'post_tag' );
const tagsTaxonomy = select( coreStore ).getEntityRecord(
'root',
'taxonomy',
'post_tag'
);
const _isPostTypeSupported = tagsTaxonomy?.types?.includes( postType );
const areTagsFetched = tagsTaxonomy !== undefined;
const tags =
Expand Down
8 changes: 5 additions & 3 deletions packages/editor/src/components/post-taxonomies/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import { store as editorStore } from '../../store';
export default function PostTaxonomiesCheck( { children } ) {
const hasTaxonomies = useSelect( ( select ) => {
const postType = select( editorStore ).getCurrentPostType();
const taxonomies = select( coreStore ).getTaxonomies( {
per_page: -1,
} );
const taxonomies = select( coreStore ).getEntityRecords(
'root',
'taxonomy',
{ per_page: -1 }
);
return taxonomies?.some( ( taxonomy ) =>
taxonomy.types.includes( postType )
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ export function FlatTermSelector( { slug, __nextHasNoMarginBottom } ) {
( select ) => {
const { getCurrentPost, getEditedPostAttribute } =
select( editorStore );
const { getEntityRecords, getTaxonomy, hasFinishedResolution } =
const { getEntityRecords, getEntityRecord, hasFinishedResolution } =
select( coreStore );
const post = getCurrentPost();
const _taxonomy = getTaxonomy( slug );
const _taxonomy = getEntityRecord( 'root', 'taxonomy', slug );
const _termIds = _taxonomy
? getEditedPostAttribute( _taxonomy.rest_base )
: EMPTY_ARRAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ export function HierarchicalTermSelector( { slug } ) {
( select ) => {
const { getCurrentPost, getEditedPostAttribute } =
select( editorStore );
const { getTaxonomy, getEntityRecords, isResolving } =
const { getEntityRecord, getEntityRecords, isResolving } =
select( coreStore );
const _taxonomy = getTaxonomy( slug );
const _taxonomy = getEntityRecord( 'root', 'taxonomy', slug );
const post = getCurrentPost();

return {
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/src/components/post-taxonomies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export function PostTaxonomies( { taxonomyWrapper = identity } ) {
const { postType, taxonomies } = useSelect( ( select ) => {
return {
postType: select( editorStore ).getCurrentPostType(),
taxonomies: select( coreStore ).getTaxonomies( { per_page: -1 } ),
taxonomies: select( coreStore ).getEntityRecords(
'root',
'taxonomy',
{ per_page: -1 }
),
};
}, [] );
const visibleTaxonomies = ( taxonomies ?? [] ).filter(
Expand Down

0 comments on commit 726e0b3

Please sign in to comment.