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

Alter text for view-only users is ReportError. #6292

Merged
merged 6 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
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
22 changes: 19 additions & 3 deletions assets/js/components/ReportError.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ import ErrorText from '../components/ErrorText';
import CTA from './notifications/CTA';
import Link from './Link';
import { CORE_SITE } from '../googlesitekit/datastore/site/constants';

import useViewOnly from '../hooks/useViewOnly';
const { useSelect, useDispatch } = Data;

export default function ReportError( { moduleSlug, error } ) {
const isViewOnly = useViewOnly();
const module = useSelect( ( select ) =>
select( CORE_MODULES ).getModule( moduleSlug )
);
Expand All @@ -68,7 +69,7 @@ export default function ReportError( { moduleSlug, error } ) {
err.selectorData.name === 'getReport'
);

const showRetry = !! retryableErrors.length;
const showRetry = !! retryableErrors.length && ! isViewOnly;

const errorTroubleshootingLinkURL = useSelect( ( select ) => {
const err = {
Expand All @@ -87,6 +88,21 @@ export default function ReportError( { moduleSlug, error } ) {
let title;

const getMessage = ( err ) => {
if ( isViewOnly ) {
title = sprintf(
/* translators: %s: module name */
__( 'Access lost to %s', 'google-site-kit' ),
module?.name
);
return sprintf(
/* translators: %s: module name */
__(
'The administrator sharing this module with you has lost access to the %s service, so you won’t be able to see stats from it on the Site Kit dashboard. You can contact them or another administrator to restore access.',
'google-site-kit'
),
module?.name
);
}
if ( isInsufficientPermissionsError( err ) ) {
title = sprintf(
/* translators: %s: module name */
Expand Down Expand Up @@ -162,7 +178,7 @@ export default function ReportError( { moduleSlug, error } ) {
}, [ dispatch, retryableErrors ] );

const showRequestAccessURL =
requestAccessURL && hasInsufficientPermissionsError;
requestAccessURL && hasInsufficientPermissionsError && ! isViewOnly;

return (
<CTA title={ title } description={ description } error>
Expand Down
22 changes: 20 additions & 2 deletions assets/js/components/ReportError.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ import {
provideModuleRegistrations,
} from '../../../tests/js/utils';
import WithRegistrySetup from '../../../tests/js/WithRegistrySetup';
import { Provider as ViewContextProvider } from './Root/ViewContextContext';
import { ERROR_REASON_INSUFFICIENT_PERMISSIONS } from '../util/errors';
import { MODULES_ANALYTICS } from '../modules/analytics/datastore/constants';
import {
VIEW_CONTEXT_MAIN_DASHBOARD,
VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
} from '../googlesitekit/constants';

const Template = ( { setupRegistry = () => {}, ...args } ) => (
const Template = ( { setupRegistry = () => {}, viewContext, ...args } ) => (
<WithRegistrySetup func={ setupRegistry }>
<ReportError moduleSlug="test-module" { ...args } />
<ViewContextProvider
value={ viewContext || VIEW_CONTEXT_MAIN_DASHBOARD }
>
<ReportError moduleSlug="test-module" { ...args } />
</ViewContextProvider>
</WithRegistrySetup>
);

Expand Down Expand Up @@ -243,6 +252,15 @@ MultipleUniqueReportErrorsWithRetryButtonWith.args = {
],
};

export const ReportErrorViewOnlyMode = Template.bind( {} );
ReportErrorViewOnlyMode.storyName = 'ReportError with ViewOnly Mode';
ReportErrorViewOnlyMode.args = {
error: {
code: 'test-error-code',
},
viewContext: VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
};

export default {
title: 'Components/ReportError',
component: ReportError,
Expand Down
32 changes: 32 additions & 0 deletions assets/js/components/ReportError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { fireEvent, render } from '../../../tests/js/test-utils';
import ReportError from './ReportError';
import { MODULES_ANALYTICS } from '../modules/analytics/datastore/constants';
import { VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY } from '../googlesitekit/constants';

describe( 'ReportError', () => {
let registry;
Expand Down Expand Up @@ -369,6 +370,37 @@ describe( 'ReportError', () => {
expect( getByRole( 'button', { name: /retry/i } ) ).toBeInTheDocument();
} );

it( 'should not render the `Retry` button for a view-only user', () => {
const { queryByText } = render(
<ReportError
moduleSlug={ moduleName }
error={ {
code: 'test-error-code',
message: 'Test error message',
data: {},
selectorData: {
args: [
{
dimensions: [ 'ga:date' ],
metrics: [ { expression: 'ga:users' } ],
startDate: '2020-08-11',
endDate: '2020-09-07',
},
],
name: 'getReport',
storeName: MODULES_ANALYTICS,
},
} }
/>,
{
registry,
viewContext: VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
}
);

expect( queryByText( /retry/i ) ).not.toBeInTheDocument();
} );

it( 'should dispatch the `invalidateResolution` action for each retry-able error', () => {
const { getByRole } = render(
<ReportError
Expand Down