RemoteFreeExtension hide bundle when all of its plugins are not visible (https://github.com/woocommerce/woocommerce-admin/pull/7182)

* Filter bundle for cases when all of its plugins are not visible

* Update changelog
This commit is contained in:
Ilyas Foo 2021-06-15 11:43:09 +08:00 committed by GitHub
parent dae2abad2d
commit 8fbda8f572
2 changed files with 57 additions and 17 deletions

View File

@ -328,6 +328,34 @@ const getVisiblePlugins = ( plugins, country, industry, productTypes ) => {
); );
}; };
/**
* Returns bundles that have at least 1 visible plugin.
*
* @param {Array} bundles list of bundles
* @param {string} country Woo store country
* @param {Array} industry List of selected industries
* @param {Array} productTypes List of selected product types
*
* @return {Array} Array of visible bundles
*/
const getVisibleBundles = ( bundles, country, industry, productTypes ) => {
return bundles
.map( ( bundle ) => {
return {
...bundle,
plugins: getVisiblePlugins(
bundle.plugins,
country,
industry,
productTypes
),
};
} )
.filter( ( bundle ) => {
return bundle.plugins.length;
} );
};
const transformRemoteExtensions = ( extensionData ) => { const transformRemoteExtensions = ( extensionData ) => {
return extensionData.map( ( section ) => { return extensionData.map( ( section ) => {
const plugins = section.plugins.map( ( plugin ) => { const plugins = section.plugins.map( ( plugin ) => {
@ -400,7 +428,14 @@ export const SelectiveExtensionsBundle = ( {
industry, industry,
productTypes productTypes
); );
setInstallableExtensions( installableExtensionsData ); setInstallableExtensions(
getVisibleBundles(
installableExtensionsData,
country,
industry,
productTypes
)
);
setValues( initialValues ); setValues( initialValues );
setIsFetching( false ); setIsFetching( false );
}; };
@ -428,7 +463,14 @@ export const SelectiveExtensionsBundle = ( {
industry, industry,
productTypes productTypes
); );
setInstallableExtensions( transformedExtensions ); setInstallableExtensions(
getVisibleBundles(
transformedExtensions,
country,
industry,
productTypes
)
);
setValues( initialValues ); setValues( initialValues );
setIsFetching( false ); setIsFetching( false );
} ) } )
@ -520,21 +562,18 @@ export const SelectiveExtensionsBundle = ( {
{ isFetching ? ( { isFetching ? (
<Spinner /> <Spinner />
) : ( ) : (
getVisiblePlugins( plugins.map(
plugins, ( { description, key } ) => (
country, <BundleExtensionCheckbox
industry, key={ key }
productTypes description={ description }
).map( ( { description, key } ) => ( isChecked={ values[ key ] }
<BundleExtensionCheckbox onChange={ getCheckboxChangeHandler(
key={ key } key
description={ description } ) }
isChecked={ values[ key ] } />
onChange={ getCheckboxChangeHandler( )
key )
) }
/>
) )
) } ) }
</div> </div>
) )

View File

@ -79,6 +79,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Add: Add unit tests around extended payment gateway controller #7133 - Add: Add unit tests around extended payment gateway controller #7133
- Fix: WCPay not working in local payments task #7151 - Fix: WCPay not working in local payments task #7151
- Fix: Include onboarding settings on the analytic pages #7109 - Fix: Include onboarding settings on the analytic pages #7109
- Fix: RemoteFreeExtension hide bundle when all of its plugins are not visible #7182
- Tweak: Revert Card component removal #7167 - Tweak: Revert Card component removal #7167
== 2.4.0 6/10/2021 == == 2.4.0 6/10/2021 ==