@@ -148,7 +148,7 @@ import {
148148 SEVERITY_DOT_COLOR ,
149149 healthColors ,
150150} from './resource-utils'
151- import { TRIVY_GROUP , searchTrivyFindings , type TrivyFindingMatch } from './resource-utils-trivy'
151+ import { TRIVY_GROUP , searchTrivyFindings , type TrivyFindingMatch , type TrivyFindingsSearch } from './resource-utils-trivy'
152152import { getGenericResourceStatus } from './generic-status'
153153import { ActiveFilterBar } from './ActiveFilterBar'
154154import { getIstioGatewayServerCount , getIstioGatewaySelectorString } from './resource-utils-istio'
@@ -5463,21 +5463,18 @@ export function ResourcesView({
54635463 }
54645464 } , [ regexMode , deferredSearchTerm ] )
54655465
5466- // Regex mode stays on names: a pattern run over every finding could
5467- // backtrack for seconds on the main thread.
54685466 const isTrivyKind = selectedKind . group === TRIVY_GROUP
5469- const findingsSearch = useMemo ( ( ) => {
5470- if ( ! tableActive || ! resources || ! deferredSearchTerm || regexMode || ! isTrivyKind ) return null
5471- return searchTrivyFindings ( resources , deferredSearchTerm . toLowerCase ( ) )
5472- } , [ tableActive , resources , deferredSearchTerm , regexMode , isTrivyKind ] )
54735467
54745468 // Filter resources by search term, status, problems, and sort
5475- const filteredResources = useMemo ( ( ) => {
5476- if ( ! tableActive || ! resources ) return [ ]
5469+ const { list : filteredResources , findings : findingsSearch } = useMemo ( ( ) : { list : any [ ] ; findings : TrivyFindingsSearch | null } => {
5470+ if ( ! tableActive || ! resources ) return { list : [ ] , findings : null }
54775471
54785472 let result = resources
5473+ let findings : TrivyFindingsSearch | null = null
54795474
5480- // Apply search filter
5475+ // Apply search filter. On Trivy report kinds a plain search also matches
5476+ // findings and runs below, after the other filters. Regex mode stays on
5477+ // names: a pattern run over every finding could backtrack for seconds.
54815478 if ( deferredSearchTerm ) {
54825479 if ( regexMode ) {
54835480 const re = searchRegex . re
@@ -5487,12 +5484,11 @@ export function ResourcesView({
54875484 re . test ( r . metadata ?. namespace ?? '' )
54885485 )
54895486 }
5490- } else {
5487+ } else if ( ! isTrivyKind ) {
54915488 const term = deferredSearchTerm . toLowerCase ( )
54925489 result = result . filter ( ( r : any ) =>
54935490 r . metadata ?. name ?. toLowerCase ( ) . includes ( term ) ||
5494- r . metadata ?. namespace ?. toLowerCase ( ) . includes ( term ) ||
5495- ! ! findingsSearch ?. matches . has ( r )
5491+ r . metadata ?. namespace ?. toLowerCase ( ) . includes ( term )
54965492 )
54975493 }
54985494 }
@@ -5564,6 +5560,19 @@ export function ResourcesView({
55645560 } )
55655561 }
55665562
5563+ // Trivy findings are searched after the other filters, so rows they hide
5564+ // don't spend the findings budget.
5565+ if ( deferredSearchTerm && ! regexMode && isTrivyKind ) {
5566+ const term = deferredSearchTerm . toLowerCase ( )
5567+ const matched = searchTrivyFindings ( result , term )
5568+ findings = matched
5569+ result = result . filter ( ( r : any ) =>
5570+ r . metadata ?. name ?. toLowerCase ( ) . includes ( term ) ||
5571+ r . metadata ?. namespace ?. toLowerCase ( ) . includes ( term ) ||
5572+ matched . matches . has ( r )
5573+ )
5574+ }
5575+
55675576 // Apply custom sorting if set. Extra columns override
55685577 // the built-in getSortValue for their key.
55695578 if ( effectiveSortColumn && sortDirection ) {
@@ -5659,8 +5668,8 @@ export function ResourcesView({
56595668 }
56605669 }
56615670
5662- return result
5663- } , [ tableActive , resources , deferredSearchTerm , regexMode , searchRegex , findingsSearch , columnFilters , columnFilterExcludes , problemFilters , showInactiveReplicaSets , labelSelector , ownerKind , ownerName , selectedKind . name , effectiveSortColumn , sortDirection , getSortValue , getDisplayFilterValue , extraColumnsByKey , podMatchesProblemFilter ] )
5671+ return { list : result , findings }
5672+ } , [ tableActive , resources , deferredSearchTerm , regexMode , searchRegex , isTrivyKind , columnFilters , columnFilterExcludes , problemFilters , showInactiveReplicaSets , labelSelector , ownerKind , ownerName , selectedKind . name , effectiveSortColumn , sortDirection , getSortValue , getDisplayFilterValue , extraColumnsByKey , podMatchesProblemFilter ] )
56645673
56655674 // For nodes table: compute the majority minor version so outliers can be highlighted
56665675 const majorityNodeMinorVersion = useMemo ( ( ) => {
@@ -6630,7 +6639,7 @@ export function ResourcesView({
66306639 </ button >
66316640 ) }
66326641 { searchTerm && isTrivyKind && (
6633- < p className = "text-xs mt-1 text-theme-text-disabled " >
6642+ < p className = "text-xs mt-1 text-theme-text-tertiary " >
66346643 { regexMode
66356644 ? 'Regex search matches names and namespaces only.'
66366645 : 'Searched names, namespaces and report findings (CVE, package, check ID, image).' }
0 commit comments