Skip to content

Commit

Permalink
clean up a little
Browse files Browse the repository at this point in the history
  • Loading branch information
flootr committed Mar 6, 2023
1 parent 755a326 commit f979041
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/components/src/query-controls/terms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ const ensureParents = (
*/
export function buildTermsTree( flatTerms: readonly ( Author | Category )[] ) {
const flatTermsWithParentAndChildren: TermWithParentAndChildren[] =
flatTerms.map( ( term ) => {
return {
children: [],
parent: null,
...term,
id: String( term.id ),
};
} );
flatTerms.map( ( term ) => ( {
children: [],
parent: null,
...term,
id: String( term.id ),
} ) );

if ( ! ensureParents( flatTermsWithParentAndChildren ) ) {
return flatTermsWithParentAndChildren;
}

const termsByParent = flatTermsWithParentAndChildren.reduce(
( acc: TermsByParent, term ) => {
const parent = term.parent.toString();
const { parent } = term;
if ( ! acc[ parent ] ) {
acc[ parent ] = [];
}
Expand Down

0 comments on commit f979041

Please sign in to comment.