diff --git a/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/utils.ts b/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/utils.ts index 15b452ff594..edb77eabb73 100644 --- a/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/utils.ts +++ b/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/utils.ts @@ -1,7 +1,6 @@ /** * External dependencies */ -import { keyBy } from 'lodash'; import { decodeEntities } from '@wordpress/html-entities'; import { Dictionary, @@ -10,6 +9,7 @@ import { ProductResponseTermItem, ProductResponseVariationsItem, } from '@woocommerce/types'; +import { keyBy } from '@woocommerce/base-utils'; /** * Internal dependencies diff --git a/assets/js/base/utils/index.js b/assets/js/base/utils/index.js index 02fb9481933..9ba997d7f02 100644 --- a/assets/js/base/utils/index.js +++ b/assets/js/base/utils/index.js @@ -12,3 +12,4 @@ export * from './create-notice'; export * from './get-navigation-type'; export * from './camel-case-keys'; export * from './debounce'; +export * from './keyby'; diff --git a/assets/js/base/utils/keyby.ts b/assets/js/base/utils/keyby.ts new file mode 100644 index 00000000000..496635e148f --- /dev/null +++ b/assets/js/base/utils/keyby.ts @@ -0,0 +1,7 @@ +export const keyBy = < T >( array: T[], key: keyof T ) => { + return array.reduce( ( acc, value ) => { + const computedKey = key ? String( value[ key ] ) : String( value ); + acc[ computedKey ] = value; + return acc; + }, {} as Record< string, T > ); +}; diff --git a/assets/js/editor-components/search-list-control/utils.tsx b/assets/js/editor-components/search-list-control/utils.tsx index 886752ceba8..7198c3b7c4b 100644 --- a/assets/js/editor-components/search-list-control/utils.tsx +++ b/assets/js/editor-components/search-list-control/utils.tsx @@ -1,9 +1,10 @@ /** * External dependencies */ -import { groupBy, keyBy } from 'lodash'; +import { groupBy } from 'lodash'; import { Fragment } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; +import { keyBy } from '@woocommerce/base-utils'; /** * Internal dependencies