@@ -27,6 +27,7 @@ import { DEFAULT_SECURITY_MODAL_IMAGE_STATE } from '../SecurityModal/constants'
2727import { CATEGORIES , SecurityModalStateType , SUB_CATEGORIES } from '../SecurityModal/types'
2828import { ScanCategories , ScanSubCategories } from '../types'
2929import { getCompiledSecurityThreats , getSecurityConfig , getStatusForScanList , getTotalSeverities } from '../utils'
30+ import { ReportTabEmptyState } from './ReportTabEmptyState'
3031import SecurityCard from './SecurityCard'
3132import { SecurityCardProps , SecurityDetailsCardsProps } from './types'
3233
@@ -40,22 +41,6 @@ const SecurityDetailsCards = ({ scanResult, Sidebar }: SecurityDetailsCardsProps
4041 const scanThreats = getCompiledSecurityThreats ( scanResult )
4142 const threatCount = getTotalSeverities ( scanThreats )
4243
43- if ( ! threatCount ) {
44- return (
45- < GenericEmptyState
46- SvgImage = { NoVulnerability }
47- title = { EMPTY_STATE_STATUS . CI_DEATILS_NO_VULNERABILITY_FOUND . TITLE }
48- subTitle = { EMPTY_STATE_STATUS . CI_DEATILS_NO_VULNERABILITY_FOUND . SUBTITLE }
49- />
50- )
51- }
52-
53- const SECURITY_CONFIG = getSecurityConfig ( {
54- imageScan : ! ! imageScan ,
55- codeScan : ! ! codeScan ,
56- kubernetesManifest : ! ! kubernetesManifest ,
57- } )
58-
5944 const getScanToolInfo = ( category : string ) : { scanToolName : string ; scanToolUrl : string } => {
6045 const image = imageScan ?. vulnerability ?. list ?. [ 0 ]
6146 switch ( category ) {
@@ -71,6 +56,49 @@ const SecurityDetailsCards = ({ scanResult, Sidebar }: SecurityDetailsCardsProps
7156 }
7257 }
7358
59+ const renderScannedToolModal = ( category : ScanCategories ) => {
60+ const { scanToolName, scanToolUrl } = getScanToolInfo ( category )
61+ return < ScannedByToolModal scanToolName = { scanToolName } scanToolUrl = { scanToolUrl } />
62+ }
63+
64+ const renderHeader = ( category ?: ScanCategories ) => (
65+ < div className = "flexbox dc__content-space pb-8 dc__border-bottom-n1" >
66+ < span className = "fs-13 fw-6 lh-1-5 cn-9" > Security Scan</ span >
67+ { category && renderScannedToolModal ( category ) }
68+ </ div >
69+ )
70+
71+ if ( ! scanResult ?. scanned ) {
72+ return (
73+ < div className = "flexbox-col dc__gap-16 mw-600 dc__mxw-1000" >
74+ < ReportTabEmptyState
75+ title = { EMPTY_STATE_STATUS . CI_DETAILS_IMAGE_NOT_SCANNED . TITLE }
76+ subtitle = { EMPTY_STATE_STATUS . CI_DETAILS_IMAGE_NOT_SCANNED . SUBTITLE }
77+ />
78+ </ div >
79+ )
80+ }
81+
82+ if ( ! threatCount ) {
83+ return (
84+ < div className = "flexbox-col dc__gap-16 mw-600 dc__mxw-1000" >
85+ < div className = "flexbox-col en-2 bw-1 br-8 dc__gap-16 cn-9 p-16" >
86+ < GenericEmptyState
87+ SvgImage = { NoVulnerability }
88+ title = { EMPTY_STATE_STATUS . CI_DEATILS_NO_VULNERABILITY_FOUND . TITLE }
89+ subTitle = { EMPTY_STATE_STATUS . CI_DEATILS_NO_VULNERABILITY_FOUND . SUBTITLE }
90+ />
91+ </ div >
92+ </ div >
93+ )
94+ }
95+
96+ const SECURITY_CONFIG = getSecurityConfig ( {
97+ imageScan : ! ! imageScan ,
98+ codeScan : ! ! codeScan ,
99+ kubernetesManifest : ! ! kubernetesManifest ,
100+ } )
101+
74102 const handleOpenModal = (
75103 category : SecurityCardProps [ 'category' ] ,
76104 subCategory : SecurityCardProps [ 'subCategory' ] ,
@@ -91,64 +119,57 @@ const SecurityDetailsCards = ({ scanResult, Sidebar }: SecurityDetailsCardsProps
91119 setShowSecurityModal ( false )
92120 }
93121
122+ const renderSecurityCards = ( { category, categoryFailed } ) =>
123+ categoryFailed ? (
124+ < div className = "dc__border br-8" >
125+ < GenericSectionErrorState
126+ title = { category === CATEGORIES . CODE_SCAN ? 'Code scan failed' : 'Manifest scan failed' }
127+ subTitle = ""
128+ description = ""
129+ />
130+ </ div >
131+ ) : (
132+ < div className = "dc__grid security-cards" >
133+ { SECURITY_CONFIG [ category ] . subCategories . map ( ( subCategory : ScanSubCategories ) => {
134+ // Explicit handling if subcategory is null
135+ if ( ! scanResult [ category ] [ subCategory ] ) {
136+ return null
137+ }
138+
139+ const scanFailed : boolean =
140+ category === CATEGORIES . IMAGE_SCAN &&
141+ getStatusForScanList ( scanResult [ category ] [ subCategory ] . list ?? [ ] ) === 'Failed'
142+
143+ const severities =
144+ subCategory === SUB_CATEGORIES . MISCONFIGURATIONS
145+ ? scanResult [ category ] [ subCategory ] ?. misConfSummary ?. status
146+ : scanResult [ category ] [ subCategory ] ?. summary ?. severities
147+
148+ return (
149+ < SecurityCard
150+ category = { category }
151+ subCategory = { subCategory }
152+ severities = { severities }
153+ handleCardClick = { handleCardClick ( category , subCategory ) }
154+ scanFailed = { scanFailed }
155+ />
156+ )
157+ } ) }
158+ </ div >
159+ )
160+
94161 return (
95162 < >
96- < div className = "flexbox-col dc__gap-20 mw-600 dc__mxw-1200 " >
163+ < div className = "flexbox-col dc__gap-20" >
97164 { Object . keys ( SECURITY_CONFIG ) . map ( ( category : ScanCategories ) => {
98165 const categoryFailed : boolean =
99166 category !== CATEGORIES . IMAGE_SCAN &&
100167 ( scanResult . codeScan ?. status === 'Failed' || scanResult . kubernetesManifest ?. status === 'Failed' )
101168
102- const { scanToolName, scanToolUrl } = getScanToolInfo ( category )
103-
104169 return (
105170 < div className = "flexbox-col dc__gap-12" key = { category } >
106- < div className = "flexbox dc__content-space pb-8 dc__border-bottom-n1" >
107- < span className = "fs-13 fw-6 lh-1-5 cn-9" > { SECURITY_CONFIG [ category ] . label } </ span >
108- < ScannedByToolModal scanToolName = { scanToolName } scanToolUrl = { scanToolUrl } />
109- </ div >
110- { categoryFailed ? (
111- < div className = "dc__border br-8" >
112- < GenericSectionErrorState
113- title = {
114- category === CATEGORIES . CODE_SCAN
115- ? 'Code scan failed'
116- : 'Manifest scan failed'
117- }
118- subTitle = ""
119- description = ""
120- />
121- </ div >
122- ) : (
123- < div className = "dc__grid security-cards" >
124- { SECURITY_CONFIG [ category ] . subCategories . map ( ( subCategory : ScanSubCategories ) => {
125- // Explicit handling if subcategory is null
126- if ( ! scanResult [ category ] [ subCategory ] ) {
127- return null
128- }
129-
130- const scanFailed : boolean =
131- category === CATEGORIES . IMAGE_SCAN &&
132- getStatusForScanList ( scanResult [ category ] [ subCategory ] . list ?? [ ] ) ===
133- 'Failed'
134-
135- const severities =
136- subCategory === SUB_CATEGORIES . MISCONFIGURATIONS
137- ? scanResult [ category ] [ subCategory ] ?. misConfSummary ?. status
138- : scanResult [ category ] [ subCategory ] ?. summary ?. severities
139-
140- return (
141- < SecurityCard
142- category = { category }
143- subCategory = { subCategory }
144- severities = { severities }
145- handleCardClick = { handleCardClick ( category , subCategory ) }
146- scanFailed = { scanFailed }
147- />
148- )
149- } ) }
150- </ div >
151- ) }
171+ { renderHeader ( category ) }
172+ { renderSecurityCards ( { category, categoryFailed } ) }
152173 </ div >
153174 )
154175 } ) }
0 commit comments