Skip to content

Commit 895043f

Browse files
authored
Protect Meets Core: Home Page Scan Report Data Adjustments (#40616)
1 parent 69a281a commit 895043f

File tree

2 files changed

+22
-10
lines changed
  • projects
    • js-packages/components/components/scan-report
    • plugins/protect/src/js/routes/home

2 files changed

+22
-10
lines changed

projects/js-packages/components/components/scan-report/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ export default function ScanReport( { dataSource, data, onChangeSelection } ): J
216216
*
217217
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#getitemid-function
218218
*/
219-
const getItemId = useCallback( ( item: ScanReportExtension ) => item.id.toString(), [] );
219+
const getItemId = useCallback(
220+
( item: ScanReportExtension ) => `${ item.type }_${ item.slug }_${ item.version }`,
221+
[]
222+
);
220223

221224
return (
222225
<DataViews

projects/plugins/protect/src/js/routes/home/index.jsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AdminSection, Container, Col, ScanReport } from '@automattic/jetpack-components';
2+
import { useMemo } from 'react';
23
import AdminPage from '../../components/admin-page';
34
import useScanStatusQuery from '../../data/scan/use-scan-status-query';
45
import HomeAdminSectionHero from './home-admin-section-hero';
@@ -13,16 +14,24 @@ import styles from './styles.module.scss';
1314
*/
1415
const HomePage = () => {
1516
const { data: status } = useScanStatusQuery( { usePolling: true } );
16-
const { core, plugins, themes, files } = status;
1717

18-
const data = [
19-
core,
20-
...plugins,
21-
...themes,
22-
{ checked: true, threats: files, type: 'files' },
23-
].map( ( item, index ) => {
24-
return { id: index + 1, ...item };
25-
} );
18+
const data = useMemo(
19+
() => [
20+
...( Object.keys( status.core ).length ? [ status.core ] : [] ),
21+
...status.plugins,
22+
...status.themes,
23+
...( status.dataSource === 'scan_api'
24+
? [
25+
{
26+
checked: !! status.lastChecked,
27+
threats: status.files,
28+
type: 'files',
29+
},
30+
]
31+
: [] ),
32+
],
33+
[ status ]
34+
);
2635

2736
return (
2837
<AdminPage>

0 commit comments

Comments
 (0)