Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<CategorySelect> support post_tags and hierarchical = false taxonomy. #13076

Merged
merged 5 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/components/src/query-controls/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { groupBy } from 'lodash';
* @return {Array} Array of terms in tree format.
*/
export function buildTermsTree( flatTerms ) {
const termsByParent = groupBy( flatTerms, 'parent' );
const flatTermsWithParent = flatTerms.map( ( term ) => {
return {
parent: 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this fix also work if the parent was null instead of 0? This makes it clear that no parent exists in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed to use parent: null

...term,
};
} );
const termsByParent = groupBy( flatTermsWithParent, 'parent' );
const fillWithChildren = ( terms ) => {
return terms.map( ( term ) => {
const children = termsByParent[ term.id ];
Expand Down
8 changes: 7 additions & 1 deletion packages/editor/src/utils/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { groupBy } from 'lodash';
* @return {Array} Array of terms in tree format.
*/
export function buildTermsTree( flatTerms ) {
const termsByParent = groupBy( flatTerms, 'parent' );
const flatTermsWithParent = flatTerms.map( ( term ) => {
return {
parent: 0,
...term,
};
} );
const termsByParent = groupBy( flatTermsWithParent, 'parent' );
const fillWithChildren = ( terms ) => {
return terms.map( ( term ) => {
const children = termsByParent[ term.id ];
Expand Down