Skip to content

Commit 7adaa13

Browse files
dkmytanateweller
andcommitted
Protect: Add Go to Cloud and Scan now button to Protect primary header (#40057)
Co-authored-by: Nate Weller <hello@nateweller.com>
1 parent bb461aa commit 7adaa13

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Adds Go to Cloud and Scan now buttons to the primary header

projects/plugins/protect/src/js/components/admin-page/index.jsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import {
22
AdminPage as JetpackAdminPage,
3+
Button,
34
Container,
5+
getRedirectUrl,
46
JetpackProtectLogo,
57
} from '@automattic/jetpack-components';
68
import { useConnection } from '@automattic/jetpack-connection';
79
import { __, sprintf } from '@wordpress/i18n';
810
import { useEffect } from 'react';
9-
import { useNavigate } from 'react-router-dom';
11+
import { useLocation, useNavigate } from 'react-router-dom';
1012
import useNotices from '../../hooks/use-notices';
13+
import usePlan from '../../hooks/use-plan';
1114
import useProtectData from '../../hooks/use-protect-data';
1215
import useWafData from '../../hooks/use-waf-data';
1316
import Notice from '../notice';
17+
import ScanButton from '../scan-button';
1418
import Tabs, { Tab } from '../tabs';
1519
import styles from './styles.module.scss';
1620

@@ -24,6 +28,8 @@ const AdminPage = ( { children } ) => {
2428
current: { threats: numThreats },
2529
},
2630
} = useProtectData();
31+
const location = useLocation();
32+
const { hasPlan } = usePlan();
2733

2834
// Redirect to the setup page if the site is not registered.
2935
useEffect( () => {
@@ -36,10 +42,27 @@ const AdminPage = ( { children } ) => {
3642
return null;
3743
}
3844

45+
const viewingScanPage = location.pathname.includes( '/scan' );
46+
47+
const { siteSuffix, blogID } = window.jetpackProtectInitialState || {};
48+
const goToCloudUrl = getRedirectUrl( 'jetpack-scan-dash', { site: blogID ?? siteSuffix } );
49+
3950
return (
4051
<JetpackAdminPage
4152
moduleName={ __( 'Jetpack Protect', 'jetpack-protect' ) }
42-
header={ <JetpackProtectLogo /> }
53+
header={
54+
<div className={ styles.header }>
55+
<JetpackProtectLogo />
56+
{ hasPlan && viewingScanPage && (
57+
<div className={ styles.header__scan_buttons }>
58+
<Button variant="secondary" weight={ 'regular' } href={ goToCloudUrl }>
59+
{ __( 'Go to Cloud', 'jetpack-protect' ) }
60+
</Button>
61+
<ScanButton />
62+
</div>
63+
) }
64+
</div>
65+
}
4366
>
4467
{ notice && <Notice floating={ true } dismissable={ true } { ...notice } /> }
4568
<Container horizontalSpacing={ 0 }>

projects/plugins/protect/src/js/components/admin-page/styles.module.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
white-space: nowrap;
33
}
44

5+
.header {
6+
display: flex;
7+
justify-content: space-between;
8+
9+
&__scan_buttons {
10+
display: flex;
11+
gap: calc( var( --spacing-base ) * 2 ); // 16px
12+
}
13+
}
14+
515
.navigation {
616
margin-top: calc( var( --spacing-base ) * 3 * -1 ); // -24px
717
}

projects/plugins/protect/src/js/components/scan-button/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Button } from '@automattic/jetpack-components';
22
import { __ } from '@wordpress/i18n';
33
import React, { forwardRef, useMemo } from 'react';
4+
import { useNavigate } from 'react-router-dom';
45
import useScanStatusQuery, { isScanInProgress } from '../../data/scan/use-scan-status-query';
56
import useStartScanMutator from '../../data/scan/use-start-scan-mutation';
67

78
const ScanButton = forwardRef( ( { variant = 'secondary', children, ...props }, ref ) => {
89
const startScanMutation = useStartScanMutator();
910
const { data: status } = useScanStatusQuery();
11+
const navigate = useNavigate();
1012

1113
const disabled = useMemo( () => {
1214
return startScanMutation.isPending || isScanInProgress( status );
@@ -15,6 +17,7 @@ const ScanButton = forwardRef( ( { variant = 'secondary', children, ...props },
1517
const handleScanClick = () => {
1618
return event => {
1719
event.preventDefault();
20+
navigate( '/scan' );
1821
startScanMutation.mutate();
1922
};
2023
};
@@ -25,6 +28,7 @@ const ScanButton = forwardRef( ( { variant = 'secondary', children, ...props },
2528
variant={ variant }
2629
onClick={ handleScanClick() }
2730
disabled={ disabled }
31+
weight={ 'regular' }
2832
{ ...props }
2933
>
3034
{ children ?? __( 'Scan now', 'jetpack-protect' ) }

0 commit comments

Comments
 (0)