diff --git a/package-lock.json b/package-lock.json index 5a8d826bc..64831ace8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "1.20.6-pre-51", + "version": "1.20.6-pre-53", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "1.20.6-pre-51", + "version": "1.20.6-pre-53", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 3625d2ac5..6545ce2a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "1.20.6-pre-51", + "version": "1.20.6-pre-53", "description": "Supporting common component library", "type": "module", "main": "dist/index.js", diff --git a/src/Common/Constants.ts b/src/Common/Constants.ts index 5b6ce0f18..a6bbd7974 100644 --- a/src/Common/Constants.ts +++ b/src/Common/Constants.ts @@ -131,7 +131,10 @@ export const URLS = { // SECURITY CENTER SECURITY_CENTER: SECURITY_CENTER_ROOT, SECURITY_CENTER_OVERVIEW: `${SECURITY_CENTER_ROOT}/overview`, - SECURITY_CENTER_SCANS: `${SECURITY_CENTER_ROOT}/scans`, + SECURITY_CENTER_VULNERABILITIES: `${SECURITY_CENTER_ROOT}/vulnerabilities`, + SECURITY_CENTER_VULNERABILITY_DEPLOYMENTS: `${SECURITY_CENTER_ROOT}/vulnerabilities/deployments`, + SECURITY_CENTER_VULNERABILITY_CVES: `${SECURITY_CENTER_ROOT}/vulnerabilities/cves`, + SECURITY_CENTER_SECURITY_ENABLEMENT: `${SECURITY_CENTER_ROOT}/security-enablement`, SECURITY_CENTER_POLICIES: `${SECURITY_CENTER_ROOT}/policies`, // AUTOMATION AND ENABLEMENT AUTOMATION_AND_ENABLEMENT: AUTOMATION_AND_ENABLEMENT_ROOT, diff --git a/src/Common/SegmentedBarChart/SegmentedBarChart.tsx b/src/Common/SegmentedBarChart/SegmentedBarChart.tsx index 93d2ac30b..3d598fba0 100644 --- a/src/Common/SegmentedBarChart/SegmentedBarChart.tsx +++ b/src/Common/SegmentedBarChart/SegmentedBarChart.tsx @@ -32,6 +32,7 @@ const SegmentedBarChart: React.FC = ({ countClassName, labelClassName, isProportional, + hideTotal, swapLegendAndBar = false, showAnimationOnBar = false, isLoading, @@ -58,7 +59,7 @@ const SegmentedBarChart: React.FC = ({
) : ( - {isProportional ? `${value}/${total}` : value} + {isProportional && !hideTotal ? `${value}/${total}` : value} ) diff --git a/src/Common/SegmentedBarChart/types.ts b/src/Common/SegmentedBarChart/types.ts index 7ddf526e6..2101e42f4 100644 --- a/src/Common/SegmentedBarChart/types.ts +++ b/src/Common/SegmentedBarChart/types.ts @@ -32,13 +32,23 @@ type EntityPropType = entities: NonNullable & { label?: never }>[] } +type ProportionalType = + | { + isProportional?: true + hideTotal?: boolean + } + | { + isProportional?: false | never + hideTotal?: never + } + export type SegmentedBarChartProps = { rootClassName?: string countClassName?: string labelClassName?: string - isProportional?: boolean swapLegendAndBar?: boolean showAnimationOnBar?: boolean isLoading?: boolean size?: ComponentSizeType -} & EntityPropType +} & EntityPropType & + ProportionalType diff --git a/src/Common/SegmentedControl/constants.ts b/src/Common/SegmentedControl/constants.ts index 21bca10ef..404965a13 100644 --- a/src/Common/SegmentedControl/constants.ts +++ b/src/Common/SegmentedControl/constants.ts @@ -22,10 +22,12 @@ export const COMPONENT_SIZE_TO_SEGMENT_CLASS_MAP: Record = { [ComponentSizeType.xs]: 'py-1', [ComponentSizeType.small]: 'py-2', [ComponentSizeType.medium]: 'py-2', + [ComponentSizeType.large]: 'py-3', } as const diff --git a/src/Common/SegmentedControl/types.ts b/src/Common/SegmentedControl/types.ts index c74672632..20344b81c 100644 --- a/src/Common/SegmentedControl/types.ts +++ b/src/Common/SegmentedControl/types.ts @@ -78,7 +78,10 @@ export type SegmentedControlProps = { * Please make sure this is unique */ name: string - size?: Extract + size?: Extract< + ComponentSizeType, + ComponentSizeType.xs | ComponentSizeType.small | ComponentSizeType.medium | ComponentSizeType.large + > fullWidth?: boolean disabled?: boolean } & ( diff --git a/src/Common/Types.ts b/src/Common/Types.ts index ff8edc942..689118388 100644 --- a/src/Common/Types.ts +++ b/src/Common/Types.ts @@ -1116,6 +1116,7 @@ export type AppsGroupedByProjectsType = { projectName: string appList: { name: string + id: number }[] }[] diff --git a/src/Shared/Components/Security/SecurityDetailsCards/SecurityCard.tsx b/src/Shared/Components/Security/SecurityDetailsCards/SecurityCard.tsx index c728c555f..aac0fd138 100644 --- a/src/Shared/Components/Security/SecurityDetailsCards/SecurityCard.tsx +++ b/src/Shared/Components/Security/SecurityDetailsCards/SecurityCard.tsx @@ -21,7 +21,7 @@ import { ReactComponent as ICShieldWarning } from '@Icons/ic-shield-warning-outl import { SegmentedBarChart } from '@Common/SegmentedBarChart' import { SECURITY_CONFIG } from '../constants' -import { SEVERITIES } from '../SecurityModal/constants' +import { SEVERITIES_LABEL_COLOR_MAP } from '../SecurityModal/constants' import { SUB_CATEGORIES } from '../SecurityModal/types' import { getTotalSeverities } from '../utils' import { SecurityCardProps } from './types' @@ -39,7 +39,7 @@ const SecurityCard = ({ const hasThreats: boolean = !!totalCount - const entities = Object.entries(SEVERITIES) + const entities = Object.entries(SEVERITIES_LABEL_COLOR_MAP) .map(([key, severity]) => ({ ...severity, value: severities[key], diff --git a/src/Shared/Components/Security/SecurityModal/constants.tsx b/src/Shared/Components/Security/SecurityModal/constants.tsx index f838c24ed..b75cdeb10 100644 --- a/src/Shared/Components/Security/SecurityModal/constants.tsx +++ b/src/Shared/Components/Security/SecurityModal/constants.tsx @@ -73,7 +73,7 @@ export const SUB_CATEGORY_LABELS = { EXPOSED_SECRETS: 'Exposed Secrets', } as const -export const SEVERITIES = { +export const SEVERITIES_LABEL_COLOR_MAP = { [SeveritiesDTO.CRITICAL]: { label: 'Critical', color: 'var(--R700)', diff --git a/src/Shared/Components/Security/SecurityModal/index.ts b/src/Shared/Components/Security/SecurityModal/index.ts index e16f6439f..9ddf29487 100644 --- a/src/Shared/Components/Security/SecurityModal/index.ts +++ b/src/Shared/Components/Security/SecurityModal/index.ts @@ -20,7 +20,7 @@ export { getSecurityModalSidebarId, getSidebarData, } from './config' -export { CATEGORY_LABELS } from './constants' +export { CATEGORY_LABELS, SEVERITIES_LABEL_COLOR_MAP } from './constants' export { default as SecurityModal } from './SecurityModal' export { getSecurityScan } from './service' export type { diff --git a/src/Shared/Components/Security/SecurityModal/utils.tsx b/src/Shared/Components/Security/SecurityModal/utils.tsx index 08ac7b5e6..c0a646607 100644 --- a/src/Shared/Components/Security/SecurityModal/utils.tsx +++ b/src/Shared/Components/Security/SecurityModal/utils.tsx @@ -20,7 +20,7 @@ import { VulnerabilityType } from '@Common/Types' import { ScannedByToolModal } from '@Shared/Components/ScannedByToolModal' import { Severity } from '@Shared/types' -import { ORDERED_SEVERITY_KEYS, SEVERITIES, TRIVY_ICON_URL } from './constants' +import { ORDERED_SEVERITY_KEYS, SEVERITIES_LABEL_COLOR_MAP, TRIVY_ICON_URL } from './constants' import { CATEGORIES, GetResourceScanDetailsResponseType, @@ -34,27 +34,30 @@ import { } from './types' export const mapSeveritiesToSegmentedBarChartEntities = ( - severities: Partial>, + severities: Partial>, ) => /* for all the SEVERITY keys in @severities create @Entity */ severities && ORDERED_SEVERITY_KEYS.map( - (key: keyof typeof SEVERITIES) => + (key: keyof typeof SEVERITIES_LABEL_COLOR_MAP) => severities[key] && { - color: SEVERITIES[key].color, - label: SEVERITIES[key].label, + color: SEVERITIES_LABEL_COLOR_MAP[key].color, + label: SEVERITIES_LABEL_COLOR_MAP[key].label, value: severities[key], }, ).filter((entity: SegmentedBarChartProps['entities'][number]) => !!entity) -export const stringifySeverities = (severities: Partial>) => +export const stringifySeverities = (severities: Partial>) => severities && Object.keys(severities) .sort( - (a: keyof typeof SEVERITIES, b: keyof typeof SEVERITIES) => + (a: keyof typeof SEVERITIES_LABEL_COLOR_MAP, b: keyof typeof SEVERITIES_LABEL_COLOR_MAP) => ORDERED_SEVERITY_KEYS.indexOf(a) - ORDERED_SEVERITY_KEYS.indexOf(b), ) - .map((key: keyof typeof SEVERITIES) => `${severities[key]} ${SEVERITIES[key].label}`) + .map( + (key: keyof typeof SEVERITIES_LABEL_COLOR_MAP) => + `${severities[key]} ${SEVERITIES_LABEL_COLOR_MAP[key].label}`, + ) .join(', ') export const getSeverityWeight = (severity: SeveritiesDTO): number => diff --git a/src/Shared/Components/Security/index.tsx b/src/Shared/Components/Security/index.tsx index e7af72994..08d1890a4 100644 --- a/src/Shared/Components/Security/index.tsx +++ b/src/Shared/Components/Security/index.tsx @@ -17,5 +17,7 @@ export { SEVERITY_LABEL_MAP } from './constants' export * from './SecurityDetailsCards' export * from './SecurityModal' +export { default as SeverityChip } from './SeverityChip' +export { FixAvailabilityOptions, VulnerabilityDiscoveryAgeOptions } from './types' export * from './utils' export * from './Vulnerabilities' diff --git a/src/Shared/Components/Security/types.tsx b/src/Shared/Components/Security/types.tsx index c7372ee97..c9e8e13e7 100644 --- a/src/Shared/Components/Security/types.tsx +++ b/src/Shared/Components/Security/types.tsx @@ -42,3 +42,15 @@ export interface GetSidebarDataParamsType extends Record( }) ?? defaultOption ) } + +export const getSelectPickerOptionsByValue = ( + optionsList: OptionsOrGroups, GroupBase>>, + values: OptionValue[], +): SelectPickerOptionType[] => { + if (!Array.isArray(optionsList)) { + return [] + } + + const flatOptionsList = optionsList.flatMap>((groupOrBaseOption) => + 'options' in groupOrBaseOption ? groupOrBaseOption.options : [groupOrBaseOption], + ) + + return flatOptionsList.filter((option) => values.includes(option.value)) +} diff --git a/src/Shared/Hooks/useUserPreferences/types.ts b/src/Shared/Hooks/useUserPreferences/types.ts index e0c9d015b..2df44992a 100644 --- a/src/Shared/Hooks/useUserPreferences/types.ts +++ b/src/Shared/Hooks/useUserPreferences/types.ts @@ -40,7 +40,8 @@ export type NavigationItemID = | 'cost-visibility-cost-breakdown' | 'cost-visibility-configurations' | 'security-center-overview' - | 'security-center-security-scans' + | 'security-center-security-vulnerabilities' + | 'security-center-security-enablement' | 'security-center-security-policy' | 'automation-and-enablement-jobs' | 'automation-and-enablement-alerting'