Skip to content

Commit e2349ad

Browse files
committed
Protect: only show Threats DataViews when scan is in progress or has results to show
1 parent a005e38 commit e2349ad

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

projects/plugins/protect/src/js/routes/home/index.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ const HomePage = () => {
3737

3838
const showReport = status.lastChecked || isScanInProgress( status );
3939

40-
const showReport = status.lastChecked || isScanInProgress( status );
41-
4240
return (
4341
<AdminPage>
4442
<HomeAdminSectionHero />

projects/plugins/protect/src/js/routes/scan/index.jsx

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useMemo, useState } from 'react';
33
import { useLocation, useParams } from 'react-router-dom';
44
import AdminPage from '../../components/admin-page';
55
import OnboardingPopover from '../../components/onboarding-popover';
6+
import useHistoryQuery from '../../data/scan/use-history-query';
67
import useScanStatusQuery, { isScanInProgress } from '../../data/scan/use-scan-status-query';
78
import useAnalyticsTracks from '../../hooks/use-analytics-tracks';
89
import { OnboardingContext } from '../../hooks/use-onboarding';
@@ -24,6 +25,7 @@ const ScanPage = () => {
2425
const location = useLocation();
2526
const { filter } = useParams();
2627
const { data: status } = useScanStatusQuery( { usePolling: true } );
28+
const { data: history } = useHistoryQuery();
2729

2830
const [ scanResultsAnchor, setScanResultsAnchor ] = useState( null );
2931

@@ -36,6 +38,9 @@ const ScanPage = () => {
3638
currentScanStatus = 'active';
3739
}
3840

41+
const hasHistory = history && history.threats.length;
42+
const showResults = status.lastChecked || isScanInProgress( status ) || hasHistory;
43+
3944
const filters = useMemo( () => {
4045
if ( location.pathname.includes( '/scan/history' ) ) {
4146
return [
@@ -68,34 +73,36 @@ const ScanPage = () => {
6873
return (
6974
<OnboardingContext.Provider value={ onboardingSteps }>
7075
<AdminPage>
71-
<ScanAdminSectionHero />
72-
<AdminSection>
73-
<Container
74-
className={ styles[ 'scan-results-container' ] }
75-
horizontalSpacing={ 5 }
76-
horizontalGap={ 4 }
77-
>
78-
<Col>
79-
<div ref={ setScanResultsAnchor }>
80-
<ScanResultsDataView filters={ filters } />
81-
</div>
82-
{ !! status && ! isScanInProgress( status ) && (
83-
<OnboardingPopover
84-
id={ hasPlan ? 'paid-scan-results' : 'free-scan-results' }
85-
anchor={ scanResultsAnchor }
86-
position={ 'top' }
87-
/>
88-
) }
89-
{ !! status && ! isScanInProgress( status ) && hasPlan && (
90-
<OnboardingPopover
91-
id={ 'paid-understand-severity' }
92-
anchor={ scanResultsAnchor }
93-
position={ 'top' }
94-
/>
95-
) }
96-
</Col>
97-
</Container>
98-
</AdminSection>
76+
<ScanAdminSectionHero size={ showResults ? 'normal' : 'large' } />
77+
{ showResults && (
78+
<AdminSection>
79+
<Container
80+
className={ styles[ 'scan-results-container' ] }
81+
horizontalSpacing={ 5 }
82+
horizontalGap={ 4 }
83+
>
84+
<Col>
85+
<div ref={ setScanResultsAnchor }>
86+
<ScanResultsDataView filters={ filters } />
87+
</div>
88+
{ !! status && ! isScanInProgress( status ) && (
89+
<OnboardingPopover
90+
id={ hasPlan ? 'paid-scan-results' : 'free-scan-results' }
91+
anchor={ scanResultsAnchor }
92+
position={ 'top' }
93+
/>
94+
) }
95+
{ !! status && ! isScanInProgress( status ) && hasPlan && (
96+
<OnboardingPopover
97+
id={ 'paid-understand-severity' }
98+
anchor={ scanResultsAnchor }
99+
position={ 'top' }
100+
/>
101+
) }
102+
</Col>
103+
</Container>
104+
</AdminSection>
105+
) }
99106
</AdminPage>
100107
</OnboardingContext.Provider>
101108
);

projects/plugins/protect/src/js/routes/scan/scan-admin-section-hero.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Text, Button, useBreakpointMatch } from '@automattic/jetpack-components
22
import { Tooltip } from '@wordpress/components';
33
import { dateI18n } from '@wordpress/date';
44
import { __, _n, sprintf } from '@wordpress/i18n';
5+
import clsx from 'clsx';
56
import { useCallback, useState, useMemo } from 'react';
67
import AdminSectionHero from '../../components/admin-section-hero';
78
import ErrorAdminSectionHero from '../../components/error-admin-section-hero';
@@ -15,7 +16,7 @@ import useWafData from '../../hooks/use-waf-data';
1516
import ScanningAdminSectionHero from './scanning-admin-section-hero';
1617
import styles from './styles.module.scss';
1718

18-
const ScanAdminSectionHero: React.FC = () => {
19+
const ScanAdminSectionHero: React.FC = ( { size = 'normal' }: { size?: 'normal' | 'large' } ) => {
1920
const { recordEvent } = useAnalyticsTracks();
2021
const { hasPlan, upgradePlan } = usePlan();
2122
const { setModal } = useModal();
@@ -106,7 +107,11 @@ const ScanAdminSectionHero: React.FC = () => {
106107

107108
return (
108109
<AdminSectionHero>
109-
<AdminSectionHero.Main className={ styles[ 'hero-main' ] }>
110+
<AdminSectionHero.Main
111+
className={ clsx( styles[ 'hero-main' ], {
112+
[ styles[ 'hero-main--large' ] ]: size === 'large',
113+
} ) }
114+
>
110115
<Text className={ styles[ 'last-checked' ] } mb={ 2 } ref={ setDailyScansPopoverAnchor }>
111116
{ lastCheckedLocalTimestamp
112117
? sprintf(

projects/plugins/protect/src/js/routes/scan/styles.module.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
max-width: 512px;
33
}
44

5+
.hero-main--large {
6+
padding-top: calc( var( --spacing-base ) * 8 ); // 64px
7+
padding-bottom: calc( var( --spacing-base ) * 8 ); // 64px
8+
}
9+
510
.auto-fixers {
611
margin-top: calc( var( --spacing-base ) * 4 ); // 32px
712
width: fit-content;
@@ -26,4 +31,4 @@
2631

2732
.last-checked {
2833
width: fit-content;
29-
}
34+
}

0 commit comments

Comments
 (0)