Skip to content

hierarchical term selector for flat taxonomies not working properly - problem with utils/terms.js #65704

@yellowmastodon

Description

@yellowmastodon

Description

If following the example in gutenberg/packages/editor/src/components/post-taxonomies/README.md to use the hierarchical term selector with a non-hierarchical taxonomy, non-hierarchical taxonomy does not render terms at all.

Problem lies in gutenberg/packages/editor/src/utils/terms.js. termsByParent is somehow not an array, but an object with one 'undefined' key.

So the return statement:
return fillWithChildren( termsByParent[ '0' ] || [] );
in function buildTermsTree() always returns empty array.

If the return statement is replaced with:
return fillWithChildren( Object.values(termsByParent)[0] || [] );
the terms function properly again.

It would be also nice if HierarchicalTermsSelector automatically removed rendering of dropdown for parent term if using non-hierarchical taxonomy. Will post a comment to the issue, if I am able to propose a solution.

Step-by-step reproduction instructions

  1. add code to theme as per instructions in gutenberg/packages/editor/src/components/post-taxonomies/README.md
  2. open any post in gutenberg editor
  3. observe that taxonomies with flat terms do not render any terms

Screenshots, screen recording, code snippet

No response

Environment info

Wordpress version: 6.6.2
Theme: custom theme in development with no other changes to the gutenberg editor so far

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Metadata

Metadata

Assignees

Labels

[Package] Editor/packages/editor[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions