Skip to content

Commit

Permalink
Protect: minor enhancements to scan report data
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Dec 16, 2024
1 parent a877b8c commit 72df33f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ export default function ScanReport( { dataSource, data, onChangeSelection } ): J
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#getitemid-function
*/
const getItemId = useCallback( ( item: ScanReportExtension ) => item.id.toString(), [] );
const getItemId = useCallback(
( item: ScanReportExtension ) => `${ item.type }_${ item.slug }_${ item.version }`,
[]
);

return (
<DataViews
Expand Down
29 changes: 20 additions & 9 deletions projects/plugins/protect/src/js/routes/home/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AdminSection, Container, Col, ScanReport } from '@automattic/jetpack-components';
import { __ } from '@wordpress/i18n';
import { useMemo } from 'react';
import AdminPage from '../../components/admin-page';
import useScanStatusQuery from '../../data/scan/use-scan-status-query';
import HomeAdminSectionHero from './home-admin-section-hero';
Expand All @@ -13,16 +15,25 @@ import styles from './styles.module.scss';
*/
const HomePage = () => {
const { data: status } = useScanStatusQuery( { usePolling: true } );
const { core, plugins, themes, files } = status;

const data = [
core,
...plugins,
...themes,
{ checked: true, threats: files, type: 'files' },
].map( ( item, index ) => {
return { id: index + 1, ...item };
} );
const data = useMemo(
() => [
...( Object.keys( status.core ).length ? [ status.core ] : [] ),
...status.plugins,
...status.themes,
...( status.dataSource === 'scan_api'
? [
{
checked: !! status.lastChecked,
threats: status.files,
type: 'files',
name: __( 'Files', 'jetpack-protect' ),
},
]
: [] ),
],
[ status ]
);

return (
<AdminPage>
Expand Down

0 comments on commit 72df33f

Please sign in to comment.