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

KMW / 7465 Implement Insufficient Permissions Error CTA on KMW Tiles #7554

Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4700ca0
Merge branch 'develop' of github.com:google/site-kit-wp into develop
10upsimon Sep 5, 2023
9345d54
Merge remote-tracking branch 'origin/develop' into kmw/7465-implement…
10upsimon Sep 6, 2023
3efcd18
Update <MetricTileError> component error to conditionally show and pa…
10upsimon Sep 6, 2023
d28a0a4
Define getHelpText prop and type, conditionally show getHelpText base…
10upsimon Sep 6, 2023
f94a0b9
Update KMW error tile styles to accommodate anchor tag based buttons …
10upsimon Sep 6, 2023
384bfc8
Add InsufficientPermissions scenario to EngagedTrafficSourcesWidget s…
10upsimon Sep 6, 2023
72f777d
Amend InsufficientPermissions label to have correct reference.
10upsimon Sep 6, 2023
7084746
Add InsufficientPermissions scenario to LoyalVisitorsWidget story.
10upsimon Sep 6, 2023
3dff530
Add InsufficientPermissions scenario to NewVisitorsWidget story.
10upsimon Sep 6, 2023
4d2a6df
Add InsufficientPermissions scenario to PopularContentWidget story.
10upsimon Sep 6, 2023
db6d180
Add InsufficientPermissions scenario to PopularProductsWidget story.
10upsimon Sep 6, 2023
cfbf2b0
Add InsufficientPermissions scenario to TopCitiesWidget story.
10upsimon Sep 6, 2023
59ae3fb
Add InsufficientPermissions scenario to TopConvertingTrafficSource st…
10upsimon Sep 6, 2023
c776a9e
Add InsufficientPermissions scenario to TopCountrisWidget story.
10upsimon Sep 6, 2023
8d98665
Add InsufficientPermissions scenario to TopTrafficSourceWidget story.
10upsimon Sep 6, 2023
bac3de1
Add InsufficientPermissions scenario to PopularKeywordsWidget story.
10upsimon Sep 6, 2023
7ee429c
Update VRT references following addition of insufficient permission s…
10upsimon Sep 6, 2023
3d250d6
Update assets/js/components/KeyMetrics/MetricTileError.js
10upsimon Sep 7, 2023
72969c5
Update assets/js/components/KeyMetrics/MetricTileError.js
10upsimon Sep 7, 2023
1bf277c
Update assets/js/components/KeyMetrics/MetricTileError.js
10upsimon Sep 7, 2023
68bbae5
Merge branch 'kmw/7465-implement-insufficient-permissions-error-cta-k…
10upsimon Sep 7, 2023
6530396
Conditional rendering of getHelpText within ReportErrorActions.
10upsimon Sep 8, 2023
ed538cf
Handle checking for insufficient permissions when error is an array o…
10upsimon Sep 8, 2023
6ee8b1c
Update VRT references.
10upsimon Sep 8, 2023
0b1fbd5
Move wordpress import.
hussain-t Sep 8, 2023
2d16aff
Remove GA4 mock data and provide SC mock data.
hussain-t Sep 8, 2023
6b6ea38
Fix translations.
hussain-t Sep 8, 2023
056959f
Simplify the logic using castArray based on Evan's suggestion.
hussain-t Sep 8, 2023
bb4b9ee
Remove superfluous comments.
techanvil Sep 19, 2023
118d7f8
Improve translatability of custom help link text.
techanvil Sep 19, 2023
53d7024
Merge branch 'develop' into kmw/7465-implement-insufficient-permissio…
techanvil Sep 19, 2023
75f9aa4
Extract GetHelpLink to its own file.
techanvil Sep 19, 2023
a7fddbe
Add missing proptypes.
techanvil Sep 20, 2023
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
42 changes: 42 additions & 0 deletions assets/js/components/KeyMetrics/MetricTileError/GetHelpLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* GetHelpLink component.
*
* Site Kit by Google, Copyright 2023 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.
*/

/**
* WordPress dependencies
*/
import { createInterpolateElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import Link from '../../Link';

export default function GetHelpLink( { linkURL } ) {
return createInterpolateElement(
/* translators: %s: get help text. */
__( 'Trouble getting access? <HelpLink />', 'google-site-kit' ),
{
HelpLink: (
<Link href={ linkURL } external>
{ __( 'Get help', 'google-site-kit' ) }
</Link>
),
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,49 @@
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import { castArray } from 'lodash';

/**
* Internal dependencies
* WordPress dependencies
*/
import CTA from '../notifications/CTA';
import ReportErrorActions from '../ReportErrorActions';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import CTA from '../../notifications/CTA';
import ReportErrorActions from '../../ReportErrorActions';
import GetHelpLink from './GetHelpLink';
import { isInsufficientPermissionsError } from '../../../util/errors';

export default function MetricTileError( props ) {
const { error, headerText, moduleSlug } = props;
const hasInsufficientPermissionsError = castArray( error ).some(
isInsufficientPermissionsError
);

return (
<div className="googlesitekit-km-widget-tile--error">
<CTA
title={ __( 'Data loading failed', 'google-site-kit' ) }
title={
hasInsufficientPermissionsError
? __( 'Insufficient permissions', 'google-site-kit' )
: __( 'Data loading failed', 'google-site-kit' )
}
headerText={ headerText }
description=""
error
>
<ReportErrorActions moduleSlug={ moduleSlug } error={ error } />
<ReportErrorActions
moduleSlug={ moduleSlug }
error={ error }
GetHelpLink={
hasInsufficientPermissionsError
? GetHelpLink
: undefined
}
/>
</CTA>
</div>
);
}

MetricTileError.propTypes = {
error: PropTypes.oneOfType( [
PropTypes.arrayOf( PropTypes.object ),
PropTypes.object,
] ).isRequired,
headerText: PropTypes.string,
moduleSlug: PropTypes.string.isRequired,
};
19 changes: 15 additions & 4 deletions assets/js/components/ReportErrorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ import Link from './Link';

const { useSelect, useDispatch } = Data;

export default function ReportErrorActions( { moduleSlug, error } ) {
export default function ReportErrorActions( {
moduleSlug,
error,
GetHelpLink,
} ) {
const isViewOnly = useViewOnly();
const storeName = useSelect( ( select ) =>
select( CORE_MODULES ).getModuleStoreName( moduleSlug )
Expand Down Expand Up @@ -131,9 +135,15 @@ export default function ReportErrorActions( { moduleSlug, error } ) {
</span>
</Fragment>
) : (
<Link href={ errorTroubleshootingLinkURL } external>
{ __( 'Get help', 'google-site-kit' ) }
</Link>
<div>
{ typeof GetHelpLink === 'function' ? (
<GetHelpLink linkURL={ errorTroubleshootingLinkURL } />
) : (
<Link href={ errorTroubleshootingLinkURL } external>
{ __( 'Get help', 'google-site-kit' ) }
</Link>
) }
</div>
) }
</div>
);
Expand All @@ -145,4 +155,5 @@ ReportErrorActions.propTypes = {
PropTypes.arrayOf( PropTypes.object ),
PropTypes.object,
] ).isRequired,
GetHelpLink: PropTypes.elementType,
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import { MODULES_ANALYTICS_4 } from '../../datastore/constants';
import {
provideKeyMetrics,
provideModuleRegistrations,
provideModules,
} from '../../../../../../tests/js/utils';
import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
Expand All @@ -31,6 +32,8 @@ import {
provideAnalytics4MockReport,
} from '../../utils/data-mock';
import { replaceValuesInAnalytics4ReportWithZeroData } from '../../../../../../.storybook/utils/zeroReports';
import { ERROR_REASON_INSUFFICIENT_PERMISSIONS } from '../../../../util/errors';
import { MODULES_ANALYTICS } from '../../../analytics/datastore/constants';

const reportOptions = {
compareStartDate: '2020-07-14',
Expand Down Expand Up @@ -125,6 +128,40 @@ Error.scenario = {
delay: 250,
};

export const InsufficientPermissions = Template.bind( {} );
InsufficientPermissions.storyName = 'Insufficient Permissions';
InsufficientPermissions.args = {
setupRegistry: ( { dispatch } ) => {
const errorObject = {
code: 403,
message: 'Test error message. ',
data: {
status: 403,
reason: ERROR_REASON_INSUFFICIENT_PERMISSIONS,
},
selectorData: {
storeName: 'modules/analytics-4',
name: 'getReport',
args: [ reportOptions ],
},
};

dispatch( MODULES_ANALYTICS_4 ).receiveError(
errorObject,
'getReport',
[ reportOptions ]
);

dispatch( MODULES_ANALYTICS_4 ).finishResolution( 'getReport', [
reportOptions,
] );
},
};
InsufficientPermissions.scenario = {
label: 'KeyMetrics/EngagedTrafficSource/InsufficientPermissions',
delay: 250,
};

export default {
title: 'Key Metrics/EngagedTrafficSourceWidget',
decorators: [
Expand All @@ -138,6 +175,24 @@ export default {
},
] );

provideModuleRegistrations( registry );

const [ accountID, propertyID, webDataStreamID ] = [
'12345',
'34567',
'56789',
];

registry
.dispatch( MODULES_ANALYTICS )
.setAccountID( accountID );
registry
.dispatch( MODULES_ANALYTICS_4 )
.setPropertyID( propertyID );
registry
.dispatch( MODULES_ANALYTICS_4 )
.setWebDataStreamID( webDataStreamID );

registry.dispatch( CORE_USER ).setReferenceDate( '2020-09-08' );

provideKeyMetrics( registry );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import { MODULES_ANALYTICS_4 } from '../../datastore/constants';
import {
provideKeyMetrics,
provideModuleRegistrations,
provideModules,
} from '../../../../../../tests/js/utils';
import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
Expand All @@ -31,6 +32,8 @@ import {
provideAnalytics4MockReport,
} from '../../utils/data-mock';
import { replaceValuesInAnalytics4ReportWithZeroData } from '../../../../../../.storybook/utils/zeroReports';
import { ERROR_REASON_INSUFFICIENT_PERMISSIONS } from '../../../../util/errors';
import { MODULES_ANALYTICS } from '../../../analytics/datastore/constants';

const reportOptions = {
compareStartDate: '2020-07-14',
Expand Down Expand Up @@ -129,6 +132,41 @@ Error.scenario = {
delay: 250,
};

export const InsufficientPermissions = Template.bind( {} );
InsufficientPermissions.storyName = 'Insufficient Permissions';
InsufficientPermissions.args = {
setupRegistry: ( { dispatch } ) => {
const errorObject = {
code: 403,
message: 'Test error message. ',
data: {
status: 403,
reason: ERROR_REASON_INSUFFICIENT_PERMISSIONS,
},
selectorData: {
storeName: 'modules/analytics-4',
name: 'getReport',
args: [ reportOptions ],
},
};

dispatch( MODULES_ANALYTICS_4 ).receiveError(
errorObject,
'getReport',
[ reportOptions ]
);

dispatch( MODULES_ANALYTICS_4 ).finishResolution( 'getReport', [
reportOptions,
] );
},
};

InsufficientPermissions.scenario = {
label: 'KeyMetrics/LoyalVisitors/InsufficientPermissions',
delay: 250,
};

export default {
title: 'Key Metrics/LoyalVisitors',
decorators: [
Expand All @@ -142,6 +180,24 @@ export default {
},
] );

provideModuleRegistrations( registry );

const [ accountID, propertyID, webDataStreamID ] = [
'12345',
'34567',
'56789',
];

registry
.dispatch( MODULES_ANALYTICS )
.setAccountID( accountID );
registry
.dispatch( MODULES_ANALYTICS_4 )
.setPropertyID( propertyID );
registry
.dispatch( MODULES_ANALYTICS_4 )
.setWebDataStreamID( webDataStreamID );

registry.dispatch( CORE_USER ).setReferenceDate( '2020-09-08' );

provideKeyMetrics( registry );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
import {
provideKeyMetrics,
provideModuleRegistrations,
provideModules,
} from '../../../../../../tests/js/utils';
import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
Expand All @@ -33,6 +34,8 @@ import {
} from '../../utils/data-mock';
import { replaceValuesInAnalytics4ReportWithZeroData } from '../../../../../../.storybook/utils/zeroReports';
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import { ERROR_REASON_INSUFFICIENT_PERMISSIONS } from '../../../../util/errors';
import { MODULES_ANALYTICS } from '../../../analytics/datastore/constants';

const reportOptions = {
compareStartDate: '2020-07-14',
Expand Down Expand Up @@ -131,6 +134,41 @@ Error.scenario = {
delay: 250,
};

export const InsufficientPermissions = Template.bind( {} );
InsufficientPermissions.storyName = 'Insufficient Permissions';
InsufficientPermissions.args = {
setupRegistry: ( { dispatch } ) => {
const errorObject = {
code: 403,
message: 'Test error message. ',
data: {
status: 403,
reason: ERROR_REASON_INSUFFICIENT_PERMISSIONS,
},
selectorData: {
storeName: 'modules/analytics-4',
name: 'getReport',
args: [ reportOptions ],
},
};

dispatch( MODULES_ANALYTICS_4 ).receiveError(
errorObject,
'getReport',
[ reportOptions ]
);

dispatch( MODULES_ANALYTICS_4 ).finishResolution( 'getReport', [
reportOptions,
] );
},
};

InsufficientPermissions.scenario = {
label: 'KeyMetrics/NewVisitors/InsufficientPermissions',
delay: 250,
};

export default {
title: 'Key Metrics/NewVisitors',
decorators: [
Expand All @@ -144,6 +182,24 @@ export default {
},
] );

provideModuleRegistrations( registry );

const [ accountID, propertyID, webDataStreamID ] = [
'12345',
'34567',
'56789',
];

registry
.dispatch( MODULES_ANALYTICS )
.setAccountID( accountID );
registry
.dispatch( MODULES_ANALYTICS_4 )
.setPropertyID( propertyID );
registry
.dispatch( MODULES_ANALYTICS_4 )
.setWebDataStreamID( webDataStreamID );

registry.dispatch( CORE_USER ).setReferenceDate( '2020-09-08' );

provideKeyMetrics( registry );
Expand Down
Loading
Loading