Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect: Show loading indicator as status icon when scan in progress #40624

Open
wants to merge 3 commits into
base: fix/protect/home-stat-card-gap
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading