Skip to content

Commit

Permalink
Add historic flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmyta committed Jan 3, 2025
1 parent 4afa6fc commit 6db0f6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import styles from './styles.module.scss';
* DataViews component for displaying security threats.
*
* @param {object} props - Component props.
* @param {boolean} props.historic - Flag to indicate if the threats are historic.
* @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.
Expand All @@ -59,6 +60,7 @@ import styles from './styles.module.scss';
* @return {JSX.Element} The ThreatsDataViews component.
*/
export default function ThreatsDataViews( {
historic = false,
data,
filters,
onChangeSelection,
Expand All @@ -70,6 +72,7 @@ export default function ThreatsDataViews( {
onUnignoreThreats,
header,
}: {
historic?: boolean;
data: Threat[];
filters?: Filter[];
onChangeSelection?: ( selectedItemIds: string[] ) => void;
Expand Down Expand Up @@ -102,7 +105,14 @@ export default function ThreatsDataViews( {
const defaultLayouts: SupportedLayouts = {
table: {
...baseView,
fields: [ THREAT_FIELD_SEVERITY, THREAT_FIELD_TYPE, THREAT_FIELD_AUTO_FIX ],
fields: historic
? [
THREAT_FIELD_SEVERITY,
THREAT_FIELD_TYPE,
THREAT_FIELD_FIRST_DETECTED,
THREAT_FIELD_FIXED_ON,
]
: [ THREAT_FIELD_SEVERITY, THREAT_FIELD_TYPE, THREAT_FIELD_AUTO_FIX ],
titleField: THREAT_FIELD_TITLE,
descriptionField: THREAT_FIELD_DESCRIPTION,
showMedia: false,
Expand Down Expand Up @@ -280,7 +290,7 @@ export default function ThreatsDataViews( {
return item.extension ? item.extension.slug : '';
},
},
...( dataFields.includes( 'status' )
...( historic && dataFields.includes( 'status' )
? [
{
id: THREAT_FIELD_STATUS,
Expand Down Expand Up @@ -373,7 +383,7 @@ export default function ThreatsDataViews( {
},
]
: [] ),
...( dataFields.includes( 'fixable' )
...( ! historic && dataFields.includes( 'fixable' )
? [
{
id: THREAT_FIELD_AUTO_FIX,
Expand Down Expand Up @@ -405,7 +415,7 @@ export default function ThreatsDataViews( {
];

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

/**
* DataView actions - collection of operations that can be performed upon each record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function HistoryDataViews() {

return (
<ThreatsDataViews
historic
data={ history ? history.threats : [] }
filters={ filters }
onUnignoreThreats={ onUnignoreThreats }
Expand Down

0 comments on commit 6db0f6f

Please sign in to comment.