Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into enhancement/4226-zero…
Browse files Browse the repository at this point in the history
…-data-states.
  • Loading branch information
eugene-manuilov committed Oct 20, 2021
2 parents b6ff9dc + 08c4e3f commit 21ae56a
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 12 deletions.
@@ -0,0 +1,55 @@
/**
* AdBlockerWarningWidget component.
*
* Site Kit by Google, Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/
import Data from 'googlesitekit-data';
import { MODULES_ADSENSE } from '../../datastore/constants';
import AdBlockerWarning from '../common/AdBlockerWarning';
import whenActive from '../../../../util/when-active';
const { useSelect } = Data;

function AdBlockerWarningWidget( { Widget } ) {
const isAdBlockerActive = useSelect( ( select ) =>
select( MODULES_ADSENSE ).isAdBlockerActive()
);

if ( ! isAdBlockerActive ) {
return null;
}

return (
<Widget noPadding>
<AdBlockerWarning />
</Widget>
);
}

AdBlockerWarningWidget.propTypes = {
Widget: PropTypes.elementType.isRequired,
};

export default whenActive( { moduleName: 'adsense' } )(
AdBlockerWarningWidget
);
@@ -0,0 +1,62 @@
/**
* AdBlockerWarningWidget Component Stories.
*
* Site Kit by Google, Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import { MODULES_ADSENSE } from '../../datastore/constants';
import { provideModules } from '../../../../../../tests/js/utils';
import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
import WithRegistrySetup from '../../../../../../tests/js/WithRegistrySetup';
import AdBlockerWarningWidget from './AdBlockerWarningWidget';

const WidgetWithComponentProps = withWidgetComponentProps( 'adBlockerWarning' )(
AdBlockerWarningWidget
);

const Template = () => <WidgetWithComponentProps />;

export const Ready = Template.bind( {} );
Ready.storyName = 'Ready';

export default {
title: 'Modules/AdSense/Widgets/AdBlockerWarning',
decorators: [
( Story ) => {
const setupRegistry = ( registry ) => {
provideModules( registry, [
{
active: true,
connected: true,
slug: 'adsense',
},
] );

registry
.dispatch( MODULES_ADSENSE )
.receiveIsAdBlockerActive( true );
};

return (
<WithRegistrySetup func={ setupRegistry }>
<Story />
</WithRegistrySetup>
);
},
],
};
1 change: 1 addition & 0 deletions assets/js/modules/adsense/components/dashboard/index.js
Expand Up @@ -20,3 +20,4 @@ export { default as DashboardAdSenseTopPages } from './DashboardAdSenseTopPages'
export { default as DashboardZeroData } from './DashboardZeroData';
export { default as DashboardSummaryWidget } from './DashboardSummaryWidget';
export { default as DashboardTopEarningPagesWidget } from './DashboardTopEarningPagesWidget';
export { default as AdBlockerWarningWidget } from './AdBlockerWarningWidget';
4 changes: 2 additions & 2 deletions assets/js/modules/adsense/datastore/adblocker.js
Expand Up @@ -171,13 +171,13 @@ export const selectors = {

if ( isModuleConnected ) {
return __(
'Ad blocker detected, you need to disable it to get the latest AdSense data.',
'Ad blocker detected; please disable it to get the latest AdSense data',
'google-site-kit'
);
}

return __(
'Ad blocker detected, you need to disable it to set up AdSense.',
'Ad blocker detected; please disable it to set up AdSense',
'google-site-kit'
);
}
Expand Down
18 changes: 17 additions & 1 deletion assets/js/modules/adsense/index.js
Expand Up @@ -38,6 +38,7 @@ import {
import {
DashboardSummaryWidget,
DashboardTopEarningPagesWidget,
AdBlockerWarningWidget,
} from './components/dashboard';
import ModuleTopEarningPagesWidget from './components/module/ModuleTopEarningPagesWidget';
import { ModuleOverviewWidget } from './components/module';
Expand Down Expand Up @@ -102,6 +103,21 @@ export const registerModule = ( modules ) => {
};

export const registerWidgets = ( widgets ) => {
widgets.registerWidget(
'adBlockerWarning',
{
Component: AdBlockerWarningWidget,
width: widgets.WIDGET_WIDTHS.FULL,
priority: 1,
wrapWidget: false,
},
[
isFeatureEnabled( 'unifiedDashboard' )
? AREA_MAIN_DASHBOARD_MONETIZATION_PRIMARY
: AREA_MODULE_ADSENSE_MAIN,
]
);

if ( ! isFeatureEnabled( 'unifiedDashboard' ) ) {
widgets.registerWidget(
'adsenseSummary',
Expand Down Expand Up @@ -134,7 +150,7 @@ export const registerWidgets = ( widgets ) => {
{
Component: ModuleOverviewWidget,
width: widgets.WIDGET_WIDTHS.FULL,
priority: 1,
priority: 2,
wrapWidget: false,
},
[
Expand Down
Expand Up @@ -37,6 +37,7 @@ import {
MODULES_ANALYTICS,
} from '../../../datastore/constants';
import { numFmt } from '../../../../../util';
import whenActive from '../../../../../util/when-active';
import { generateDateRangeArgs } from '../../../util/report-date-range-args';
import { isZeroReport } from '../../../util';
import TableOverflowContainer from '../../../../../components/TableOverflowContainer';
Expand All @@ -48,7 +49,7 @@ import Header from './Header';
import Footer from './Footer';
const { useSelect } = Data;

export default function ModulePopularPagesWidget( props ) {
function ModulePopularPagesWidget( props ) {
const { Widget, WidgetReportError, WidgetReportZero } = props;

const isGatheringData = useSelect( ( select ) =>
Expand Down Expand Up @@ -218,3 +219,7 @@ ModulePopularPagesWidget.propTypes = {
WidgetReportError: PropTypes.elementType.isRequired,
WidgetReportZero: PropTypes.elementType.isRequired,
};

export default whenActive( { moduleName: 'analytics' } )(
ModulePopularPagesWidget
);
1 change: 1 addition & 0 deletions assets/sass/admin.scss
Expand Up @@ -164,6 +164,7 @@
@import "widgets/widgets";
@import "widgets/googlesitekit-widget-adsense-performance";
@import "widgets/googlesitekit-widget-analyticsAllTraffic";
@import "widgets/googlesitekit-widget-adBlockerWarning";

// Utilities
@import "utilities/alignment";
Expand Down
25 changes: 25 additions & 0 deletions assets/sass/widgets/_googlesitekit-widget-adBlockerWarning.scss
@@ -0,0 +1,25 @@
/**
* AdSense AdBlocker Warning widget styles.
*
* Site Kit by Google, Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

.googlesitekit-plugin {

.googlesitekit-widget--adBlockerWarning {
background-color: transparent;
box-shadow: none;
}
}
25 changes: 17 additions & 8 deletions includes/Core/Authentication/Authentication.php
Expand Up @@ -1077,20 +1077,29 @@ private function get_authentication_oauth_error_notice() {
return '';
}

$message = $auth_client->get_error_message( $error_code );
$access_code = $this->user_options->get( OAuth_Client::OPTION_PROXY_ACCESS_CODE );
if ( $this->credentials->using_proxy() ) {
$message = $auth_client->get_error_message( $error_code );

if ( $this->is_authenticated() ) {
$setup_url = $this->get_connect_url();
} elseif ( $this->credentials->using_proxy() ) {
$access_code = $this->user_options->get( OAuth_Client::OPTION_PROXY_ACCESS_CODE );
$setup_url = $auth_client->get_proxy_setup_url( $access_code );
$this->user_options->delete( OAuth_Client::OPTION_PROXY_ACCESS_CODE );
} else {
$setup_url = $this->context->admin_url( 'splash' );
}

if ( 'access_denied' === $error_code ) {
$message .= ' ' . sprintf(
/* translators: %s: URL to re-authenticate */
__( 'To fix this, <a href="%s">redo the plugin setup</a>.', 'google-site-kit' ),
esc_url( $auth_client->get_proxy_setup_url( $access_code ) )
/* translators: %s: setup screen URL */
__( 'To use Site Kit, you’ll need to <a href="%s">redo the plugin setup</a> – make sure to approve all permissions at the authentication stage.', 'google-site-kit' ),
esc_url( $setup_url )
);
$this->user_options->delete( OAuth_Client::OPTION_PROXY_ACCESS_CODE );
} else {
$message .= ' ' . sprintf(
/* translators: %s: setup screen URL */
__( 'To fix this, <a href="%s">redo the plugin setup</a>.', 'google-site-kit' ),
esc_url( $this->context->admin_url( 'splash' ) )
esc_url( $setup_url )
);
}

Expand Down

0 comments on commit 21ae56a

Please sign in to comment.