Skip to content

Commit

Permalink
Adjust scan status selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Aug 8, 2024
1 parent 2517699 commit 9a6711f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 1 addition & 5 deletions projects/plugins/protect/src/js/routes/scan/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,12 @@ const ScanPage = () => {
return <ScanningSection currentProgress={ status.currentProgress } />;
}

if ( statusIsFetching ) {
return <Spinner />;
}

if ( scanError ) {
return <ErrorSection errorMessage={ scanError.message } errorCode={ scanError.code } />;
}

return <DefaultSection />;
}, [ scanInProgress, status.currentProgress, statusIsFetching, scanError ] );
}, [ scanInProgress, status.currentProgress, scanError ] );

return (
<OnboardingContext.Provider value={ onboardingSteps }>
Expand Down
22 changes: 18 additions & 4 deletions projects/plugins/protect/src/js/state/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SCAN_IN_PROGRESS_STATUSES, SCAN_STATUS_OPTIMISTICALLY_SCANNING } from '
* @returns {boolean} Whether a scan is in progress.
*/
const scanInProgress = state => {
const { status, lastChecked } = selectors.getStatus( state );
const { status, lastChecked, error } = selectors.getStatus( state );
const unavailable = selectors.getScanIsUnavailable( state );

// When "optimistically" scanning, ignore any other status or error.
Expand All @@ -21,8 +21,13 @@ const scanInProgress = state => {
return false;
}

// If the status is one of the scanning statuses, or if we have never checked, we are scanning.
if ( SCAN_IN_PROGRESS_STATUSES.includes( status ) || ! lastChecked ) {
// If the status is one of the scanning statuses, we are scanning.
if ( SCAN_IN_PROGRESS_STATUSES.includes( status ) ) {
return true;
}

// If we have no record of a previous scan, we must be queueing up the initial scan.
if ( ! lastChecked && ! error ) {
return true;
}

Expand All @@ -43,14 +48,23 @@ const scanInProgress = state => {
const scanError = state => {
const { status, error, errorCode, errorMessage } = selectors.getStatus( state );
const unavailable = selectors.getScanIsUnavailable( state );
const isFetching = selectors.getStatusIsFetching( state );

// If the scan results include an error, return it.
if ( error ) {
return { code: errorCode, message: errorMessage };
}

// If the scan is unavailable, return an error.
if ( unavailable || ! status ) {
if ( unavailable ) {
return {
code: 'scan_unavailable',
message: __( 'We are having problems scanning your site.', 'jetpack-protect' ),
};
}

// If there is no status and we are not requesting it, return an error.
if ( ! status && ! isFetching ) {
return {
code: 'scan_unavailable',
message: __( 'We are having problems scanning your site.', 'jetpack-protect' ),
Expand Down

0 comments on commit 9a6711f

Please sign in to comment.