Skip to content
Merged
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
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 }`,
Copy link
Contributor

@dkmyta dkmyta Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we certain every item will have a type, slug and version? IIRC the slug for core is null and we don't currently appear to be supply a slug or version property for the files object we pass. Storybook runs fine so it doesn't really appear to matter, perhaps wordpress_null_6.7.1 or files_null_null is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps wordpress_null_6.7.1 or files_null_null is fine.

This was/is my thought, as the generated IDs are still unique, specific to the item, and accurate.

[]
);

return (
<DataViews
Expand Down
27 changes: 18 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,5 @@
import { AdminSection, Container, Col, ScanReport } from '@automattic/jetpack-components';
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 +14,24 @@ 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',
},
]
: [] ),
],
[ status ]
);

return (
<AdminPage>
Expand Down
Loading