Skip to content

Commit 647f507

Browse files
committed
Merge branch 'feat/integrate-scan-tool-url' of https://github.com/devtron-labs/devtron-fe-common-lib into feat/integrate-scan-tool-url
2 parents 9a73ca0 + 02c2bbd commit 647f507

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ComponentSizeType } from '@Shared/constants'
1919
import { Table, InfoCard } from './components'
2020
import { getDefaultSecurityModalState } from './constants'
2121
import { getTableData, getInfoCardData } from './config'
22-
import { SecurityModalPropsType, SecurityModalStateType, DetailViewDataType, SidebarPropsType } from './types'
22+
import { SecurityModalPropsType, SecurityModalStateType, DetailViewDataType } from './types'
2323
import { getEmptyStateValues } from './config/EmptyState'
2424
import './styles.scss'
2525

@@ -44,15 +44,14 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
4444
}) => {
4545
const data = responseData ?? null
4646

47-
const categoriesConfig: SidebarPropsType['categoriesConfig'] = {
48-
imageScan: !!data?.imageScan,
49-
imageScanLicenseRisks: !!data?.imageScan?.license,
50-
codeScan: !!data?.codeScan,
51-
kubernetesManifest: !!data?.kubernetesManifest,
52-
}
53-
5447
const [state, setState] = useState<SecurityModalStateType>(
55-
defaultState ?? getDefaultSecurityModalState(categoriesConfig),
48+
defaultState ??
49+
getDefaultSecurityModalState({
50+
imageScan: !!data?.imageScan,
51+
imageScanLicenseRisks: !!data?.imageScan?.license,
52+
codeScan: !!data?.codeScan,
53+
kubernetesManifest: !!data?.kubernetesManifest,
54+
}),
5655
)
5756

5857
const setDetailViewData = (detailViewData: DetailViewDataType) => {
@@ -167,7 +166,7 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
167166
/* NOTE: the height is restricted to (viewport - header) height since we need overflow-scroll */
168167
<div className="flexbox" style={{ height: 'calc(100vh - 49px)' }}>
169168
{/* NOTE: only show sidebar in AppDetails */}
170-
{Sidebar && <Sidebar modalState={state} setModalState={setState} categoriesConfig={categoriesConfig} />}
169+
{Sidebar && <Sidebar modalState={state} setModalState={setState} scanResult={responseData} />}
171170
<div className="dc__border-right-n1 h-100" />
172171
<div className="dc__overflow-auto flex-grow-1" style={{ width: '744px' }}>
173172
{selectedDetailViewData && renderDetailViewSubHeader()}

src/Shared/Components/Security/SecurityModal/config/Sidebar.ts

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

5+
import { ScanCategoriesWithLicense } from '../../types'
56
import { CATEGORY_LABELS, SUB_CATEGORY_LABELS } from '../constants'
6-
import { CATEGORIES, SUB_CATEGORIES, SidebarDataType, SidebarPropsType } from '../types'
7+
import { CATEGORIES, SUB_CATEGORIES, SidebarDataType } from '../types'
78

8-
export const getSidebarData = (categoriesConfig: SidebarPropsType['categoriesConfig']): SidebarDataType[] => {
9+
export const getSidebarData = (categoriesConfig: Record<ScanCategoriesWithLicense, boolean>): SidebarDataType[] => {
910
const { imageScan, codeScan, kubernetesManifest, imageScanLicenseRisks } = categoriesConfig
1011

1112
return [

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
SeveritiesDTO,
1111
SortOrderEnum,
1212
EmptyStateType,
13-
SidebarPropsType,
1413
SecurityModalStateType,
1514
} from './types'
15+
import { ScanCategoriesWithLicense } from '../types'
1616

1717
export const DEFAULT_SECURITY_MODAL_IMAGE_STATE = {
1818
category: CATEGORIES.IMAGE_SCAN,
@@ -33,7 +33,7 @@ const DEFAULT_SECURITY_MODAL_MANIFEST_STATE = {
3333
}
3434

3535
export const getDefaultSecurityModalState = (
36-
categoriesConfig: SidebarPropsType['categoriesConfig'],
36+
categoriesConfig: Record<ScanCategoriesWithLicense, boolean>,
3737
): SecurityModalStateType => {
3838
if (categoriesConfig.imageScan) {
3939
return DEFAULT_SECURITY_MODAL_IMAGE_STATE

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GenericEmptyStateType } from '@Common/Types'
77
import { LastExecutionResultType, NodeType, Nodes } from '@Shared/types'
88
import { SegmentedBarChartProps } from '@Common/SegmentedBarChart'
99
import { ServerErrors } from '@Common/ServerError'
10+
import { ScanCategories, ScanSubCategories } from '../types'
1011

1112
export interface GetResourceScanDetailsPayloadType {
1213
name: string
@@ -100,17 +101,11 @@ export type DetailViewDataType = {
100101
InfoCardPropsType
101102

102103
export type SecurityModalStateType = {
103-
category: (typeof CATEGORIES)[keyof typeof CATEGORIES]
104-
subCategory: (typeof SUB_CATEGORIES)[keyof typeof SUB_CATEGORIES]
104+
category: ScanCategories
105+
subCategory: ScanSubCategories
105106
detailViewData: DetailViewDataType[]
106107
}
107108

108-
export interface SidebarPropsType {
109-
modalState: SecurityModalStateType
110-
setModalState: React.Dispatch<React.SetStateAction<SecurityModalStateType>>
111-
categoriesConfig: Record<(typeof CATEGORIES)[keyof typeof CATEGORIES] | 'imageScanLicenseRisks', boolean>
112-
}
113-
114109
export enum SeveritiesDTO {
115110
CRITICAL = 'critical',
116111
HIGH = 'high',
@@ -243,6 +238,12 @@ export type ScanResultDTO = {
243238
[CATEGORIES.KUBERNETES_MANIFEST]: KubernetesManifest
244239
}
245240

241+
export interface SidebarPropsType {
242+
modalState: SecurityModalStateType
243+
setModalState: React.Dispatch<React.SetStateAction<SecurityModalStateType>>
244+
scanResult: ScanResultDTO
245+
}
246+
246247
interface SecurityModalBaseProps {
247248
isLoading: boolean
248249
error: ServerErrors
@@ -264,8 +265,8 @@ export interface IndexedTextDisplayPropsType {
264265
export type SidebarDataChildType = {
265266
label: string
266267
value: {
267-
category: (typeof CATEGORIES)[keyof typeof CATEGORIES]
268-
subCategory: (typeof SUB_CATEGORIES)[keyof typeof SUB_CATEGORIES]
268+
category: ScanCategories
269+
subCategory: ScanSubCategories
269270
}
270271
}
271272

src/Shared/Components/Security/types.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { CATEGORIES, SUB_CATEGORIES } from './SecurityModal/types'
33
export type ScanCategories = (typeof CATEGORIES)[keyof typeof CATEGORIES]
44
export type ScanSubCategories = (typeof SUB_CATEGORIES)[keyof typeof SUB_CATEGORIES]
55

6+
export type ScanCategoriesWithLicense = ScanCategories | 'imageScanLicenseRisks'
7+
68
export type CategoriesConfig = {
79
imageScan: boolean
810
codeScan: boolean

0 commit comments

Comments
 (0)