Update `snackbarNotices` filter to `snackbarNoticeVisibility` (https://github.com/woocommerce/woocommerce-blocks/pull/4417)

* Change snackbarNotices filter to snackbarNoticeVisibility

* Add deprecation notice to snackbarNotices

* Rename noticesToDisplay to visibleNotices

* Update link in deprecated message
This commit is contained in:
Thomas Roberts 2021-07-26 09:13:54 +01:00 committed by GitHub
parent 45bbe80259
commit fb846c5b78
2 changed files with 26 additions and 3 deletions

View File

@ -19,11 +19,20 @@ const SnackbarNoticesContainer = ( {
( notice ) => notice.type === 'snackbar'
);
const noticeVisibility = snackbarNotices.reduce( ( acc, { content } ) => {
acc[ content ] = true;
return acc;
}, {} );
const filteredNotices = __experimentalApplyCheckoutFilter( {
filterName: 'snackbarNotices',
defaultValue: snackbarNotices,
filterName: 'snackbarNoticeVisibility',
defaultValue: noticeVisibility,
} );
const visibleNotices = snackbarNotices.filter(
( notice ) => filteredNotices[ notice.content ] === true
);
const wrapperClass = classnames(
className,
'wc-block-components-notices__snackbar'
@ -31,7 +40,7 @@ const SnackbarNoticesContainer = ( {
return (
<SnackbarList
notices={ filteredNotices }
notices={ visibleNotices }
className={ wrapperClass }
onRemove={ removeNotice }
/>

View File

@ -35,6 +35,20 @@ export const __experimentalRegisterCheckoutFilters = (
namespace: string,
filters: Record< string, CheckoutFilterFunction >
): void => {
/**
* Let developers know snackbarNotices is no longer available as a filter.
*
* See: https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4417
*/
if ( Object.keys( filters ).includes( 'couponName' ) ) {
deprecated( 'snackbarNotices', {
alternative: 'snackbarNoticeVisibility',
plugin: 'WooCommerce Blocks',
link:
'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4417',
} );
}
/**
* Let the user know couponName is no longer available as a filter.
*