Convert getProductTypes method to use object param
This commit is contained in:
parent
c8146d6c5d
commit
657e40ed98
|
@ -49,7 +49,9 @@ export const Products = () => {
|
|||
} );
|
||||
|
||||
const productTypeListItems = useProductTypeListItems(
|
||||
getProductTypes( [ 'subscription' ] ),
|
||||
getProductTypes( {
|
||||
exclude: [ 'subscription' ],
|
||||
} ),
|
||||
[],
|
||||
{
|
||||
onClick: recordCompletionTime,
|
||||
|
|
|
@ -11,7 +11,9 @@ describe( 'getProductTypes', () => {
|
|||
|
||||
it( 'should return the product types without excluded items', () => {
|
||||
expect(
|
||||
getProductTypes( [ 'external', 'digital' ] ).map( ( p ) => p.key )
|
||||
getProductTypes( { exclude: [ 'external', 'digital' ] } ).map(
|
||||
( p ) => p.key
|
||||
)
|
||||
).toEqual( [ 'physical', 'variable', 'subscription', 'grouped' ] );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -15,12 +15,19 @@ import {
|
|||
defaultSurfacedProductTypes,
|
||||
} from './constants';
|
||||
|
||||
export const getProductTypes = (
|
||||
exclude: ProductTypeKey[] = []
|
||||
): ProductType[] =>
|
||||
productTypes.filter(
|
||||
export const getProductTypes = ( {
|
||||
exclude,
|
||||
}: {
|
||||
exclude?: ProductTypeKey[];
|
||||
} = {} ): ProductType[] => {
|
||||
if ( ! exclude ) {
|
||||
return [ ...productTypes ];
|
||||
}
|
||||
|
||||
return productTypes.filter(
|
||||
( productType ) => ! exclude.includes( productType.key )
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get key of surfaced product types by onboarding product types.
|
||||
|
|
Loading…
Reference in New Issue