15
15
*/
16
16
17
17
import 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'
19
29
import DeleteResourcePopup from './DeleteResourcePopup'
20
30
import { importComponentFromFELibrary , getShowResourceScanModal } from '../../common'
21
31
import { RESOURCE_ACTION_MENU } from '../Constants'
@@ -28,8 +38,25 @@ import { ReactComponent as DeleteIcon } from '../../../assets/icons/ic-delete-in
28
38
import { ReactComponent as MenuDots } from '../../../assets/icons/appstatus/ic-menu-dots.svg'
29
39
import { NodeType } from '../../v2/appDetails/appDetails.type'
30
40
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
+ )
33
60
34
61
const ResourceBrowserActionMenu : React . FC < ResourceBrowserActionMenuType > = ( {
35
62
clusterId,
@@ -41,9 +68,25 @@ const ResourceBrowserActionMenu: React.FC<ResourceBrowserActionMenuType> = ({
41
68
} ) => {
42
69
const { installedModuleMap } = useMainContext ( )
43
70
71
+ const isSecurityScanV2Enabled = window . _env_ . ENABLE_RESOURCE_SCAN_V2 && isFELibAvailable
72
+
44
73
const [ showDeleteDialog , setShowDeleteDialog ] = useState ( false )
45
74
const [ showVulnerabilityModal , setShowVulnerabilityModal ] = useState ( false )
46
75
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
+
47
90
const toggleDeleteDialog = ( ) => {
48
91
setShowDeleteDialog ( ( prevState ) => ! prevState )
49
92
}
@@ -56,10 +99,12 @@ const ResourceBrowserActionMenu: React.FC<ResourceBrowserActionMenuType> = ({
56
99
setShowVulnerabilityModal ( false )
57
100
}
58
101
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
+
63
108
return (
64
109
< >
65
110
< PopupMenu autoClose >
@@ -141,17 +186,15 @@ const ResourceBrowserActionMenu: React.FC<ResourceBrowserActionMenuType> = ({
141
186
/>
142
187
) }
143
188
144
- { showVulnerabilityModal && SecurityModal && (
189
+ { showVulnerabilityModal && ! ! isFELibAvailable && (
145
190
< 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
154
192
handleModalClose = { handleCloseVulnerabilityModal }
193
+ Sidebar = { SecurityModalSidebar }
194
+ isSecurityScanV2Enabled = { isSecurityScanV2Enabled }
195
+ isLoading = { resourceScanLoading }
196
+ error = { resourceScanError }
197
+ responseData = { resourceScanResponse ?. result }
155
198
/>
156
199
) }
157
200
</ >
0 commit comments