Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
44f8f5b
Init project branch
nateweller Nov 14, 2024
01718e9
Protect: Add Go to Cloud and Scan now button to Protect primary heade…
dkmyta Nov 14, 2024
8937043
Protect: Update Scan and History headers (#40058)
dkmyta Nov 14, 2024
657dbef
Protect: de-emphasize cloud link by using link variant (#40211)
nateweller Nov 18, 2024
ddc735e
Protect: add ShieldIcon component
nateweller Nov 30, 2024
29e05eb
Protect: Add ShieldIcon Component (#40402)
nateweller Dec 5, 2024
f0fcba8
Protect: Integrate ThreatsDataViews Component (#40076)
nateweller Dec 5, 2024
d339c35
Components: Add ScanReport (#40419)
dkmyta Dec 5, 2024
983ef0c
Fix type errors
nateweller Dec 6, 2024
c91afb8
Protect: Refactor AdminSectionHero (#40516)
nateweller Dec 9, 2024
a9763ae
Protect: Update Scan History extension types (#40548)
dkmyta Dec 10, 2024
69648c8
Protect: Add Home page (#40317)
dkmyta Dec 10, 2024
cebc921
Protect: Integrate ScanReport (#40420)
dkmyta Dec 11, 2024
ccf0ed8
Fix duplicate imports
nateweller Dec 15, 2024
02a1f2e
ScanReport: Fix defaultLayout (#40603)
dkmyta Dec 15, 2024
4aff770
Update onboarding popover placement (#40550)
dkmyta Dec 15, 2024
4a9294b
Protect Meets Core: Home Page Scan Report Data Adjustments (#40616)
nateweller Dec 18, 2024
21b7ae1
Scan Report: Align Status Icon (#40617)
nateweller Dec 18, 2024
94732c6
Apply max width to hero content (#40618)
nateweller Dec 18, 2024
f6b6d75
Protect: Hide Scan Report When No Data (#40619)
nateweller Dec 18, 2024
7d5ad6e
Protect: Hide Threats Report When No Data (#40620)
nateweller Dec 18, 2024
f0dfecd
Protect: Update Threat Icons (#40621)
nateweller Dec 18, 2024
51f270f
Protect: fix home page stat card spacing (#40623)
nateweller Dec 18, 2024
fb68c51
Fix ESLint issue
nateweller Jan 1, 2025
3fa38b5
ScanReport: Disable hiding relevant fields (#40602)
dkmyta Jan 2, 2025
cb979da
Use error variant (#40832)
dkmyta Jan 3, 2025
e42e4ef
Protect: Restore HistoryAdminSectionHero (#40551)
dkmyta Jan 4, 2025
e181c22
Protect: Separate scan results and history DataViews (#40845)
dkmyta Jan 14, 2025
aa5b2a3
ThreatsDataViews: Improve responsiveness (#40670)
dkmyta Jan 14, 2025
193070d
ThreatsDataViews: ThreatModal integration (#40202)
dkmyta Jan 14, 2025
5eda38e
Protect Meets Core: Fix "0" rendered by conditional render chain (#40…
nateweller Jan 14, 2025
3af8b55
Fix: add missing return
nateweller Jan 16, 2025
c24ad4d
Fix: reduce of empty array with no initial value
nateweller Jan 16, 2025
94010c9
Fix: hide home report when first protect report scan initializing
nateweller Jan 16, 2025
6b592a9
minor adjustments
nateweller Jan 31, 2025
149ae4c
Update lockfile
nateweller Jan 31, 2025
eb000c5
Remove changes to protect-status package
nateweller Jan 31, 2025
35f474d
Remove changes to badge components, moved to #41450
nateweller Jan 31, 2025
b368b68
Fix type error
nateweller Feb 3, 2025
556e0f5
Fix stories
nateweller Feb 4, 2025
4a8d00b
Fix case where status.core is empty
nateweller Feb 4, 2025
6f73041
Spacing and sizing adjustments
nateweller Feb 5, 2025
5f2b0e8
Restore unintended webpack-cli version change
nateweller Feb 5, 2025
4953bd8
Fix ThreatsDataViews test
nateweller Feb 6, 2025
d3e68cf
changelog
nateweller Feb 9, 2025
138753d
Fix width of hero content
nateweller Feb 9, 2025
c03770c
Improve threat ignore/unignore queries
nateweller Feb 9, 2025
dc202f0
Remove close button from threat details modal actions
nateweller Feb 9, 2025
fa36e2b
Remove unneccessary changes to protect-status package
nateweller Feb 22, 2025
37fc1a0
Fix z-index conflict between Notice and DataViews components
nateweller Feb 22, 2025
1776bd1
Fix ThreatsDataViews title line wrapping
nateweller Feb 22, 2025
332009e
Add alternate 'how to fix it' message when no fixer or fixed in versi…
nateweller Feb 23, 2025
c44edb1
Fix imports and enhance types
nateweller Feb 23, 2025
aa98338
Additional import fixes and type improvements
nateweller Feb 23, 2025
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
Prev Previous commit
Next Next commit
Protect: Separate scan results and history DataViews (#40845)
* Init project branch

* Protect: Refactor AdminSectionHero (#40516)

* Restore history header

* Pass status filter presets to consumer

* Restore early return

* Add plan level restrictions

* Init project branch

* Protect: Integrate ThreatsDataViews Component (#40076)

* Separate scan and history DataViews

* Reapply history routes

* Add filters

* Add toggle group control

* Add historic flag

* Update stories

* Remove unneeded filter handling

* Revert unnecessary threats data views updates

* Fix import

* Include fixer action as label in list view action dropdown

* Add field constants

* Reorg

* Add initialFields prop, update active to current where applicable

* Init project branch

* Fix exports and imports

* Move default values to function params

* Fix ts warning

* minor adjustment to definition of initial filters

* Add tsc-expect-error to dummy arg for minification cases

---------

Co-authored-by: Nate Weller <[email protected]>
Co-authored-by: Nate Weller <[email protected]>
  • Loading branch information
3 people committed Mar 22, 2025
commit e181c2271aa915a1d743c87b8a5732de2c3c6992
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import {
wordpress as coreIcon,
} from '@wordpress/icons';

export const THREAT_STATUSES: { value: string; label: string; variant?: 'success' | 'warning' }[] =
[
{ value: 'current', label: __( 'Active', 'jetpack-components' ), variant: 'warning' },
{ value: 'fixed', label: __( 'Fixed', 'jetpack-components' ), variant: 'success' },
{ value: 'ignored', label: __( 'Ignored', 'jetpack-components' ) },
];
export const THREAT_STATUSES: { value: string; label: string; variant?: 'success' }[] = [
{ value: 'fixed', label: __( 'Fixed', 'jetpack-components' ), variant: 'success' },
{ value: 'ignored', label: __( 'Ignored', 'jetpack-components' ) },
];

export const THREAT_TYPES = [
{ value: 'plugins', label: __( 'Plugin', 'jetpack-components' ) },
Expand Down Expand Up @@ -45,6 +43,26 @@ export const THREAT_FIELD_FIRST_DETECTED = 'first-detected';
export const THREAT_FIELD_FIXED_ON = 'fixed-on';
export const THREAT_FIELD_AUTO_FIX = 'auto-fix';

export const CURRENT_TABLE_FIELDS = [
THREAT_FIELD_SEVERITY,
THREAT_FIELD_TYPE,
THREAT_FIELD_AUTO_FIX,
];

export const HISTORIC_TABLE_FIELDS = [
THREAT_FIELD_SEVERITY,
THREAT_FIELD_TYPE,
THREAT_FIELD_FIRST_DETECTED,
THREAT_FIELD_FIXED_ON,
];

export const LIST_FIELDS = [
THREAT_FIELD_SEVERITY,
THREAT_FIELD_TYPE,
THREAT_FIELD_EXTENSION,
THREAT_FIELD_SIGNATURE,
];

export const THREAT_ACTION_FIX = 'fix';
export const THREAT_ACTION_IGNORE = 'ignore';
export const THREAT_ACTION_UNIGNORE = 'unignore';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getThreatType, type Threat } from '@automattic/jetpack-scan';
import { getFixerAction, getThreatType, type Threat } from '@automattic/jetpack-scan';
import {
type Action,
type ActionButton,
Expand All @@ -19,6 +19,8 @@ import Badge from '../badge/index.js';
import ThreatFixerButton from '../threat-fixer-button/index.js';
import ThreatSeverityBadge from '../threat-severity-badge/index.js';
import {
CURRENT_TABLE_FIELDS,
LIST_FIELDS,
THREAT_ACTION_FIX,
THREAT_ACTION_IGNORE,
THREAT_ACTION_UNIGNORE,
Expand All @@ -40,52 +42,62 @@ import {
THREAT_TYPES,
} from './constants.js';
import styles from './styles.module.scss';
import ThreatsStatusToggleGroupControl from './threats-status-toggle-group-control.js';

export { HISTORIC_TABLE_FIELDS } from './constants.js';

/**
* DataViews component for displaying security threats.
*
* @param {object} props - Component props.
* @param {Array} props.data - Threats data.
* @param {Array} props.filters - Initial DataView filters.
* @param {Function} props.onChangeSelection - Callback function run when an item is selected.
* @param {Function} props.onFixThreats - Threat fix action callback.
* @param {Function} props.onIgnoreThreats - Threat ignore action callback.
* @param {Function} props.onUnignoreThreats - Threat unignore action callback.
* @param {Function} props.isThreatEligibleForFix - Function to determine if a threat is eligible for fixing.
* @param {Function} props.isThreatEligibleForIgnore - Function to determine if a threat is eligible for ignoring.
* @param {Function} props.isThreatEligibleForUnignore - Function to determine if a threat is eligible for unignoring.
* @param {object} props - Component props.
* @param {string} props.status - Flag to indicate if the threats are current or historic.
* @param {Array} props.data - Threats data.
* @param {Array} props.initialFilters - Initial DataView filters.
* @param {Array} props.initialFields - Initial DataView fields.
* @param {Function} props.onChangeSelection - Callback function run when an item is selected.
* @param {Function} props.onFixThreats - Threat fix action callback.
* @param {Function} props.onIgnoreThreats - Threat ignore action callback.
* @param {Function} props.onUnignoreThreats - Threat unignore action callback.
* @param {Function} props.isThreatEligibleForFix - Function to determine if a threat is eligible for fixing.
* @param {Function} props.isThreatEligibleForIgnore - Function to determine if a threat is eligible for ignoring.
* @param {Function} props.isThreatEligibleForUnignore - Function to determine if a threat is eligible for unignoring.
* @param {JSX.Element} props.header - Header component.
*
* @return {JSX.Element} The ThreatsDataViews component.
*/
export default function ThreatsDataViews( {
status = 'current',
data,
filters,
initialFields = CURRENT_TABLE_FIELDS,
initialFilters = [],
onChangeSelection,
isThreatEligibleForFix,
isThreatEligibleForIgnore,
isThreatEligibleForUnignore,
onFixThreats,
onIgnoreThreats,
onUnignoreThreats,
header,
}: {
status?: string;
data: Threat[];
filters?: Filter[];
initialFields?: string[];
initialFilters?: Filter[];
onChangeSelection?: ( selectedItemIds: string[] ) => void;
isThreatEligibleForFix?: ( threat: Threat ) => boolean;
isThreatEligibleForIgnore?: ( threat: Threat ) => boolean;
isThreatEligibleForUnignore?: ( threat: Threat ) => boolean;
onFixThreats?: ( threats: Threat[] ) => void;
onIgnoreThreats?: ActionButton< Threat >[ 'callback' ];
onUnignoreThreats?: ActionButton< Threat >[ 'callback' ];
header?: JSX.Element;
} ): JSX.Element {
const baseView = {
sort: {
field: 'severity',
direction: 'desc' as SortDirection,
},
search: '',
filters: filters || [],
filters: initialFilters,
page: 1,
perPage: 20,
};
Expand All @@ -100,19 +112,14 @@ export default function ThreatsDataViews( {
const defaultLayouts: SupportedLayouts = {
table: {
...baseView,
fields: [ THREAT_FIELD_SEVERITY, THREAT_FIELD_TYPE, THREAT_FIELD_AUTO_FIX ],
fields: initialFields,
titleField: THREAT_FIELD_TITLE,
descriptionField: THREAT_FIELD_DESCRIPTION,
showMedia: false,
},
list: {
...baseView,
fields: [
THREAT_FIELD_SEVERITY,
THREAT_FIELD_TYPE,
THREAT_FIELD_EXTENSION,
THREAT_FIELD_SIGNATURE,
],
fields: LIST_FIELDS,
titleField: THREAT_FIELD_TITLE,
mediaField: THREAT_FIELD_ICON,
showMedia: true,
Expand Down Expand Up @@ -238,28 +245,6 @@ export default function ThreatsDataViews( {
);
},
},
{
id: THREAT_FIELD_STATUS,
label: __( 'Status', 'jetpack-components' ),
elements: THREAT_STATUSES,
getValue( { item }: { item: Threat } ) {
if ( ! item.status ) {
return 'current';
}
return (
THREAT_STATUSES.find( ( { value } ) => value === item.status )?.value ?? item.status
);
},
render( { item }: { item: Threat } ) {
if ( item.status ) {
const status = THREAT_STATUSES.find( ( { value } ) => value === item.status );
if ( status ) {
return <Badge variant={ status?.variant }>{ status.label }</Badge>;
}
}
return <Badge variant="warning">{ __( 'Active', 'jetpack-components' ) }</Badge>;
},
},
{
id: THREAT_FIELD_TYPE,
label: __( 'Type', 'jetpack-components' ),
Expand Down Expand Up @@ -300,6 +285,35 @@ export default function ThreatsDataViews( {
return item.extension ? item.extension.slug : '';
},
},
...( 'historic' === status && dataFields.includes( 'status' )
? [
{
id: THREAT_FIELD_STATUS,
label: __( 'Status', 'jetpack-components' ),
elements: THREAT_STATUSES,
getValue( { item }: { item: Threat } ) {
if ( ! item.status ) {
return 'current';
}
return (
THREAT_STATUSES.find( ( { value } ) => value === item.status )?.value ??
item.status
);
},
render( { item }: { item: Threat } ) {
if ( item.status ) {
const threatStatus = THREAT_STATUSES.find(
( { value } ) => value === item.status
);
if ( threatStatus ) {
return <Badge variant={ threatStatus?.variant }>{ threatStatus.label }</Badge>;
}
}
return <Badge variant="warning">{ __( 'Current', 'jetpack-components' ) }</Badge>;
},
},
]
: [] ),
...( dataFields.includes( 'severity' )
? [
{
Expand Down Expand Up @@ -366,7 +380,7 @@ export default function ThreatsDataViews( {
},
]
: [] ),
...( dataFields.includes( 'fixable' )
...( 'historic' !== status && dataFields.includes( 'fixable' )
? [
{
id: THREAT_FIELD_AUTO_FIX,
Expand Down Expand Up @@ -398,7 +412,7 @@ export default function ThreatsDataViews( {
];

return result;
}, [ dataFields, plugins, themes, signatures, onFixThreats ] );
}, [ dataFields, plugins, themes, signatures, status, onFixThreats ] );

/**
* DataView actions - collection of operations that can be performed upon each record.
Expand All @@ -408,10 +422,12 @@ export default function ThreatsDataViews( {
const actions = useMemo( () => {
const result: Action< Threat >[] = [];

if ( dataFields.includes( 'fixable' ) ) {
if ( dataFields.includes( 'fixable' ) && view.type === 'list' ) {
result.push( {
id: THREAT_ACTION_FIX,
label: __( 'Auto-fix', 'jetpack-components' ),
label: items => {
return getFixerAction( items[ 0 ] );
},
isPrimary: true,
callback: onFixThreats,
isEligible( item ) {
Expand Down Expand Up @@ -466,6 +482,7 @@ export default function ThreatsDataViews( {

return result;
}, [
view.type,
dataFields,
onFixThreats,
onIgnoreThreats,
Expand Down Expand Up @@ -511,13 +528,7 @@ export default function ThreatsDataViews( {
onChangeView={ onChangeView }
paginationInfo={ paginationInfo }
view={ view }
header={
<ThreatsStatusToggleGroupControl
data={ data }
view={ view }
onChangeView={ onChangeView }
/>
}
header={ header }
/>
);
}
Loading