Skip to content

Commit

Permalink
Adjustments to scan fetching/in progress/results/error state management
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Aug 7, 2024
1 parent 7fc705b commit 45ee387
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion projects/plugins/protect/src/js/routes/scan/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,16 @@ 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, scanError ] );
}, [ scanInProgress, status.currentProgress, statusIsFetching, scanError ] );

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

// When "optimistically" scanning, ignore any other status or error.
if ( SCAN_STATUS_OPTIMISTICALLY_SCANNING === status ) {
return true;
}

// If there is an error or the scan is unavailable, scanning is not in progress.
if ( error || unavailable ) {
// If the scanner is unavailable, scanning is not in progress.
if ( unavailable ) {
return false;
}

Expand All @@ -41,7 +41,7 @@ const scanInProgress = state => {
* @returns {ScanError|null} The error object or null.
*/
const scanError = state => {
const { error, errorCode, errorMessage } = selectors.getStatus( state );
const { status, error, errorCode, errorMessage } = selectors.getStatus( state );
const unavailable = selectors.getScanIsUnavailable( state );

// If the scan results include an error, return it.
Expand All @@ -50,7 +50,7 @@ const scanError = state => {
}

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

0 comments on commit 45ee387

Please sign in to comment.