From 45ee387e5f51285e3168c284eee37d1cc967c927 Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Wed, 7 Aug 2024 15:10:16 -0600 Subject: [PATCH] Adjustments to scan fetching/in progress/results/error state management --- projects/plugins/protect/src/js/routes/scan/index.jsx | 6 +++++- projects/plugins/protect/src/js/state/selectors.js | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/projects/plugins/protect/src/js/routes/scan/index.jsx b/projects/plugins/protect/src/js/routes/scan/index.jsx index 1de1cb5448eb4..ba105418a8cc0 100644 --- a/projects/plugins/protect/src/js/routes/scan/index.jsx +++ b/projects/plugins/protect/src/js/routes/scan/index.jsx @@ -199,12 +199,16 @@ const ScanPage = () => { return ; } + if ( statusIsFetching ) { + return ; + } + if ( scanError ) { return ; } return ; - }, [ scanInProgress, status.currentProgress, scanError ] ); + }, [ scanInProgress, status.currentProgress, statusIsFetching, scanError ] ); return ( diff --git a/projects/plugins/protect/src/js/state/selectors.js b/projects/plugins/protect/src/js/state/selectors.js index 6382c120931aa..a20a2bfe08ba1 100644 --- a/projects/plugins/protect/src/js/state/selectors.js +++ b/projects/plugins/protect/src/js/state/selectors.js @@ -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, 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. @@ -16,8 +16,8 @@ const scanInProgress = state => { 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; } @@ -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. @@ -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' ),