-
Notifications
You must be signed in to change notification settings - Fork 844
Components: Add ScanReport #40419
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
Components: Add ScanReport #40419
Changes from 1 commit
d0e310e
c741513
7784874
5a7d70f
a5cdeed
600a05e
60ba2de
257f90a
a5c2691
4742c9a
8cfc9b6
448c05b
6cd56cb
7715221
ed4eb50
402c95f
e491ac9
83d9312
8b720f6
2c8de2e
5d8f4ef
519bac2
d44ca54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,13 +7,13 @@ import { | |||||
| filterSortAndPaginate, | ||||||
| } from '@wordpress/dataviews'; | ||||||
| import { __ } from '@wordpress/i18n'; | ||||||
| import { Icon, check } from '@wordpress/icons'; | ||||||
| import { Icon } from '@wordpress/icons'; | ||||||
| import { useCallback, useMemo, useState } from 'react'; | ||||||
| import { | ||||||
| THREAT_FIELD_EXTENSION, | ||||||
| THREAT_FIELD_VERSION, | ||||||
| THREAT_FIELD_ICON, | ||||||
| THREAT_FIELD_SAFETY, | ||||||
| THREAT_FIELD_UPDATE, | ||||||
| THREAT_FIELD_TYPE, | ||||||
| THREAT_TYPES, | ||||||
| THREAT_ICONS, | ||||||
|
|
@@ -33,7 +33,6 @@ import styles from './styles.module.scss'; | |||||
| * @return {JSX.Element} The ScanReport component. | ||||||
| */ | ||||||
| export default function ScanReport( { data, filters, onChangeSelection } ): JSX.Element { | ||||||
| // TODO: Add types | ||||||
| const baseView = { | ||||||
| search: '', | ||||||
| filters: filters || [], | ||||||
|
|
@@ -55,17 +54,17 @@ export default function ScanReport( { data, filters, onChangeSelection } ): JSX. | |||||
| THREAT_FIELD_SAFETY, | ||||||
| THREAT_FIELD_TYPE, | ||||||
| THREAT_FIELD_EXTENSION, | ||||||
| THREAT_FIELD_UPDATE, | ||||||
| THREAT_FIELD_VERSION, | ||||||
| ], | ||||||
| layout: { | ||||||
| primaryField: THREAT_FIELD_SAFETY, | ||||||
| }, | ||||||
| }, | ||||||
| list: { | ||||||
| ...baseView, | ||||||
| fields: [ THREAT_FIELD_SAFETY, THREAT_FIELD_TYPE, THREAT_FIELD_UPDATE ], | ||||||
| fields: [ THREAT_FIELD_SAFETY, THREAT_FIELD_EXTENSION, THREAT_FIELD_VERSION ], | ||||||
| layout: { | ||||||
| primaryField: THREAT_FIELD_EXTENSION, | ||||||
| primaryField: THREAT_FIELD_TYPE, | ||||||
| mediaField: THREAT_FIELD_ICON, | ||||||
| }, | ||||||
| }, | ||||||
|
|
@@ -144,15 +143,14 @@ export default function ScanReport( { data, filters, onChangeSelection } ): JSX. | |||||
| enableGlobalSearch: true, | ||||||
| render( { item } ) { | ||||||
| return item.name ? item.name : ''; | ||||||
| // TODO: Account for file and db? | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| id: THREAT_FIELD_UPDATE, | ||||||
| label: __( 'Update Available', 'jetpack' ), | ||||||
| render() { | ||||||
| return <Icon className={ styles.check } icon={ check } />; | ||||||
| // TODO: Is this possible to determine? | ||||||
| id: THREAT_FIELD_VERSION, | ||||||
| label: __( 'Version', 'jetpack' ), | ||||||
| enableGlobalSearch: true, | ||||||
| render( { item } ) { | ||||||
dkmyta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| return item.version ? item.version : ''; | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
|
|
@@ -195,7 +193,6 @@ export default function ScanReport( { data, filters, onChangeSelection } ): JSX. | |||||
| * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#getitemid-function | ||||||
| */ | ||||||
| const getItemId = useCallback( ( item: Threat ) => item.id.toString(), [] ); | ||||||
|
||||||
| const getItemId = useCallback( ( item: Threat ) => item.id.toString(), [] ); | |
| const getItemId = useCallback( ( item: Extension ) => item.slug, [] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How I've got this to work in Protect is by spreading the core, plugins, themes, and a modified files variable from the useProtectData hook as data and passing it to this component. The core and files variables will no include a slug so instead I've just combined the set and indexed them like so:
const {
results: { core, plugins, themes, files },
} = useProtectData();
const data = [
...core,
...plugins,
...themes,
{ checked: true, threats: files, type: 'files' },
].map( ( item, index ) => {
return { id: index + 1, ...item };
} );
Obviously the Threat doesn't apply here, but Extension won't either. Any thought on how we could approach this differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The useProtectData hook is being removed in add/protect/core, we will be referencing data from protect-status here which should return the full Extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(We could add a custom type if Extension is not applicable, i.e. ScanReportExtension)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do go with generating an ID, I would recommend using the slug or any other unique identifiers whenever possible as opposed to index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The useProtectData hook is being removed in add/protect/core, we will be referencing data from protect-status here which should return the full Extension.
Ah good to know, I missed that entirely. How will core and file threats be formatted? Will all follow the same structure? Or will they remain unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should remain the same, with core being an Extension with threats, and files being an array of file threats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added/applied a custom ScanReportExtension type. I've kept with generating an ID for now, because for core the slug will always be null, and for the variable we'll have to generate from files and pass to the component, it seems a little awkward to predefine the slug in someway. Perhaps we can add a followup to investigate an improved way to use unique identifier, unless you have a different recommendation for now?
Uh oh!
There was an error while loading. Please reload this page.