Convert getProductTypes method to use object param

This commit is contained in:
Chi-Hsuan Huang 2022-05-17 12:22:20 +08:00
parent c8146d6c5d
commit 657e40ed98
3 changed files with 17 additions and 6 deletions

View File

@ -49,7 +49,9 @@ export const Products = () => {
} );
const productTypeListItems = useProductTypeListItems(
getProductTypes( [ 'subscription' ] ),
getProductTypes( {
exclude: [ 'subscription' ],
} ),
[],
{
onClick: recordCompletionTime,

View File

@ -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' ] );
} );
} );

View File

@ -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.