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 16, 2024
1 parent 1fd1702 commit dc8c830
Show file tree
Hide file tree
Showing 3 changed files with 24 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
min-width: 32px;
display: flex;
justify-content: center;

> svg {
margin: 0;
}
}
8 changes: 6 additions & 2 deletions projects/plugins/protect/src/js/routes/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { __ } from '@wordpress/i18n';
import { useMemo } from 'react';
import AdminPage from '../../components/admin-page';
import { SCAN_IN_PROGRESS_STATUSES } from '../../constants';
import useScanStatusQuery from '../../data/scan/use-scan-status-query';
import useScanStatusQuery, { isScanInProgress } from '../../data/scan/use-scan-status-query';
import HomeAdminSectionHero from './home-admin-section-hero';
import styles from './styles.module.scss';

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

0 comments on commit dc8c830

Please sign in to comment.