1515 */
1616
1717import React , { useState } from 'react'
18- import { PopupMenu , Nodes , useMainContext , ModuleNameMap } from '@devtron-labs/devtron-fe-common-lib'
18+ import {
19+ PopupMenu ,
20+ Nodes ,
21+ useMainContext ,
22+ ModuleNameMap ,
23+ SecurityModal ,
24+ ResponseType ,
25+ ApiResponseResultType ,
26+ GetResourceScanDetailsPayloadType ,
27+ useAsync ,
28+ } from '@devtron-labs/devtron-fe-common-lib'
1929import DeleteResourcePopup from './DeleteResourcePopup'
2030import { importComponentFromFELibrary , getShowResourceScanModal } from '../../common'
2131import { RESOURCE_ACTION_MENU } from '../Constants'
@@ -28,8 +38,25 @@ import { ReactComponent as DeleteIcon } from '../../../assets/icons/ic-delete-in
2838import { ReactComponent as MenuDots } from '../../../assets/icons/appstatus/ic-menu-dots.svg'
2939import { NodeType } from '../../v2/appDetails/appDetails.type'
3040
31- const OpenSecurityModalButton = importComponentFromFELibrary ( 'OpenSecurityModalButton' )
32- const SecurityModal = importComponentFromFELibrary ( 'SecurityModal' )
41+ const OpenSecurityModalButton = importComponentFromFELibrary ( 'OpenSecurityModalButton' , null , 'function' )
42+ const isFELibAvailable = importComponentFromFELibrary ( 'isFELibAvailable' , false , 'function' )
43+ const SecurityModalSidebar = importComponentFromFELibrary ( 'SecurityModalSidebar' , null , 'function' )
44+ const getResourceScanDetails : ( {
45+ name,
46+ namespace,
47+ clusterId,
48+ group,
49+ version,
50+ kind,
51+ appId,
52+ appType,
53+ deploymentType,
54+ isAppDetailView,
55+ } : GetResourceScanDetailsPayloadType ) => Promise < ResponseType < ApiResponseResultType > > = importComponentFromFELibrary (
56+ 'getResourceScanDetails' ,
57+ null ,
58+ 'function' ,
59+ )
3360
3461const ResourceBrowserActionMenu : React . FC < ResourceBrowserActionMenuType > = ( {
3562 clusterId,
@@ -41,9 +68,25 @@ const ResourceBrowserActionMenu: React.FC<ResourceBrowserActionMenuType> = ({
4168} ) => {
4269 const { installedModuleMap } = useMainContext ( )
4370
71+ const isSecurityScanV2Enabled = window . _env_ . ENABLE_RESOURCE_SCAN_V2 && isFELibAvailable
72+
4473 const [ showDeleteDialog , setShowDeleteDialog ] = useState ( false )
4574 const [ showVulnerabilityModal , setShowVulnerabilityModal ] = useState ( false )
4675
76+ const [ resourceScanLoading , resourceScanResponse , resourceScanError ] = useAsync (
77+ ( ) =>
78+ getResourceScanDetails ( {
79+ name : String ( resourceData . name ) ,
80+ namespace : String ( resourceData . namespace ) ,
81+ group : selectedResource ?. gvk ?. Group ,
82+ kind : selectedResource ?. gvk ?. Kind ,
83+ version : selectedResource ?. gvk ?. Version ,
84+ clusterId : + clusterId ,
85+ } ) ,
86+ [ ] ,
87+ showVulnerabilityModal && getResourceScanDetails && isSecurityScanV2Enabled ,
88+ )
89+
4790 const toggleDeleteDialog = ( ) => {
4891 setShowDeleteDialog ( ( prevState ) => ! prevState )
4992 }
@@ -56,10 +99,12 @@ const ResourceBrowserActionMenu: React.FC<ResourceBrowserActionMenuType> = ({
5699 setShowVulnerabilityModal ( false )
57100 }
58101
59- const showResourceScanModal = getShowResourceScanModal (
60- selectedResource ?. gvk ?. Kind as NodeType ,
61- installedModuleMap . current ?. [ ModuleNameMap . SECURITY_TRIVY ] ,
62- )
102+ const showResourceScanModal =
103+ getShowResourceScanModal (
104+ selectedResource ?. gvk ?. Kind as NodeType ,
105+ installedModuleMap . current ?. [ ModuleNameMap . SECURITY_TRIVY ] ,
106+ ) && window . _env_ . ENABLE_RESOURCE_SCAN_V2
107+
63108 return (
64109 < >
65110 < PopupMenu autoClose >
@@ -141,17 +186,15 @@ const ResourceBrowserActionMenu: React.FC<ResourceBrowserActionMenuType> = ({
141186 />
142187 ) }
143188
144- { showVulnerabilityModal && SecurityModal && (
189+ { showVulnerabilityModal && ! ! isFELibAvailable && (
145190 < SecurityModal
146- resourceScanPayload = { {
147- name : resourceData . name ,
148- namespace : resourceData . namespace ,
149- group : selectedResource ?. gvk ?. Group ,
150- kind : selectedResource ?. gvk ?. Kind ,
151- version : selectedResource ?. gvk ?. Version ,
152- clusterId,
153- } }
191+ isResourceScan
154192 handleModalClose = { handleCloseVulnerabilityModal }
193+ Sidebar = { SecurityModalSidebar }
194+ isSecurityScanV2Enabled = { isSecurityScanV2Enabled }
195+ isLoading = { resourceScanLoading }
196+ error = { resourceScanError }
197+ responseData = { resourceScanResponse ?. result }
155198 />
156199 ) }
157200 </ >
0 commit comments