From 16c8bbd0943ceed43d3c1ed52e81bbc4f5564008 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 21 Apr 2023 13:38:31 +0100 Subject: [PATCH] Replace groupBy usage in search list control --- .../editor-components/search-list-control/utils.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/assets/js/editor-components/search-list-control/utils.tsx b/assets/js/editor-components/search-list-control/utils.tsx index 7198c3b7c4b..5c12cca0999 100644 --- a/assets/js/editor-components/search-list-control/utils.tsx +++ b/assets/js/editor-components/search-list-control/utils.tsx @@ -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'; @@ -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' ];