Skip to content

Commit

Permalink
Protect: show loading indicator in status column when scan is in prog…
Browse files Browse the repository at this point in the history
…ress
  • Loading branch information
nateweller committed Dec 15, 2024
1 parent 7aadefb commit 4eb7f10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
18 changes: 14 additions & 4 deletions projects/js-packages/components/components/scan-report/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ScanReportExtension } from '@automattic/jetpack-scan';
import { Tooltip } from '@wordpress/components';
import { Spinner, Tooltip } from '@wordpress/components';
import {
type SupportedLayouts,
type View,
Expand Down Expand Up @@ -30,10 +30,16 @@ import styles from './styles.module.scss';
* @param {string} props.dataSource - Data source.
* @param {Array} props.data - Scan report data.
* @param {Function} props.onChangeSelection - Callback function run when an item is selected.
* @param {boolean} props.scanInProgress - Whether a scan is in progress.
*
* @return {JSX.Element} The ScanReport component.
*/
export default function ScanReport( { dataSource, data, onChangeSelection } ): JSX.Element {
export default function ScanReport( {
dataSource,
data,
onChangeSelection,
scanInProgress = false,
} ): JSX.Element {
const baseView = {
search: '',
filters: [],
Expand Down Expand Up @@ -140,7 +146,11 @@ export default function ScanReport( { dataSource, data, onChangeSelection } ): J
return (
<Tooltip className={ styles.tooltip } text={ text }>
<div className={ styles.icon }>
<ShieldIcon variant={ variant } height={ iconHeight } />
{ scanInProgress ? (
<Spinner />
) : (
<ShieldIcon variant={ variant } height={ iconHeight } />
) }
</div>
</Tooltip>
);
Expand Down Expand Up @@ -191,7 +201,7 @@ export default function ScanReport( { dataSource, data, onChangeSelection } ): J
];

return result;
}, [ view, dataSource ] );
}, [ view.type, dataSource, scanInProgress ] );

/**
* Apply the view settings (i.e. filters, sorting, pagination) to the dataset.
Expand Down
9 changes: 7 additions & 2 deletions projects/plugins/protect/src/js/routes/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const HomePage = () => {
[ status ]
);

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

return (
<AdminPage>
Expand All @@ -48,7 +49,11 @@ const HomePage = () => {
horizontalGap={ 4 }
>
<Col>
<ScanReport dataSource={ status.dataSource } data={ data } />
<ScanReport
dataSource={ status.dataSource }
data={ data }
scanInProgress={ scanInProgress }
/>
</Col>
</Container>
</AdminSection>
Expand Down

0 comments on commit 4eb7f10

Please sign in to comment.