Skip to content

Commit b6e7c8f

Browse files
authored
Merge pull request #11184 from google/9300-adsense-followup
Fix issue with AdSense notifications delivered from API.
2 parents 75b32ec + d83c6d5 commit b6e7c8f

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

assets/js/components/NotificationFromServer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import Link from './Link';
4747
* @param {Object} props Component props.
4848
* @param {string} props.id Notification ID/slug.
4949
* @param {string} props.title Notification title/heading.
50-
* @param {?ReactNode} props.content Decsription for notification.
50+
* @param {?ReactNode} props.content Description for notification.
5151
* @param {string} props.ctaLabel Label for the call-to-action button.
5252
* @param {?string} props.ctaTarget `target` for the call-to-action link, e.g. `_blank`. Optional.
5353
* @param {?string} props.ctaURL URL for the call-to-action link.
@@ -79,9 +79,11 @@ function NotificationFromServer( {
7979
description={
8080
<Description
8181
learnMoreLink={
82-
<Link href={ learnMoreURL } external>
83-
{ learnMoreLabel }
84-
</Link>
82+
!! learnMoreURL && !! learnMoreLabel ? (
83+
<Link href={ learnMoreURL } external>
84+
{ learnMoreLabel }
85+
</Link>
86+
) : undefined
8587
}
8688
text={ content }
8789
/>

assets/js/hooks/useAdSenseNotifications.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* WordPress dependencies
2121
*/
2222
import { useEffect, useState } from '@wordpress/element';
23+
import { __ } from '@wordpress/i18n';
2324

2425
/**
2526
* Internal dependencies
@@ -65,9 +66,33 @@ export default function useAdSenseNotifications() {
6566
return;
6667
}
6768

69+
/**
70+
* Adjust the notification props to match the expected
71+
* `NotificationFromServer` component props, which vary
72+
* slightly from the attributes returned from the REST API.
73+
*/
74+
const notificationProps = { ...notification };
75+
76+
// Some notifications do not include a `title` property, so supply
77+
// a default.
78+
if ( ! notificationProps.title ) {
79+
notificationProps.title = __(
80+
'Notice about your AdSense account',
81+
'google-site-kit'
82+
);
83+
}
84+
85+
if (
86+
! notificationProps.content?.length &&
87+
!! notificationProps.description?.length
88+
) {
89+
notificationProps.content = notificationProps.description;
90+
delete notificationProps.description;
91+
}
92+
6893
registerNotification( notification.id, {
6994
Component() {
70-
return <NotificationFromServer { ...notification } />;
95+
return <NotificationFromServer { ...notificationProps } />;
7196
},
7297
priority: notification.priority,
7398
areaSlug: NOTIFICATION_AREAS.HEADER,

0 commit comments

Comments
 (0)