|
1 |
| -import { getThreatType, type Threat, type ThreatStatus } from '@automattic/jetpack-scan'; |
| 1 | +import { getThreatType, type Threat } from '@automattic/jetpack-scan'; |
2 | 2 | import {
|
3 | 3 | type Action,
|
4 | 4 | type ActionButton,
|
@@ -238,6 +238,28 @@ export default function ThreatsDataViews( {
|
238 | 238 | );
|
239 | 239 | },
|
240 | 240 | },
|
| 241 | + { |
| 242 | + id: THREAT_FIELD_STATUS, |
| 243 | + label: __( 'Status', 'jetpack-components' ), |
| 244 | + elements: THREAT_STATUSES, |
| 245 | + getValue( { item }: { item: Threat } ) { |
| 246 | + if ( ! item.status ) { |
| 247 | + return 'current'; |
| 248 | + } |
| 249 | + return ( |
| 250 | + THREAT_STATUSES.find( ( { value } ) => value === item.status )?.value ?? item.status |
| 251 | + ); |
| 252 | + }, |
| 253 | + render( { item }: { item: Threat } ) { |
| 254 | + if ( item.status ) { |
| 255 | + const status = THREAT_STATUSES.find( ( { value } ) => value === item.status ); |
| 256 | + if ( status ) { |
| 257 | + return <Badge variant={ status?.variant }>{ status.label }</Badge>; |
| 258 | + } |
| 259 | + } |
| 260 | + return <Badge variant="warning">{ __( 'Active', 'jetpack-components' ) }</Badge>; |
| 261 | + }, |
| 262 | + }, |
241 | 263 | {
|
242 | 264 | id: THREAT_FIELD_TYPE,
|
243 | 265 | label: __( 'Type', 'jetpack-components' ),
|
@@ -278,33 +300,6 @@ export default function ThreatsDataViews( {
|
278 | 300 | return item.extension ? item.extension.slug : '';
|
279 | 301 | },
|
280 | 302 | },
|
281 |
| - ...( dataFields.includes( 'status' ) |
282 |
| - ? [ |
283 |
| - { |
284 |
| - id: THREAT_FIELD_STATUS, |
285 |
| - label: __( 'Status', 'jetpack-components' ), |
286 |
| - elements: THREAT_STATUSES, |
287 |
| - getValue( { item }: { item: Threat } ) { |
288 |
| - if ( ! item.status ) { |
289 |
| - return 'current'; |
290 |
| - } |
291 |
| - return ( |
292 |
| - THREAT_STATUSES.find( ( { value } ) => value === item.status )?.value ?? |
293 |
| - item.status |
294 |
| - ); |
295 |
| - }, |
296 |
| - render( { item }: { item: Threat } ) { |
297 |
| - if ( item.status ) { |
298 |
| - const status = THREAT_STATUSES.find( ( { value } ) => value === item.status ); |
299 |
| - if ( status ) { |
300 |
| - return <Badge variant={ status?.variant }>{ status.label }</Badge>; |
301 |
| - } |
302 |
| - } |
303 |
| - return <Badge variant="warning">{ __( 'Active', 'jetpack-components' ) }</Badge>; |
304 |
| - }, |
305 |
| - }, |
306 |
| - ] |
307 |
| - : [] ), |
308 | 303 | ...( dataFields.includes( 'severity' )
|
309 | 304 | ? [
|
310 | 305 | {
|
@@ -480,33 +475,6 @@ export default function ThreatsDataViews( {
|
480 | 475 | isThreatEligibleForUnignore,
|
481 | 476 | ] );
|
482 | 477 |
|
483 |
| - /** |
484 |
| - * Memoized function to determine if a status filter is selected. |
485 |
| - * |
486 |
| - * @param {Array} threatStatuses - List of threat statuses. |
487 |
| - */ |
488 |
| - const isStatusFilterSelected = useMemo( |
489 |
| - () => ( threatStatuses: ThreatStatus[] ) => |
490 |
| - view.filters.some( |
491 |
| - filter => |
492 |
| - filter.field === 'status' && |
493 |
| - Array.isArray( filter.value ) && |
494 |
| - filter.value.length === threatStatuses.length && |
495 |
| - threatStatuses.every( threatStatus => filter.value.includes( threatStatus ) ) |
496 |
| - ), |
497 |
| - [ view.filters ] |
498 |
| - ); |
499 |
| - |
500 |
| - const selectedStatusFilter = useMemo( () => { |
501 |
| - if ( isStatusFilterSelected( [ 'current' ] ) ) { |
502 |
| - return 'active' as const; |
503 |
| - } |
504 |
| - if ( isStatusFilterSelected( [ 'fixed', 'ignored' ] ) ) { |
505 |
| - return 'historic' as const; |
506 |
| - } |
507 |
| - return null; |
508 |
| - }, [ isStatusFilterSelected ] ); |
509 |
| - |
510 | 478 | /**
|
511 | 479 | * Apply the view settings (i.e. filters, sorting, pagination) to the dataset.
|
512 | 480 | *
|
@@ -548,7 +516,6 @@ export default function ThreatsDataViews( {
|
548 | 516 | data={ data }
|
549 | 517 | view={ view }
|
550 | 518 | onChangeView={ onChangeView }
|
551 |
| - selectedStatusFilter={ selectedStatusFilter } |
552 | 519 | />
|
553 | 520 | }
|
554 | 521 | />
|
|
0 commit comments