11<script setup lang="ts">
2- import type { OsvSeverityLevel , PackageVulnerabilities } from ' #shared/types'
2+ import type { PackageVulnerabilities } from ' #shared/types'
3+ import { SEVERITY_LEVELS } from ' #shared/types'
4+ import { SEVERITY_COLORS , SEVERITY_BADGE_COLORS , getHighestSeverity } from ' #shared/utils/severity'
35
46const props = defineProps <{
57 packageName: string
@@ -38,47 +40,14 @@ const { data: vulnData, status } = useLazyAsyncData(
3840)
3941
4042const hasVulnerabilities = computed (() => vulnData .value .counts .total > 0 )
41-
42- // Severity color classes for the banner
43- const severityColors: Record <OsvSeverityLevel , string > = {
44- critical: ' text-red-400 bg-red-500/10 border-red-500/30' ,
45- high: ' text-orange-400 bg-orange-500/10 border-orange-500/30' ,
46- moderate: ' text-yellow-400 bg-yellow-500/10 border-yellow-500/30' ,
47- low: ' text-blue-400 bg-blue-500/10 border-blue-500/30' ,
48- unknown: ' text-fg-muted bg-bg-subtle border-border' ,
49- }
50-
51- // Severity badge styles - greyscale theme matching the design system
52- const severityBadgeColors: Record <OsvSeverityLevel , string > = {
53- critical: ' bg-bg-muted border border-border text-fg' ,
54- high: ' bg-bg-muted border border-border text-fg-muted' ,
55- moderate: ' bg-bg-muted border border-border text-fg-muted' ,
56- low: ' bg-bg-muted border border-border text-fg-subtle' ,
57- unknown: ' bg-bg-muted border border-border text-fg-subtle' ,
58- }
59-
60- // Expand/collapse state
6143const isExpanded = shallowRef (false )
44+ const highestSeverity = computed (() => getHighestSeverity (vulnData .value .counts ))
6245
63- // Get highest severity for banner color
64- const highestSeverity = computed <OsvSeverityLevel >(() => {
65- const counts = vulnData .value .counts
66- if (counts .critical > 0 ) return ' critical'
67- if (counts .high > 0 ) return ' high'
68- if (counts .moderate > 0 ) return ' moderate'
69- if (counts .low > 0 ) return ' low'
70- return ' unknown'
71- })
72-
73- // Summary text for collapsed view
7446const summaryText = computed (() => {
75- const counts = vulnData .value .counts
76- const parts: string [] = []
77- if (counts .critical > 0 ) parts .push (` ${counts .critical } critical ` )
78- if (counts .high > 0 ) parts .push (` ${counts .high } high ` )
79- if (counts .moderate > 0 ) parts .push (` ${counts .moderate } moderate ` )
80- if (counts .low > 0 ) parts .push (` ${counts .low } low ` )
81- return parts .join (' , ' )
47+ const { counts } = vulnData .value
48+ return SEVERITY_LEVELS .filter (s => counts [s ] > 0 )
49+ .map (s => ` ${counts [s ]} ${s } ` )
50+ .join (' , ' )
8251})
8352 </script >
8453
@@ -88,7 +57,7 @@ const summaryText = computed(() => {
8857 <div
8958 role =" alert"
9059 class =" rounded-lg border overflow-hidden"
91- :class =" severityColors [highestSeverity]"
60+ :class =" SEVERITY_COLORS [highestSeverity]"
9261 >
9362 <!-- Header (always visible, clickable to expand) -->
9463 <button
@@ -140,7 +109,7 @@ const summaryText = computed(() => {
140109 </a >
141110 <span
142111 class =" px-2 py-0.5 text-xs font-mono rounded"
143- :class =" severityBadgeColors [vuln.severity]"
112+ :class =" SEVERITY_BADGE_COLORS [vuln.severity]"
144113 >
145114 {{ vuln.severity }}
146115 </span >
0 commit comments