Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Top Earning Pages widget for view-only mode. #5884

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const { useSelect, useInViewSelect } = Data;
function DashboardTopEarningPagesWidget( props ) {
const { Widget, WidgetReportError, WidgetNull } = props;

const isViewOnly = useViewOnly();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Props for spotting the duplicate assignment of the hook.


const viewOnlyDashboard = useViewOnly();

const isGatheringData = useInViewSelect( ( select ) =>
Expand Down Expand Up @@ -108,9 +106,12 @@ function DashboardTopEarningPagesWidget( props ) {
] )
);

const isAdSenseLinked = useSelect( ( select ) =>
select( MODULES_ANALYTICS ).getAdsenseLinked()
);
const isAdSenseLinked = useSelect( ( select ) => {
if ( viewOnlyDashboard && loading ) {
return undefined;
}
return select( MODULES_ANALYTICS ).getAdsenseLinked();
} );

const isAdblockerActive = useSelect( ( select ) =>
select( MODULES_ADSENSE ).isAdBlockerActive()
Expand Down Expand Up @@ -153,13 +154,13 @@ function DashboardTopEarningPagesWidget( props ) {
);
}

if ( ! isAdSenseLinked && isViewOnly ) {
if ( ! isAdSenseLinked && viewOnlyDashboard ) {
return <WidgetNull />;
}

// A restricted metrics error will cause this value to change in the resolver
// so this check should happen before an error, which is only relevant if they are linked.
if ( ! isAdSenseLinked && ! isViewOnly ) {
if ( ! isAdSenseLinked && ! viewOnlyDashboard ) {
return (
<Widget Footer={ Footer }>
<AdSenseLinkCTA />
Expand Down