Fix promotions filtering by tab (#44884)
* Fixing filtering by tabs in `Promotions` component. Using reference to WC_Admin_Marketplace_Promotions::TRANSIENT_NAME when outputting JS data for promotions, instead of transient string. Better initialisation of wc global object in the inline script. * Changelog. * Using global var for marketplace. * More tentative reference to global object. * icon TS error
This commit is contained in:
parent
0a3c285b08
commit
24a216f887
|
@ -6,10 +6,8 @@ import Notice from '../notice/notice';
|
|||
|
||||
declare global {
|
||||
interface Window {
|
||||
wc: {
|
||||
marketplace?: {
|
||||
promotions: Promotion[];
|
||||
};
|
||||
wcMarketplace?: {
|
||||
promotions?: Promotion[];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +19,7 @@ type Promotion = {
|
|||
pages: Page[];
|
||||
position: string;
|
||||
content: { [ locale: string ]: string };
|
||||
icon?: string | undefined;
|
||||
icon?: string;
|
||||
is_dismissible?: boolean;
|
||||
menu_item_id?: string;
|
||||
style?: string;
|
||||
|
@ -41,7 +39,7 @@ const Promotions: () => null | JSX.Element = () => {
|
|||
if ( currentPage !== 'wc-admin' ) {
|
||||
return null;
|
||||
}
|
||||
const promotions = window.wc?.marketplace?.promotions ?? [];
|
||||
const promotions = window?.wcMarketplace?.promotions ?? [];
|
||||
const currentDateUTC = Date.now();
|
||||
const currentPath = decodeURIComponent( urlParams.get( 'path' ) || '' );
|
||||
const currentTab = urlParams.get( 'tab' );
|
||||
|
@ -65,11 +63,12 @@ const Promotions: () => null | JSX.Element = () => {
|
|||
)
|
||||
? currentPath
|
||||
: `/${ currentPath }`;
|
||||
return (
|
||||
page.page === currentPage &&
|
||||
|
||||
return page.page === currentPage &&
|
||||
normalizedPath === normalizedCurrentPath &&
|
||||
( page.tab ? page.tab === currentTab : true )
|
||||
);
|
||||
page.tab
|
||||
? page.tab === currentTab
|
||||
: ! currentTab;
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -104,7 +103,7 @@ const Promotions: () => null | JSX.Element = () => {
|
|||
variant={
|
||||
promotion.style ? promotion.style : 'info'
|
||||
}
|
||||
icon={ promotion?.icon }
|
||||
icon={ promotion?.icon || '' }
|
||||
isDismissible={ promotion.is_dismissible || false }
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
|
||||
Fix condition in Promotions component so marketplace promotions are properly filtered by page.
|
|
@ -558,7 +558,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
|
|||
// Marketplace promotions.
|
||||
if ( in_array( $screen_id, array( 'woocommerce_page_wc-admin' ), true ) ) {
|
||||
|
||||
$promotions = get_transient( 'woocommerce_marketplace_promotions' );
|
||||
$promotions = get_transient( WC_Admin_Marketplace_Promotions::TRANSIENT_NAME );
|
||||
|
||||
if ( false === $promotions ) {
|
||||
return;
|
||||
|
@ -566,7 +566,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
|
|||
|
||||
wp_add_inline_script(
|
||||
'wc-admin-app',
|
||||
'window.wc = window.wc || {}; wc.marketplace = ' . wp_json_encode( array( 'promotions' => $promotions ) ),
|
||||
'window.wcMarketplace = ' . wp_json_encode( array( 'promotions' => $promotions ) ),
|
||||
'before'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue