Skip to content

Commit

Permalink
Protect: only show Threats DataViews when scan is in progress or has …
Browse files Browse the repository at this point in the history
…results to show
  • Loading branch information
nateweller committed Dec 16, 2024
1 parent 635c949 commit 838b060
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 36 deletions.
2 changes: 0 additions & 2 deletions projects/plugins/protect/src/js/routes/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const HomePage = () => {

const showReport = status.lastChecked || SCAN_IN_PROGRESS_STATUSES.indexOf( status?.status ) >= 0;

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

return (
<AdminPage>
<HomeAdminSectionHero />
Expand Down
63 changes: 35 additions & 28 deletions projects/plugins/protect/src/js/routes/scan/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMemo, useState } from 'react';
import { useLocation, useParams } from 'react-router-dom';
import AdminPage from '../../components/admin-page';
import OnboardingPopover from '../../components/onboarding-popover';
import useHistoryQuery from '../../data/scan/use-history-query';
import useScanStatusQuery, { isScanInProgress } from '../../data/scan/use-scan-status-query';
import useAnalyticsTracks from '../../hooks/use-analytics-tracks';
import { OnboardingContext } from '../../hooks/use-onboarding';
Expand All @@ -24,6 +25,7 @@ const ScanPage = () => {
const location = useLocation();
const { filter } = useParams();
const { data: status } = useScanStatusQuery( { usePolling: true } );
const { data: history } = useHistoryQuery();

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

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

const hasHistory = history && history.threats.length;
const showResults = !! status.threats.length || hasHistory;

const filters = useMemo( () => {
if ( location.pathname.includes( '/scan/history' ) ) {
return [
Expand Down Expand Up @@ -68,34 +73,36 @@ const ScanPage = () => {
return (
<OnboardingContext.Provider value={ onboardingSteps }>
<AdminPage>
<ScanAdminSectionHero />
<AdminSection>
<Container
className={ styles[ 'scan-results-container' ] }
horizontalSpacing={ 5 }
horizontalGap={ 4 }
>
<Col>
<div ref={ setScanResultsAnchor }>
<ScanResultsDataView filters={ filters } />
</div>
{ !! status && ! isScanInProgress( status ) && (
<OnboardingPopover
id={ hasPlan ? 'paid-scan-results' : 'free-scan-results' }
anchor={ scanResultsAnchor }
position={ 'top' }
/>
) }
{ !! status && ! isScanInProgress( status ) && hasPlan && (
<OnboardingPopover
id={ 'paid-understand-severity' }
anchor={ scanResultsAnchor }
position={ 'top' }
/>
) }
</Col>
</Container>
</AdminSection>
<ScanAdminSectionHero size={ showResults ? 'normal' : 'large' } />
{ showResults && (
<AdminSection>
<Container
className={ styles[ 'scan-results-container' ] }
horizontalSpacing={ 5 }
horizontalGap={ 4 }
>
<Col>
<div ref={ setScanResultsAnchor }>
<ScanResultsDataView filters={ filters } />
</div>
{ !! status && ! isScanInProgress( status ) && (
<OnboardingPopover
id={ hasPlan ? 'paid-scan-results' : 'free-scan-results' }
anchor={ scanResultsAnchor }
position={ 'top' }
/>
) }
{ !! status && ! isScanInProgress( status ) && hasPlan && (
<OnboardingPopover
id={ 'paid-understand-severity' }
anchor={ scanResultsAnchor }
position={ 'top' }
/>
) }
</Col>
</Container>
</AdminSection>
) }
</AdminPage>
</OnboardingContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Text, Button, useBreakpointMatch } from '@automattic/jetpack-components
import { Tooltip } from '@wordpress/components';
import { dateI18n } from '@wordpress/date';
import { __, _n, sprintf } from '@wordpress/i18n';
import clsx from 'clsx';
import { useCallback, useState, useMemo } from 'react';
import AdminSectionHero from '../../components/admin-section-hero';
import ErrorAdminSectionHero from '../../components/error-admin-section-hero';
Expand All @@ -15,7 +16,7 @@ import useWafData from '../../hooks/use-waf-data';
import ScanningAdminSectionHero from './scanning-admin-section-hero';
import styles from './styles.module.scss';

const ScanAdminSectionHero: React.FC = () => {
const ScanAdminSectionHero: React.FC = ( { size = 'normal' }: { size?: 'normal' | 'large' } ) => {
const { recordEvent } = useAnalyticsTracks();
const { hasPlan, upgradePlan } = usePlan();
const { setModal } = useModal();
Expand Down Expand Up @@ -91,7 +92,7 @@ const ScanAdminSectionHero: React.FC = () => {
};

if ( scanning ) {
return <ScanningAdminSectionHero />;
return <ScanningAdminSectionHero size={ size } />;
}

if ( status.error ) {
Expand All @@ -106,7 +107,11 @@ const ScanAdminSectionHero: React.FC = () => {

return (
<AdminSectionHero>
<AdminSectionHero.Main className={ styles[ 'hero-main' ] }>
<AdminSectionHero.Main
className={ clsx( styles[ 'hero-main' ], {
[ styles[ 'hero-main--large' ] ]: size === 'large',
} ) }
>
<Text className={ styles[ 'last-checked' ] } mb={ 2 } ref={ setDailyScansPopoverAnchor }>
{ lastCheckedLocalTimestamp
? sprintf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Text } from '@automattic/jetpack-components';
import { __, sprintf } from '@wordpress/i18n';
import clsx from 'clsx';
import AdminSectionHero from '../../components/admin-section-hero';
import InProgressAnimation from '../../components/in-progress-animation';
import ProgressBar from '../../components/progress-bar';
Expand All @@ -8,7 +9,7 @@ import usePlan from '../../hooks/use-plan';
import useWafData from '../../hooks/use-waf-data';
import styles from './styles.module.scss';

const ScanningAdminSectionHero: React.FC = () => {
const ScanningAdminSectionHero = ( { size = 'normal' }: { size?: 'normal' | 'large' } ) => {
const { hasPlan } = usePlan();
const { globalStats } = useWafData();
const { data: status } = useScanStatusQuery( { usePolling: true } );
Expand All @@ -19,7 +20,11 @@ const ScanningAdminSectionHero: React.FC = () => {

return (
<AdminSectionHero>
<AdminSectionHero.Main className={ styles[ 'hero-main' ] }>
<AdminSectionHero.Main
className={ clsx( styles[ 'hero-main' ], {
[ styles[ 'hero-main--large' ] ]: size === 'large',
} ) }
>
<AdminSectionHero.Heading>
{ __( 'Your results will be ready soon', 'jetpack-protect' ) }
</AdminSectionHero.Heading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
max-width: 512px;
}

.hero-main--large {
flex: 1 auto;
align-content: center;
height: calc( 100vh - 408px );
}

.auto-fixers {
margin-top: calc( var( --spacing-base ) * 4 ); // 32px
width: fit-content;
Expand All @@ -26,4 +32,4 @@

.last-checked {
width: fit-content;
}
}

0 comments on commit 838b060

Please sign in to comment.