Skip to content

Commit bd56c7d

Browse files
committed
feat: move sidebar and scan-result api to fe-lib
1 parent 601e7c9 commit bd56c7d

File tree

17 files changed

+121
-244
lines changed

17 files changed

+121
-244
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.3.5-beta-3",
3+
"version": "0.3.5-beta-6",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ export const ROUTES = {
107107
PLUGIN_GLOBAL_LIST_DETAIL_V2: 'plugin/global/list/detail/v2',
108108
PLUGIN_GLOBAL_LIST_V2: 'plugin/global/list/v2',
109109
PLUGIN_GLOBAL_LIST_TAGS: 'plugin/global/list/tags',
110-
K8S_RESOURCE_SECURITY: 'k8s/resource/security',
111-
SCAN_RESULT: 'scan-result',
112110
PLUGIN_LIST_MIN: 'plugin/global/list/v2/min',
113111
DEPLOYMENT_CHARTS_LIST: 'deployment/template/fetch',
114112
USER_LIST_MIN: 'user/list/min',

src/Shared/Components/ImageCardAccordion/ImageCardAccordion.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const ImageCardAccordion = ({
4949
isScanned,
5050
isScanEnabled,
5151
isScanV2Enabled,
52+
SecurityModalSidebar,
53+
getSecurityScan,
5254
}: ImageCardAccordionProps) => {
5355
const [isOpened, setIsOpened] = useState<boolean>(false)
5456
const [activeTab, setActiveTab] = useState<CDModalTabType>(CDModalTab.Changes)
@@ -76,6 +78,8 @@ const ImageCardAccordion = ({
7678
environmentId={environmentId}
7779
setVulnerabilityCount={setVulnerabilityCount}
7880
isScanV2Enabled={isScanV2Enabled}
81+
SecurityModalSidebar={SecurityModalSidebar}
82+
getSecurityScan={getSecurityScan}
7983
/>
8084
)
8185
}

src/Shared/Components/ImageCardAccordion/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616

1717
import React, { ReactNode } from 'react'
18-
import { CDModalTabType, VulnerabilityType } from '../../../Common'
18+
import { CDModalTabType, ResponseType, VulnerabilityType } from '../../../Common'
1919
import { MaterialSecurityInfoType } from '../../types'
20+
import { ApiResponseResultType, AppDetailsPayload, SidebarPropsType } from '../Security'
2021

2122
export interface ImageCardAccordionProps extends MaterialSecurityInfoType {
2223
isSecurityModuleInstalled: boolean
@@ -27,6 +28,8 @@ export interface ImageCardAccordionProps extends MaterialSecurityInfoType {
2728
isScanned: boolean
2829
isScanEnabled: boolean
2930
isScanV2Enabled: boolean
31+
SecurityModalSidebar: React.FC<SidebarPropsType>
32+
getSecurityScan: ({ appId, envId, artifactId }: AppDetailsPayload) => Promise<ResponseType<ApiResponseResultType>>
3033
}
3134

3235
export interface SecurityDetailsType {

src/Shared/Components/Security/SecurityModal/SecurityModal.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import React, { useState } from 'react'
66
import {
77
ErrorScreenManager,
88
ClipboardButton,
9-
useAsync,
109
GenericEmptyState,
1110
ImageType,
1211
Progressing,
@@ -15,9 +14,8 @@ import {
1514
} from '@Common/index'
1615
import { ReactComponent as ICClose } from '@Icons/ic-close.svg'
1716
import { ReactComponent as ICBack } from '@Icons/ic-caret-down.svg'
18-
import { Sidebar, Table, InfoCard } from './components'
17+
import { Table, InfoCard } from './components'
1918
import { DEFAULT_SECURITY_MODAL_STATE } from './constants'
20-
import { getExecutionDetails, getResourceScanDetails, getSecurityScan } from './service'
2119
import { getTableData, getInfoCardData } from './config'
2220
import { SecurityModalPropsType, SecurityModalStateType, DetailViewDataType } from './types'
2321
import { getEmptyStateValues } from './config/EmptyState'
@@ -34,25 +32,19 @@ import './styles.scss'
3432
* For further detail please refer the types to understand the Api Response and workflow of the modal component.
3533
* */
3634
const SecurityModal: React.FC<SecurityModalPropsType> = ({
37-
appDetailsPayload,
38-
resourceScanPayload,
39-
executionDetailsPayload,
35+
Sidebar,
4036
handleModalClose,
41-
isExternalCI,
37+
isLoading,
38+
error,
39+
responseData,
40+
isResourceScan = false,
41+
isHelmApp = false,
42+
isSecurityScanV2Enabled = false,
43+
isExternalCI = false,
4244
}) => {
4345
const [state, setState] = useState<SecurityModalStateType>(DEFAULT_SECURITY_MODAL_STATE)
4446

45-
const [loading, _data, error] = useAsync(() => {
46-
if (appDetailsPayload) {
47-
return getSecurityScan(appDetailsPayload)
48-
}
49-
if (executionDetailsPayload) {
50-
return getExecutionDetails(executionDetailsPayload)
51-
}
52-
return getResourceScanDetails(resourceScanPayload)
53-
})
54-
55-
const data = _data?.result || null
47+
const data = responseData ?? null
5648

5749
const setDetailViewData = (detailViewData: DetailViewDataType) => {
5850
setState((prevState) => ({
@@ -140,7 +132,7 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
140132
}
141133

142134
const renderContent = () => {
143-
if (loading) {
135+
if (isLoading) {
144136
return (
145137
<div className="h-100 w-100 flex">
146138
<Progressing size={24} pageLoader />
@@ -160,9 +152,9 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
160152
/* NOTE: the height is restricted to (viewport - header) height since we need overflow-scroll */
161153
<div className="flexbox" style={{ height: 'calc(100vh - 49px)' }}>
162154
{/* NOTE: only show sidebar in AppDetails */}
163-
{appDetailsPayload && (
155+
{isSecurityScanV2Enabled && !isResourceScan && Sidebar && (
164156
<Sidebar
165-
isHelmApp={!!appDetailsPayload?.installedAppId}
157+
isHelmApp={isHelmApp}
166158
modalState={state}
167159
setModalState={setState}
168160
isExternalCI={isExternalCI}
@@ -180,7 +172,7 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
180172
return (
181173
<VisibleModal2 className="dc__position-rel" close={handleModalClose}>
182174
<div
183-
className={`${resourceScanPayload ? 'w-800' : 'w-1024'} h-100vh bcn-0 flexbox-col dc__right-0 dc__top-0 dc__position-abs`}
175+
className={`${isResourceScan ? 'w-800' : 'w-1024'} h-100vh bcn-0 flexbox-col dc__right-0 dc__top-0 dc__position-abs`}
184176
onClick={stopPropagation}
185177
>
186178
{renderHeader()}

src/Shared/Components/Security/SecurityModal/components/Sidebar.tsx

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/Shared/Components/Security/SecurityModal/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright (c) 2024. Devtron Inc.
33
*/
44

5-
export { default as Sidebar } from './Sidebar'
65
export { default as Table } from './Table'
76
export { default as InfoCard } from './InfoCard'
87
export { default as OpenDetailViewButton } from './OpenDetailViewButton'

src/Shared/Components/Security/SecurityModal/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
*/
44

55
export { default as SecurityModal } from './SecurityModal'
6-
export { getSecurityScan } from './service'
7-
export { getSecurityScanSeveritiesCount } from './utils'
8-
export type { AppDetailsPayload, ExecutionDetailsPayload, ApiResponseResultType } from './types'
6+
export {
7+
getSecurityScanSeveritiesCount,
8+
getTotalVulnerabilityCount,
9+
parseGetResourceScanDetailsResponse,
10+
parseExecutionDetailResponse,
11+
} from './utils'
12+
export type {
13+
AppDetailsPayload,
14+
ExecutionDetailsPayload,
15+
ApiResponseResultType,
16+
SidebarPropsType,
17+
SidebarDataChildType,
18+
SidebarDataType,
19+
GetResourceScanDetailsPayloadType,
20+
GetResourceScanDetailsResponseType,
21+
} from './types'
22+
export { SIDEBAR_DATA } from './config'
23+
export { CATEGORY_LABELS } from './constants'
24+
export { getExecutionDetails } from './service'

src/Shared/Components/Security/SecurityModal/service.ts

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,31 @@
22
* Copyright (c) 2024. Devtron Inc.
33
*/
44

5-
import { get, post } from '@Common/Api'
5+
import { get } from '@Common/Api'
66
import { ResponseType } from '@Common/Types'
77
import { getUrlWithSearchParams } from '@Common/Helper'
88
import { ROUTES } from '@Common/Constants'
9-
import { getParsedScanResult } from '../Vulnerabilities'
10-
import {
11-
ApiResponseResultType,
12-
GetResourceScanDetailsPayloadType,
13-
GetResourceScanDetailsResponseType,
14-
SecurityModalPropsType,
15-
} from './types'
16-
import { getTotalVulnerabilityCount, parseExecutionDetailResponse, parseGetResourceScanDetailsResponse } from './utils'
9+
import { ApiResponseResultType, ExecutionDetailsPayload } from './types'
10+
import { parseExecutionDetailResponse } from './utils'
1711

1812
export const getExecutionDetails = async (
19-
executionDetailPayload: SecurityModalPropsType['executionDetailsPayload'],
13+
executionDetailPayload: ExecutionDetailsPayload,
2014
): Promise<ResponseType<ApiResponseResultType>> => {
2115
const url = getUrlWithSearchParams(ROUTES.SECURITY_SCAN_EXECUTION_DETAILS, executionDetailPayload)
2216
const response = await get(url)
23-
return { ...response, result: parseExecutionDetailResponse(response.result) }
24-
}
25-
26-
export const getResourceScanDetails = async ({
27-
name,
28-
namespace,
29-
clusterId,
30-
group,
31-
version,
32-
kind,
33-
appId,
34-
appType,
35-
deploymentType,
36-
isAppDetailView,
37-
}: GetResourceScanDetailsPayloadType): Promise<ResponseType<ApiResponseResultType>> => {
38-
const baseObject = {
39-
k8sRequest: {
40-
resourceIdentifier: {
41-
groupVersionKind: {
42-
Group: group || '',
43-
Version: version || 'v1',
44-
Kind: kind,
45-
},
46-
namespace,
47-
name,
48-
},
49-
},
50-
clusterId: clusterId ? +clusterId : 0,
17+
const parsedResult = {
18+
...response.result,
19+
scanExecutionId: response.result.ScanExecutionId,
20+
lastExecution: response.result.executionTime,
21+
objectType: response.result.objectType,
22+
vulnerabilities: response.result.vulnerabilities?.map((cve) => ({
23+
name: cve.cveName,
24+
severity: cve.severity,
25+
package: cve.package,
26+
version: cve.currentVersion,
27+
fixedVersion: cve.fixedVersion,
28+
policy: cve.permission,
29+
})),
5130
}
52-
53-
const payload = isAppDetailView
54-
? {
55-
...baseObject,
56-
appId,
57-
appType,
58-
deploymentType,
59-
}
60-
: baseObject
61-
62-
const response = await post(ROUTES.K8S_RESOURCE_SECURITY, payload)
63-
const parsedScannedResult =
64-
response.result?.map((resourceData) => ({
65-
...resourceData,
66-
scanResult: getParsedScanResult(resourceData.scanResult),
67-
})) ?? []
68-
const data: GetResourceScanDetailsResponseType = {
69-
...getTotalVulnerabilityCount(parsedScannedResult),
70-
imageVulnerabilities: parsedScannedResult,
71-
}
72-
response.result = parseGetResourceScanDetailsResponse(data)
73-
return response
74-
}
75-
76-
export const getSecurityScan = async ({
77-
appId,
78-
envId,
79-
installedAppId,
80-
artifactId,
81-
installedAppVersionHistoryId,
82-
}: SecurityModalPropsType['appDetailsPayload']) => {
83-
const url = getUrlWithSearchParams(ROUTES.SCAN_RESULT, {
84-
appId,
85-
envId,
86-
installedAppId,
87-
artifactId,
88-
installedAppVersionHistoryId,
89-
})
90-
return get(url) as Promise<ResponseType<ApiResponseResultType>>
31+
return { ...response, result: parseExecutionDetailResponse(parsedResult) }
9132
}

0 commit comments

Comments
 (0)