Skip to content

Commit 75e2647

Browse files
Farooq-Fateh-Aftabheliocastro
authored andcommitted
feat(Vulnerability): Added svm link for external id
1 parent 02ee690 commit 75e2647

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/app/[locale]/vulnerabilities/detail/[id]/components/Summary.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import { signOut, useSession } from 'next-auth/react'
1414
import { useTranslations } from 'next-intl'
1515
import { ReactNode, useEffect, useState } from 'react'
1616
import { DisplayMap } from '@/components/DisplayMap/DisplayMap'
17-
import { Vulnerability } from '@/object-types'
17+
import { useConfigValue } from '@/contexts'
18+
import { UIConfigKeys, Vulnerability } from '@/object-types'
1819
import UsingReleasesTable from './UsingReleasesTable'
1920

2021
export default function Summary({ summaryData }: { summaryData: Vulnerability }): ReactNode {
2122
const t = useTranslations('default')
2223
const [toggle, setToggle] = useState(false)
2324
const { status } = useSession()
25+
const svmNotificationUrl = useConfigValue(UIConfigKeys.UI_SVM_NOTIFICATION_URL) as string | null
2426

2527
useEffect(() => {
2628
if (status === 'unauthenticated') {
@@ -54,7 +56,29 @@ export default function Summary({ summaryData }: { summaryData: Vulnerability })
5456
</tr>
5557
<tr>
5658
<td>{t('External Id')}:</td>
57-
<td>{(summaryData.externalId ?? '') && (summaryData.externalId ?? '')}</td>
59+
<td>
60+
{(() => {
61+
const externalId = summaryData.externalId
62+
if (!externalId) return ''
63+
64+
const urlString = String(svmNotificationUrl || '').trim()
65+
if (urlString && urlString.length > 0) {
66+
const fullUrl = `${urlString}${externalId}`
67+
return (
68+
<a
69+
href={fullUrl}
70+
target='_blank'
71+
rel='noopener noreferrer'
72+
className='text-link'
73+
>
74+
{externalId}
75+
</a>
76+
)
77+
}
78+
79+
return externalId
80+
})()}
81+
</td>
5882
</tr>
5983
<tr>
6084
<td>{t('Publish Date')}:</td>

src/contexts/UiConfigContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function useUiConfigContext() {
3434
return context
3535
}
3636

37-
export function useConfigValue(key: UIConfigKeys): boolean | string[] | null {
37+
export function useConfigValue(key: UIConfigKeys): boolean | string[] | string | null {
3838
const { config } = useUiConfigContext()
3939

4040
if (!config || !(key in config)) {

src/object-types/UiConfiguration.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77
// SPDX-License-Identifier: EPL-2.0
88
// License-Filename: LICENSE
99

10-
import { ArrayTypeUIConfigKeys, UIConfigKeys } from './enums/UIConfigKeys'
10+
import { ArrayTypeUIConfigKeys, StringTypeUIConfigKeys, UIConfigKeys } from './enums/UIConfigKeys'
1111

1212
export type UiConfiguration = {
1313
[key in UIConfigKeys]: string
1414
}
1515

1616
// Extended type for processed configuration after parsing
1717
export type ProcessedUiConfig = {
18-
[key in UIConfigKeys]: key extends (typeof ArrayTypeUIConfigKeys)[number] ? string[] : boolean
18+
[key in UIConfigKeys]: key extends (typeof ArrayTypeUIConfigKeys)[number]
19+
? string[]
20+
: key extends (typeof StringTypeUIConfigKeys)[number]
21+
? string
22+
: boolean
1923
}
2024

2125
// Helper functions to process raw configuration
22-
export function parseConfigValue(key: UIConfigKeys, value: string): string[] | boolean {
26+
export function parseConfigValue(key: UIConfigKeys, value: string): string[] | string | boolean {
2327
if (ArrayTypeUIConfigKeys.includes(key)) {
2428
if (value === undefined) {
2529
return []
@@ -31,12 +35,12 @@ export function parseConfigValue(key: UIConfigKeys, value: string): string[] | b
3135
parsedValues = []
3236
}
3337
return parsedValues.map((item) => item.trim()).filter(Boolean)
38+
} else if (StringTypeUIConfigKeys.includes(key)) {
39+
// Handle string type configurations
40+
return value || ''
3441
} else {
35-
if (value) {
36-
return value.toLowerCase() === 'true'
37-
} else {
38-
return false
39-
}
42+
// Handle boolean type configurations
43+
return value ? value.toLowerCase() === 'true' : false
4044
}
4145
}
4246

src/object-types/enums/UIConfigKeys.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export enum UIConfigKeys {
3030
UI_CUSTOMMAP_PROJECT_ROLES = 'ui.custommap.project.roles',
3131
UI_ENABLE_SECURITY_VULNERABILITY_MONITORING = 'ui.enable.security.vulnerability.monitoring',
3232
UI_REST_APITOKEN_WRITE_GENERATOR_ENABLE = 'ui.rest.apitoken.write.generator.enable',
33+
UI_SVM_NOTIFICATION_URL = 'svm.notification.url',
3334
}
3435

3536
export const ArrayTypeUIConfigKeys: UIConfigKeys[] = [
@@ -51,3 +52,7 @@ export const ArrayTypeUIConfigKeys: UIConfigKeys[] = [
5152
UIConfigKeys.UI_SOFTWARE_PLATFORMS,
5253
UIConfigKeys.UI_CUSTOMMAP_RELEASE_ROLES,
5354
]
55+
56+
export const StringTypeUIConfigKeys: UIConfigKeys[] = [
57+
UIConfigKeys.UI_SVM_NOTIFICATION_URL,
58+
]

0 commit comments

Comments
 (0)