Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Replace groupBy usage in search list control
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Apr 21, 2023
1 parent 549826b commit 16c8bbd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions assets/js/editor-components/search-list-control/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { groupBy } from 'lodash';
import { Fragment } from '@wordpress/element';
import { __, _n, sprintf } from '@wordpress/i18n';
import { keyBy } from '@woocommerce/base-utils';
Expand Down Expand Up @@ -43,7 +42,17 @@ export const buildTermsTree = (
filteredList: SearchListItem[],
list = filteredList
): SearchListItem[] | [] => {
const termsByParent = groupBy( filteredList, 'parent' );
const termsByParent = filteredList.reduce( ( acc, currentValue ) => {
const key = currentValue.parent || 0;

if ( ! acc[ key ] ) {
acc[ key ] = [];
}

acc[ key ].push( currentValue );
return acc;
}, {} as Record< string, SearchListItem[] > );

const listById = keyBy( list, 'id' );
const builtParents = [ '0' ];

Expand Down

0 comments on commit 16c8bbd

Please sign in to comment.