feat(frontend): rebuild package, detail and vulnerable views

Package groups use Accordion with Table or DataTable in the cards layout
below sm. Delete confirmations use ConfirmDialog and results go to the
Toaster. Vulnerability descriptions render through Markdown instead of
v-html, and references use the library Link.
This commit is contained in:
2026-11-23 02:29:13 +00:00
parent 041c6e8012
commit 54bc809f66
4 changed files with 421 additions and 723 deletions
+152 -272
View File
@@ -1,250 +1,154 @@
<template>
<div class="max-w-7xl mx-auto px-4 py-8">
<!-- Header with Back Button -->
<div class="mb-6">
<Button @click="goBack" variant="ghost" class="mb-4">
<i class="fas fa-arrow-left mr-2"></i>
Back to Packages
</Button>
<div class="flex items-center gap-3">
<i class="fas fa-box text-3xl text-primary-600"></i>
<div>
<h1 class="text-3xl font-bold text-gray-900">{{ packageName }}</h1>
<div class="flex items-center gap-2 mt-2">
<Badge :class="getRegistryBadgeClass(registry)">{{ registry }}</Badge>
<Badge variant="outline" class="font-mono">v{{ version }}</Badge>
</div>
</div>
</div>
</div>
<div class="flex flex-col gap-6">
<PageHeader :title="packageName">
<template #back>
<Button variant="ghost" size="sm" :icon-start="faArrowLeft" @click="goBack">Back to packages</Button>
</template>
<template #description>
<span class="flex flex-wrap items-center gap-2">
<Badge variant="outline">{{ registry }}</Badge>
<Badge variant="outline" class="font-mono">v{{ version }}</Badge>
</span>
</template>
</PageHeader>
<!-- Loading State -->
<div v-if="loading" class="text-center py-12">
<i class="fas fa-spinner fa-spin text-4xl text-primary-600"></i>
<p class="mt-4 text-gray-600">Loading vulnerability details...</p>
</div>
<LoadingState v-if="loading" variant="card" label="Loading vulnerability details..." />
<!-- Error State -->
<Alert v-else-if="error" variant="destructive" class="mb-4">
<i class="fas fa-exclamation-circle mr-2"></i>
<AlertDescription>{{ error }}</AlertDescription>
</Alert>
<ErrorState
v-else-if="error"
variant="card"
title="Could not load vulnerability details"
:message="error"
@retry="fetchVulnerabilities"
/>
<!-- Vulnerability Details -->
<div v-else-if="vulnerabilities" class="space-y-6">
<!-- Summary Card -->
<template v-else-if="vulnerabilities">
<Card>
<CardHeader>
<CardTitle class="flex items-center gap-2">
<i class="fas fa-shield-virus text-red-600"></i>
Security Scan Summary
</CardTitle>
<CardTitle as="h2">Security scan summary</CardTitle>
</CardHeader>
<CardContent>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
<div class="text-center p-4 bg-red-50 rounded-lg border border-red-200">
<p class="text-3xl font-bold text-red-600">{{ severityCounts.critical }}</p>
<p class="text-sm text-gray-600 mt-1">Critical</p>
</div>
<div class="text-center p-4 bg-orange-50 rounded-lg border border-orange-200">
<p class="text-3xl font-bold text-orange-600">{{ severityCounts.high }}</p>
<p class="text-sm text-gray-600 mt-1">High</p>
</div>
<div class="text-center p-4 bg-yellow-50 rounded-lg border border-yellow-200">
<p class="text-3xl font-bold text-yellow-600">{{ severityCounts.moderate }}</p>
<p class="text-sm text-gray-600 mt-1">Moderate</p>
</div>
<div class="text-center p-4 bg-blue-50 rounded-lg border border-blue-200">
<p class="text-3xl font-bold text-blue-600">{{ severityCounts.low }}</p>
<p class="text-sm text-gray-600 mt-1">Low</p>
</div>
</div>
<Separator class="my-4" />
<div class="flex items-center justify-between text-sm">
<div class="flex flex-col gap-3">
<span class="text-gray-600">
<i class="fas fa-search mr-1"></i>
Scanned: {{ formatDate(vulnerabilities.scanned_at) }}
<CardContent class="flex flex-col gap-4">
<SeveritySummary :counts="severityCounts" label="Vulnerabilities by severity" />
<DescriptionList variant="inline" divided>
<DescriptionItem term="Scanned">{{ formatDate(vulnerabilities.scanned_at) }}</DescriptionItem>
<DescriptionItem term="Scanners">
<span class="flex flex-wrap gap-1">
<Badge v-for="scanner in scannerList" :key="scanner" variant="secondary">{{ scanner }}</Badge>
</span>
<div class="flex items-center gap-2">
<span class="text-gray-600">
<i class="fas fa-cog mr-1"></i>
Scanners:
</span>
<div class="flex flex-wrap gap-1">
<Badge
v-for="scanner in scannerList"
:key="scanner"
variant="secondary"
class="text-xs"
>
{{ scanner }}
</Badge>
</div>
</div>
</div>
<div v-if="bypassedCount > 0" class="flex items-center gap-2 text-green-600">
<i class="fas fa-check-circle"></i>
<span>{{ bypassedCount }} bypassed</span>
</div>
</div>
</DescriptionItem>
<DescriptionItem v-if="bypassedCount > 0" term="Bypassed">
<StatusBadge status="bypassed" :label="`${bypassedCount} bypassed`" :tones="{ bypassed: 'success' }" />
</DescriptionItem>
</DescriptionList>
</CardContent>
</Card>
<!-- No Vulnerabilities -->
<Card v-if="vulnerabilityList.length === 0">
<CardContent class="text-center py-12">
<i class="fas fa-check-circle text-6xl text-green-500 mb-4"></i>
<p class="text-xl font-semibold text-gray-900">No Vulnerabilities Found</p>
<p class="mt-2 text-gray-600">This package is clean and safe to use</p>
<CardContent>
<EmptyState
tone="success"
:icon="faCircleCheck"
title="No vulnerabilities found"
description="The scanners reported nothing for this package version."
/>
</CardContent>
</Card>
<!-- Vulnerability List -->
<Card v-else>
<CardHeader>
<CardTitle class="flex items-center gap-2">
<i class="fas fa-list text-gray-600"></i>
Detected Vulnerabilities ({{ vulnerabilityList.length }})
</CardTitle>
<CardTitle as="h2">Detected vulnerabilities ({{ vulnerabilityList.length }})</CardTitle>
</CardHeader>
<CardContent class="p-0">
<div class="border-t overflow-x-auto">
<Table class="min-w-[800px]">
<TableHeader>
<TableRow class="bg-gray-50 hover:bg-gray-50">
<TableHead class="w-[100px]">Severity</TableHead>
<TableHead class="w-[180px]">CVE ID</TableHead>
<TableHead>Description</TableHead>
<TableHead class="w-[120px]">Fix Version</TableHead>
<TableHead class="w-[100px] text-center">Details</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<template v-for="(vuln, index) in vulnerabilityList" :key="vuln.id">
<!-- Main Row -->
<TableRow
:class="getRowClass(index, vuln.severity)"
@click="toggleRow(index)"
>
<TableCell>
<Badge :class="getSeverityBadgeClass(vuln.severity)">
{{ formatSeverityName(vuln.severity) }}
</Badge>
<span
<CardContent>
<Table label="Detected vulnerabilities" layout="cards">
<TableHeader>
<TableRow>
<TableHead>Severity</TableHead>
<TableHead>CVE ID</TableHead>
<TableHead>Description</TableHead>
<TableHead>Fix version</TableHead>
<TableHead align="center">Details</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<template v-for="(vuln, index) in vulnerabilityList" :key="vuln.id">
<TableRow class="cursor-pointer" :selected="expandedRows.has(index)" @click="toggleRow(index)">
<TableCell label="Severity">
<span class="flex flex-wrap items-center gap-2">
<StatusBadge
:status="vuln.severity"
:tones="SEVERITY_TONES"
:label="formatSeverityName(vuln.severity)"
/>
<StatusBadge
v-if="vuln.bypassed"
class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-green-800"
title="Bypassed"
>
<i class="fas fa-unlock text-xs"></i>
</span>
</TableCell>
<TableCell>
<span class="font-mono text-sm font-medium">{{ vuln.id }}</span>
</TableCell>
<TableCell>
<p class="text-sm text-gray-900 line-clamp-2 break-words">{{ vuln.title || vuln.description }}</p>
</TableCell>
<TableCell>
<span v-if="vuln.fixed_in" class="inline-flex items-center text-sm text-green-700">
<i class="fas fa-arrow-up text-xs mr-1"></i>
v{{ vuln.fixed_in }}
</span>
<span v-else class="text-sm text-gray-400">-</span>
</TableCell>
<TableCell class="text-center">
<Button
variant="ghost"
size="sm"
class="h-8 w-8 p-0"
@click.stop="toggleRow(index)"
>
<i
:class="[
'fas transition-transform',
expandedRows.has(index) ? 'fa-chevron-up' : 'fa-chevron-down'
]"
></i>
</Button>
</TableCell>
</TableRow>
status="bypassed"
label="Bypassed"
:tones="{ bypassed: 'success' }"
/>
</span>
</TableCell>
<TableCell label="CVE ID" class="font-mono font-medium">{{ vuln.id }}</TableCell>
<TableCell label="Description">
<p class="m-0 line-clamp-2 break-words">{{ vuln.title || vuln.description }}</p>
</TableCell>
<TableCell label="Fix version">
<span v-if="vuln.fixed_in">v{{ vuln.fixed_in }}</span>
<span v-else class="text-muted-foreground">-</span>
</TableCell>
<TableCell label="Details" align="center">
<IconButton
size="icon-sm"
:icon="expandedRows.has(index) ? faChevronUp : faChevronDown"
:label="`${expandedRows.has(index) ? 'Hide' : 'Show'} details for ${vuln.id}`"
:aria-expanded="expandedRows.has(index)"
@click.stop="toggleRow(index)"
/>
</TableCell>
</TableRow>
<!-- Expanded Details Row -->
<TableRow v-if="expandedRows.has(index)" class="bg-gray-50 hover:bg-gray-50">
<TableCell colspan="5" class="p-0">
<div class="px-6 py-4 space-y-3">
<!-- Full Description -->
<div>
<h5 class="font-semibold text-gray-900 mb-2">Description</h5>
<div
class="text-sm text-gray-700 leading-relaxed prose prose-sm max-w-none break-words overflow-hidden"
v-html="renderMarkdown(vuln.description)"
></div>
</div>
<TableRow v-if="expandedRows.has(index)" :hoverable="false">
<TableCell :colspan="5">
<div class="flex flex-col gap-4 py-2">
<section>
<h3 class="mb-2 text-sm font-semibold">Description</h3>
<Markdown :source="vuln.description" :heading-offset="3" />
</section>
<!-- Bypass Information -->
<div v-if="vuln.bypassed && vuln.bypass" class="bg-green-50 border border-green-200 rounded-lg p-3">
<h5 class="font-semibold text-green-900 mb-2 flex items-center gap-2">
<i class="fas fa-info-circle"></i>
Bypass Active
</h5>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm text-green-800">
<div class="break-words">
<span class="font-medium">Reason:</span> {{ vuln.bypass.reason }}
</div>
<div class="break-words">
<span class="font-medium">By:</span> {{ vuln.bypass.created_by }}
</div>
<div class="break-words">
<span class="font-medium">Expires:</span> {{ formatDate(vuln.bypass.expires_at) }}
</div>
</div>
</div>
<Alert v-if="vuln.bypassed && vuln.bypass" variant="success">
<AlertTitle>Bypass active</AlertTitle>
<AlertDescription>
<DescriptionList variant="grid" :columns="3" size="sm">
<DescriptionItem term="Reason">{{ vuln.bypass.reason }}</DescriptionItem>
<DescriptionItem term="By">{{ vuln.bypass.created_by }}</DescriptionItem>
<DescriptionItem term="Expires">{{ formatDate(vuln.bypass.expires_at) }}</DescriptionItem>
</DescriptionList>
</AlertDescription>
</Alert>
<!-- Fix Information -->
<div v-if="vuln.fixed_in" class="bg-blue-50 border border-blue-200 rounded-lg p-3">
<div class="flex items-center gap-2">
<i class="fas fa-wrench text-blue-700"></i>
<span class="text-sm text-blue-900">
<span class="font-semibold">Fix Available:</span> Upgrade to version <strong>{{ vuln.fixed_in }}</strong> or later
</span>
</div>
</div>
<Alert v-if="vuln.fixed_in" variant="info">
<AlertTitle>Fix available</AlertTitle>
<AlertDescription>
Upgrade to version <strong>{{ vuln.fixed_in }}</strong> or later.
</AlertDescription>
</Alert>
<!-- References -->
<div v-if="vuln.references && vuln.references.length > 0">
<h5 class="font-semibold text-gray-900 mb-2 flex items-center gap-2">
<i class="fas fa-link"></i>
References ({{ vuln.references.length }})
</h5>
<div class="space-y-1.5">
<div
v-for="(ref, refIndex) in vuln.references"
:key="refIndex"
class="flex items-start gap-2 text-sm"
>
<i class="fas fa-external-link-alt text-gray-400 text-xs mt-0.5"></i>
<a
:href="ref"
target="_blank"
rel="noopener noreferrer"
class="text-blue-600 hover:text-blue-800 hover:underline break-all"
>
{{ ref }}
</a>
</div>
</div>
</div>
</div>
</TableCell>
</TableRow>
</template>
</TableBody>
</Table>
</div>
<section v-if="vuln.references && vuln.references.length > 0">
<h3 class="mb-2 text-sm font-semibold">References ({{ vuln.references.length }})</h3>
<ul class="m-0 flex list-none flex-col gap-1 p-0 text-sm">
<li v-for="(ref, refIndex) in vuln.references" :key="refIndex" class="break-all">
<Link :href="ref" external>{{ ref }}</Link>
</li>
</ul>
</section>
</div>
</TableCell>
</TableRow>
</template>
</TableBody>
</Table>
</CardContent>
</Card>
</div>
</template>
</div>
</template>
@@ -252,32 +156,37 @@
import { ref, computed, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import axios from 'axios'
import { marked } from 'marked'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { Separator } from '@/components/ui/separator'
import {
Alert,
AlertDescription,
AlertTitle,
Badge,
Button,
Card,
CardContent,
CardHeader,
CardTitle,
DescriptionItem,
DescriptionList,
EmptyState,
ErrorState,
IconButton,
Link,
LoadingState,
Markdown,
PageHeader,
StatusBadge,
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import {
getSeverityBadgeClass,
getRegistryBadgeClass,
getVulnerabilityBorderClass,
formatSeverityName,
} from '@/composables/useBadgeStyles'
// Configure marked
marked.setOptions({
breaks: true,
gfm: true,
})
} from '@perfect-design/ui'
import SeveritySummary from './SeveritySummary.vue'
import { formatDate } from '@/lib/format'
import { faArrowLeft, faChevronDown, faChevronUp, faCircleCheck } from '@/lib/icons'
import { NO_VULNERABILITIES, SEVERITY_TONES, formatSeverityName, severityRank } from '@/lib/severity'
const router = useRouter()
const route = useRoute()
@@ -332,27 +241,15 @@ const error = ref<string | null>(null)
const vulnerabilities = ref<VulnerabilityResponse | null>(null)
const expandedRows = ref<Set<number>>(new Set())
// Severity order for sorting (higher values = more severe)
const severityOrder: Record<string, number> = {
CRITICAL: 4,
HIGH: 3,
MEDIUM: 2,
MODERATE: 2, // Treat MODERATE same as MEDIUM
LOW: 1,
UNKNOWN: 0,
}
const vulnerabilityList = computed(() => {
const vulns = vulnerabilities.value?.vulnerabilities || []
// Sort by severity (most severe first)
return [...vulns].sort((a, b) => {
const severityA = severityOrder[a.severity.toUpperCase()] || 0
const severityB = severityOrder[b.severity.toUpperCase()] || 0
return severityB - severityA // Descending order
return severityRank(b.severity) - severityRank(a.severity)
})
})
const severityCounts = computed(() => vulnerabilities.value?.severity_counts || { critical: 0, high: 0, moderate: 0, low: 0 })
const severityCounts = computed(() => vulnerabilities.value?.severity_counts || NO_VULNERABILITIES)
const bypassedCount = computed(() => vulnerabilities.value?.bypassed_count || 0)
// Parse scanner string into array of scanner names
@@ -396,21 +293,4 @@ function toggleRow(index: number) {
}
}
function getRowClass(index: number, severity: string): string {
const classes = ['cursor-pointer']
if (expandedRows.value.has(index)) {
classes.push('bg-gray-50')
}
classes.push(getVulnerabilityBorderClass(severity))
return classes.join(' ')
}
function formatDate(date: string): string {
return new Date(date).toLocaleString()
}
function renderMarkdown(text: string): string {
if (!text) return ''
return marked.parse(text) as string
}
</script>
+5 -8
View File
@@ -46,7 +46,7 @@ describe('PackageList.vue', () => {
it('renders package list component', async () => {
const wrapper = await mountWithRouter()
expect(wrapper.find('h2').text()).toBe('Packages')
expect(wrapper.find('h1').text()).toBe('Packages')
})
it('displays loading state when loading', async () => {
@@ -169,7 +169,7 @@ describe('PackageList.vue', () => {
expect(wrapper.text()).toContain('1 MB')
})
it('applies correct registry badge classes', async () => {
it('prints every registry as a badge with its name', async () => {
const wrapper = await mountWithRouter()
const store = usePackageStore()
@@ -214,11 +214,8 @@ describe('PackageList.vue', () => {
expect(wrapper.text()).toContain('pypi')
expect(wrapper.text()).toContain('go')
// Verify badge component is used with correct classes
// (matches getRegistryBadgeClass in src/composables/useBadgeStyles.ts)
const html = wrapper.html()
expect(html).toContain('bg-red-100') // npm badge
expect(html).toContain('bg-blue-100') // pypi badge
expect(html).toContain('bg-cyan-100') // go badge
// Each registry is printed as text in an outline badge, never as colour alone.
const badges = wrapper.findAll('[data-slot="badge"]').map((badge) => badge.text())
expect(badges).toEqual(['go', 'npm', 'pypi'])
})
})
+148 -262
View File
@@ -1,128 +1,89 @@
<template>
<div>
<div class="flex justify-between items-center mb-8">
<h2 class="text-3xl font-bold text-gray-900">Packages</h2>
<Button @click="store.fetchPackages()">
<i class="fas fa-sync-alt mr-2"></i>Refresh
</Button>
<div class="flex flex-col gap-6">
<PageHeader title="Packages" description="Everything the proxy has cached, grouped by package.">
<template #actions>
<Button variant="outline" :icon-start="faRotateRight" @click="store.fetchPackages()">Refresh</Button>
</template>
</PageHeader>
<div class="flex flex-col gap-4 sm:flex-row sm:items-center">
<SegmentedControl
:model-value="selectedRegistry"
:options="REGISTRY_OPTIONS"
aria-label="Filter by registry"
@update:model-value="changeRegistryFilter"
/>
<SearchInput v-model="searchTerm" aria-label="Search packages" placeholder="Search packages..." class="w-full sm:ms-auto sm:w-64" />
</div>
<!-- Filter and Search Section -->
<div class="mb-6 flex flex-col sm:flex-row items-start sm:items-center gap-4">
<div class="flex items-center gap-2">
<span class="text-sm font-medium text-gray-700">Filter by registry:</span>
<div class="flex gap-2">
<Button
@click="changeRegistryFilter('all')"
:variant="selectedRegistry === 'all' ? 'default' : 'outline'"
size="sm"
>
All
</Button>
<Button
@click="changeRegistryFilter('npm')"
:variant="selectedRegistry === 'npm' ? 'default' : 'outline'"
size="sm"
>
<i class="fab fa-npm mr-2"></i>NPM
</Button>
<Button
@click="changeRegistryFilter('pypi')"
:variant="selectedRegistry === 'pypi' ? 'default' : 'outline'"
size="sm"
>
<i class="fab fa-python mr-2"></i>PyPI
</Button>
<Button
@click="changeRegistryFilter('go')"
:variant="selectedRegistry === 'go' ? 'default' : 'outline'"
size="sm"
>
<i class="fas fa-code mr-2"></i>Go
</Button>
</div>
</div>
<div class="flex items-center gap-2 w-full sm:w-auto sm:ml-auto">
<i class="fas fa-search text-gray-500"></i>
<Input
v-model="searchTerm"
type="text"
placeholder="Search packages..."
class="w-full sm:w-64"
/>
</div>
</div>
<ErrorState
v-if="error"
variant="card"
title="Could not load packages"
:message="error"
@retry="store.fetchPackages()"
/>
<!-- Error Alert -->
<Alert v-if="error" variant="destructive" class="mb-4">
<i class="fas fa-exclamation-circle mr-2"></i>
<AlertDescription>{{ error }}</AlertDescription>
</Alert>
<LoadingState v-if="loading" variant="table" label="Loading packages..." />
<!-- Loading State -->
<div v-if="loading" class="text-center py-12">
<i class="fas fa-spinner fa-spin text-4xl text-primary-600"></i>
<p class="mt-4 text-gray-600">Loading packages...</p>
</div>
<!-- Package List -->
<Card v-else>
<CardContent class="p-6">
<div v-if="packages.length === 0" class="text-center py-12 text-gray-500">
<i class="fas fa-inbox text-6xl mb-4"></i>
<p class="text-xl">No packages cached yet</p>
<p class="mt-2">Packages will appear here once they are downloaded through the proxy</p>
</div>
<CardContent>
<EmptyState
v-if="packages.length === 0"
:icon="faBoxOpen"
title="No packages cached yet"
description="Packages will appear here once they are downloaded through the proxy."
/>
<EmptyState
v-else-if="groupedPackages.length === 0"
:icon="faMagnifyingGlass"
title="No packages match"
description="Change the registry filter or the search text."
/>
<Accordion v-else type="multiple" class="w-full">
<AccordionItem
v-for="group in groupedPackages"
:key="`${group.registry}:${group.name}`"
:value="`${group.registry}:${group.name}`"
class="border-b border-gray-200"
>
<AccordionTrigger class="px-4 py-4 hover:bg-gray-50">
<div class="flex items-center justify-between w-full pr-4">
<div class="flex items-center space-x-4">
<div class="text-left">
<h4 class="font-semibold text-gray-900">{{ group.name }}</h4>
<p class="text-sm text-gray-500">{{ group.versions.length }} version{{ group.versions.length > 1 ? 's' : '' }}</p>
</div>
</div>
<div class="flex items-center space-x-6">
<Badge variant="outline" :class="getRegistryBadgeClass(group.registry)">
{{ group.registry }}
</Badge>
<div class="text-right">
<p class="text-sm font-medium text-gray-900">{{ formatBytes(group.totalSize) }}</p>
<p class="text-xs text-gray-500">{{ formatNumber(group.totalDownloads) }} downloads</p>
</div>
</div>
</div>
</AccordionTrigger>
<AccordionContent class="px-4 pb-4">
<div class="space-y-3">
<div
v-for="version in group.versions"
:key="version.id"
class="flex items-center justify-between p-4 bg-gray-50 rounded-lg hover:bg-gray-100"
>
<div class="flex items-center space-x-4 flex-1">
<div class="flex-1">
<p class="font-medium text-gray-900">{{ version.version.startsWith('v') ? version.version : 'v' + version.version }}</p>
<div class="flex items-center space-x-4 mt-1 text-sm text-gray-500">
<span>
<i class="fas fa-download mr-1"></i>{{ formatNumber(version.download_count) }}
</span>
<span>
<i class="fas fa-hard-drive mr-1"></i>{{ formatBytes(version.size) }}
</span>
<span>
<i class="fas fa-clock mr-1"></i>{{ formatDate(version.cached_at) }}
</span>
</div>
<!-- Vulnerability Badge -->
<div v-if="version.vulnerabilities" class="mt-2">
<AccordionItem
v-for="group in groupedPackages"
:key="`${group.registry}:${group.name}`"
:value="`${group.registry}:${group.name}`"
>
<AccordionTrigger :heading-level="2">
<span class="flex w-full min-w-0 items-center justify-between gap-4">
<span class="min-w-0 text-start">
<span class="block break-words font-semibold">{{ group.name }}</span>
<span class="block text-sm text-muted-foreground">
{{ group.versions.length }} version{{ group.versions.length > 1 ? 's' : '' }}
</span>
</span>
<span class="flex shrink-0 items-center gap-4">
<Badge variant="outline">{{ group.registry }}</Badge>
<span class="text-end tabular-nums">
<span class="block text-sm font-medium">{{ formatBytes(group.totalSize) }}</span>
<span class="block text-xs text-muted-foreground">{{ formatNumber(group.totalDownloads) }} downloads</span>
</span>
</span>
</span>
</AccordionTrigger>
<AccordionContent>
<Table :label="`Versions of ${group.name}`" layout="cards">
<TableHeader>
<TableRow>
<TableHead>Version</TableHead>
<TableHead align="right">Downloads</TableHead>
<TableHead align="right">Size</TableHead>
<TableHead>Cached</TableHead>
<TableHead>Vulnerabilities</TableHead>
<TableHead align="right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="version in group.versions" :key="version.id">
<TableCell label="Version" class="font-medium">{{ withVersionPrefix(version.version) }}</TableCell>
<TableCell label="Downloads" numeric>{{ formatNumber(version.download_count) }}</TableCell>
<TableCell label="Size" numeric>{{ formatBytes(version.size) }}</TableCell>
<TableCell label="Cached">{{ formatDate(version.cached_at) }}</TableCell>
<TableCell label="Vulnerabilities">
<VulnerabilityBadge
v-if="version.vulnerabilities"
:scanned="version.vulnerabilities.scanned"
:status="version.vulnerabilities.status"
:counts="version.vulnerabilities.counts"
@@ -131,106 +92,44 @@
:isBlocked="version.vulnerabilities.isBlocked"
@click="showVulnerabilityDetails(group.registry, group.name, version.version)"
/>
</div>
</div>
</div>
<button
@click="confirmDelete(version)"
class="text-red-600 hover:text-red-900 p-2"
title="Delete this version"
>
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</AccordionContent>
</AccordionItem>
</TableCell>
<TableCell label="Actions" align="right">
<IconButton
:icon="faTrash"
:label="`Delete ${group.name} ${version.version}`"
@click="confirmDelete(version)"
/>
</TableCell>
</TableRow>
</TableBody>
</Table>
</AccordionContent>
</AccordionItem>
</Accordion>
<!-- Pagination -->
<div v-if="totalPages > 1" class="mt-6 flex items-center justify-between border-t pt-4">
<div class="text-sm text-gray-700">
<div v-if="totalPages > 1" class="mt-6 flex flex-col gap-3 border-t pt-4 sm:flex-row sm:items-center sm:justify-between">
<p class="m-0 text-sm text-muted-foreground">
Page {{ currentPage }} of {{ totalPages }} ({{ allGroupedPackages.length }} total packages)
</div>
<div class="flex items-center gap-2">
<Button
@click="changePage(currentPage - 1)"
:disabled="currentPage === 1"
variant="outline"
size="sm"
>
<i class="fas fa-chevron-left mr-2"></i>Previous
</Button>
<div class="flex gap-1">
<!-- First page -->
<Button
v-if="currentPage > 3"
@click="changePage(1)"
variant="outline"
size="sm"
>
1
</Button>
<span v-if="currentPage > 4" class="px-2">...</span>
<!-- Page numbers around current page -->
<Button
v-for="page in getPageNumbers()"
:key="page"
@click="changePage(page)"
:variant="page === currentPage ? 'default' : 'outline'"
size="sm"
>
{{ page }}
</Button>
<span v-if="currentPage < totalPages - 3" class="px-2">...</span>
<!-- Last page -->
<Button
v-if="currentPage < totalPages - 2"
@click="changePage(totalPages)"
variant="outline"
size="sm"
>
{{ totalPages }}
</Button>
</div>
<Button
@click="changePage(currentPage + 1)"
:disabled="currentPage === totalPages"
variant="outline"
size="sm"
>
Next<i class="fas fa-chevron-right ml-2"></i>
</Button>
</div>
</p>
<Pagination
:page="currentPage"
:total="allGroupedPackages.length"
:page-size="itemsPerPage"
@update:page="changePage"
/>
</div>
</CardContent>
</Card>
<!-- Delete Confirmation Dialog -->
<Dialog v-model:open="showDeleteModal">
<DialogContent>
<DialogHeader>
<DialogTitle>Confirm Deletion</DialogTitle>
<DialogDescription>
Are you sure you want to delete <strong>{{ packageToDelete?.name }}@{{ packageToDelete?.version }}</strong>?
This action cannot be undone.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button @click="showDeleteModal = false" variant="outline">
Cancel
</Button>
<Button @click="deletePackage" variant="destructive">
Delete
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<ConfirmDialog
v-model:open="showDeleteModal"
title="Delete package version?"
:description="`Delete ${packageToDelete?.name}@${packageToDelete?.version}? This action cannot be undone.`"
confirm-label="Delete version"
tone="danger"
destructive
@confirm="deletePackage"
/>
</div>
</template>
@@ -244,22 +143,30 @@ import {
AccordionContent,
AccordionItem,
AccordionTrigger,
} from '@/components/ui/accordion'
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { Card, CardContent } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Input } from '@/components/ui/input'
Badge,
Button,
Card,
CardContent,
ConfirmDialog,
EmptyState,
ErrorState,
IconButton,
LoadingState,
PageHeader,
Pagination,
SearchInput,
SegmentedControl,
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
useToastStore,
} from '@perfect-design/ui'
import VulnerabilityBadge from './VulnerabilityBadge.vue'
import { getRegistryBadgeClass } from '@/composables/useBadgeStyles'
import { formatBytes, formatDate, formatNumber, withVersionPrefix } from '@/lib/format'
import { faBoxOpen, faMagnifyingGlass, faRotateRight, faTrash } from '@/lib/icons'
// Props from router
const props = defineProps<{
@@ -269,10 +176,18 @@ const props = defineProps<{
const route = useRoute()
const router = useRouter()
const store = usePackageStore()
const toasts = useToastStore()
const { packages, loading, error } = storeToRefs(store)
const showDeleteModal = ref(false)
const packageToDelete = ref<Package | null>(null)
const REGISTRY_OPTIONS = [
{ value: 'all', label: 'All' },
{ value: 'npm', label: 'npm' },
{ value: 'pypi', label: 'PyPI' },
{ value: 'go', label: 'Go' },
]
const selectedRegistry = ref<string>(props.registry || 'all')
const searchTerm = ref<string>('')
const currentPage = ref<number>(1)
@@ -336,18 +251,6 @@ function changePage(page: number) {
}
}
// Get page numbers to display around current page
function getPageNumbers(): number[] {
const pages: number[] = []
const start = Math.max(1, currentPage.value - 2)
const end = Math.min(totalPages.value, currentPage.value + 2)
for (let i = start; i <= end; i++) {
pages.push(i)
}
return pages
}
// Reset to page 1 when filters change
function resetPagination() {
currentPage.value = 1
@@ -373,31 +276,14 @@ function confirmDelete(pkg: Package) {
}
async function deletePackage() {
if (packageToDelete.value) {
await store.deletePackage(
packageToDelete.value.registry,
packageToDelete.value.name,
packageToDelete.value.version
)
showDeleteModal.value = false
packageToDelete.value = null
}
}
function formatNumber(num: number): string {
return new Intl.NumberFormat().format(num)
}
function formatBytes(bytes: number): string {
if (bytes === 0) return '0 B'
const k = 1024
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]
}
function formatDate(date: string): string {
return new Date(date).toLocaleString()
const target = packageToDelete.value
if (!target) return
await store.deletePackage(target.registry, target.name, target.version)
showDeleteModal.value = false
packageToDelete.value = null
const label = `${target.name}@${target.version}`
if (store.error) toasts.error('Could not delete package', `${label}: ${store.error}`)
else toasts.success('Package deleted', label)
}
function showVulnerabilityDetails(registry: string, name: string, version: string) {
+116 -181
View File
@@ -1,159 +1,103 @@
<template>
<div class="max-w-7xl mx-auto px-4 py-8">
<!-- Header -->
<div class="mb-6">
<Button @click="goBack" variant="ghost" class="mb-4">
<i class="fas fa-arrow-left mr-2"></i>
Back to Stats
</Button>
<div class="flex items-center gap-3">
<i :class="showOnlyBlocked ? 'fas fa-hand' : 'fas fa-exclamation-triangle'" class="text-3xl text-red-600"></i>
<div>
<h1 class="text-3xl font-bold text-gray-900">
{{ showOnlyBlocked ? 'Blocked Packages' : 'Vulnerable Packages' }}
</h1>
<p class="text-gray-600 mt-1">
{{ showOnlyBlocked
? 'Packages blocked from download due to exceeding vulnerability thresholds'
: 'Packages with known security vulnerabilities, sorted by risk'
}}
</p>
</div>
</div>
</div>
<div class="flex flex-col gap-6">
<PageHeader
:title="showOnlyBlocked ? 'Blocked packages' : 'Vulnerable packages'"
:description="
showOnlyBlocked
? 'Packages blocked from download because they exceed the vulnerability thresholds.'
: 'Packages with known security vulnerabilities, sorted by risk.'
"
>
<template #back>
<Button variant="ghost" size="sm" :icon-start="faArrowLeft" @click="goBack">Back to stats</Button>
</template>
</PageHeader>
<!-- Loading State -->
<div v-if="loading" class="text-center py-12">
<i class="fas fa-spinner fa-spin text-4xl text-primary-600"></i>
<p class="mt-4 text-gray-600">Loading vulnerable packages...</p>
</div>
<LoadingState v-if="loading" variant="card" label="Loading vulnerable packages..." />
<!-- Error State -->
<Alert v-else-if="error" variant="destructive" class="mb-4">
<i class="fas fa-exclamation-circle mr-2"></i>
<AlertDescription>{{ error }}</AlertDescription>
</Alert>
<ErrorState
v-else-if="error"
variant="card"
title="Could not load vulnerable packages"
:message="error"
@retry="fetchVulnerablePackages"
/>
<!-- Empty State -->
<Card v-else-if="sortedVulnerablePackages.length === 0">
<CardContent class="text-center py-12">
<i class="fas fa-check-circle text-6xl text-green-500 mb-4"></i>
<p class="text-xl font-semibold text-gray-900">No Vulnerable Packages</p>
<p class="mt-2 text-gray-600">All your packages are clean and safe to use!</p>
<CardContent>
<EmptyState
tone="success"
:icon="faCircleCheck"
:title="showOnlyBlocked ? 'No blocked packages' : 'No vulnerable packages'"
description="Every cached package is clean."
/>
</CardContent>
</Card>
<!-- Vulnerable Packages List -->
<div v-else class="space-y-6">
<!-- Summary Card -->
<Card>
<CardContent class="p-6">
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div class="text-center p-4 bg-red-50 rounded-lg border border-red-200">
<p class="text-3xl font-bold text-red-600">{{ criticalCount }}</p>
<p class="text-sm text-gray-600 mt-1">Critical</p>
</div>
<div class="text-center p-4 bg-orange-50 rounded-lg border border-orange-200">
<p class="text-3xl font-bold text-orange-600">{{ highCount }}</p>
<p class="text-sm text-gray-600 mt-1">High</p>
</div>
<div class="text-center p-4 bg-yellow-50 rounded-lg border border-yellow-200">
<p class="text-3xl font-bold text-yellow-600">{{ moderateCount }}</p>
<p class="text-sm text-gray-600 mt-1">Moderate</p>
</div>
<div class="text-center p-4 bg-blue-50 rounded-lg border border-blue-200">
<p class="text-3xl font-bold text-blue-600">{{ lowCount }}</p>
<p class="text-sm text-gray-600 mt-1">Low</p>
</div>
</div>
</CardContent>
</Card>
<template v-else>
<SeveritySummary :counts="totalCounts" label="Vulnerabilities by severity" />
<!-- Packages List -->
<Card>
<CardContent class="p-6">
<div class="mb-4">
<h3 class="text-xl font-semibold text-gray-900">
<i class="fas fa-list mr-2"></i>
Vulnerable Packages ({{ sortedVulnerablePackages.length }})
</h3>
<p class="text-sm text-gray-600 mt-1">
{{ groupedPackages.length }} unique package{{ groupedPackages.length !== 1 ? 's' : '' }} • Sorted by risk: Critical → High → Moderate → Low
</p>
</div>
<CardHeader>
<CardTitle as="h2">
{{ showOnlyBlocked ? 'Blocked' : 'Vulnerable' }} packages ({{ sortedVulnerablePackages.length }})
</CardTitle>
<CardDescription>
{{ groupedPackages.length }} unique package{{ groupedPackages.length !== 1 ? 's' : '' }}, most critical first
</CardDescription>
</CardHeader>
<CardContent>
<Accordion type="multiple" class="w-full">
<AccordionItem
v-for="group in groupedPackages"
:key="`${group.registry}:${group.name}`"
:value="`${group.registry}:${group.name}`"
class="border-b border-gray-200"
>
<AccordionTrigger class="px-4 py-4 hover:bg-gray-50">
<div class="flex items-center justify-between w-full pr-4">
<div class="flex items-center space-x-4 flex-1 min-w-0">
<div class="text-left flex-1 min-w-0">
<h4 class="font-semibold text-gray-900 break-words">{{ group.name }}</h4>
<p class="text-sm text-gray-500">{{ group.versions.length }} vulnerable version{{ group.versions.length > 1 ? 's' : '' }}</p>
</div>
</div>
<div class="flex items-center space-x-6 flex-shrink-0">
<Badge variant="outline" :class="getRegistryBadgeClass(group.registry)">
{{ group.registry }}
</Badge>
<div class="text-right whitespace-nowrap">
<p class="text-sm font-medium text-gray-900">{{ formatBytes(group.totalSize) }}</p>
<p class="text-xs text-gray-500">{{ formatNumber(group.totalDownloads) }} downloads</p>
</div>
</div>
</div>
<AccordionTrigger :heading-level="3">
<span class="flex w-full min-w-0 items-center justify-between gap-4">
<span class="min-w-0 text-start">
<span class="block break-words font-semibold">{{ group.name }}</span>
<span class="block text-sm text-muted-foreground">
{{ group.versions.length }} vulnerable version{{ group.versions.length > 1 ? 's' : '' }}
</span>
</span>
<span class="flex shrink-0 items-center gap-4">
<Badge variant="outline">{{ group.registry }}</Badge>
<span class="whitespace-nowrap text-end tabular-nums">
<span class="block text-sm font-medium">{{ formatBytes(group.totalSize) }}</span>
<span class="block text-xs text-muted-foreground">{{ formatNumber(group.totalDownloads) }} downloads</span>
</span>
</span>
</span>
</AccordionTrigger>
<AccordionContent class="px-4 pb-4">
<div class="space-y-3">
<div
v-for="version in group.versions"
:key="version.id"
class="flex items-center justify-between p-4 bg-gray-50 rounded-lg hover:bg-gray-100 cursor-pointer"
@click="navigateToPackage(version)"
>
<div class="flex items-center space-x-4 flex-1">
<div class="flex-1">
<p class="font-medium text-gray-900">{{ version.version.startsWith('v') ? version.version : 'v' + version.version }}</p>
<div class="flex items-center space-x-4 mt-1 text-sm text-gray-500">
<span>
<i class="fas fa-download mr-1"></i>{{ formatNumber(version.download_count) }}
</span>
<span>
<i class="fas fa-hard-drive mr-1"></i>{{ formatBytes(version.size) }}
</span>
<span>
<i class="fas fa-clock mr-1"></i>{{ formatDate(version.cached_at) }}
</span>
</div>
<!-- Vulnerability Badge -->
<div v-if="version.vulnerabilities" class="mt-2">
<VulnerabilityBadge
:scanned="version.vulnerabilities.scanned"
:status="version.vulnerabilities.status"
:counts="version.vulnerabilities.counts"
:total="version.vulnerabilities.total"
:scannedAt="version.vulnerabilities.scannedAt"
:isBlocked="version.vulnerabilities.isBlocked"
@click.stop="navigateToPackage(version)"
/>
</div>
</div>
</div>
<div class="ml-4 flex-shrink-0">
<i class="fas fa-chevron-right text-gray-400"></i>
</div>
</div>
</div>
<AccordionContent>
<DataTable
:label="`Vulnerable versions of ${group.name}`"
layout="cards"
row-clickable
:columns="versionColumns"
:rows="group.versions"
@row-click="navigateToPackage"
>
<template #cell-vulnerabilities="{ row }">
<VulnerabilityBadge
v-if="row.vulnerabilities"
:scanned="row.vulnerabilities.scanned"
:status="row.vulnerabilities.status"
:counts="row.vulnerabilities.counts"
:total="row.vulnerabilities.total"
:scannedAt="row.vulnerabilities.scannedAt"
:isBlocked="row.vulnerabilities.isBlocked"
@click="navigateToPackage(row)"
/>
</template>
</DataTable>
</AccordionContent>
</AccordionItem>
</Accordion>
</CardContent>
</Card>
</div>
</template>
</div>
</template>
@@ -161,18 +105,30 @@
import { computed, onMounted, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { usePackageStore, type Package } from '../stores/packages'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { Card, CardContent } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from '@/components/ui/accordion'
Badge,
Button,
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
DataTable,
EmptyState,
ErrorState,
LoadingState,
PageHeader,
type DataTableColumn,
} from '@perfect-design/ui'
import VulnerabilityBadge from './VulnerabilityBadge.vue'
import { getRegistryBadgeClass } from '@/composables/useBadgeStyles'
import SeveritySummary from './SeveritySummary.vue'
import { formatBytes, formatDate, formatNumber, withVersionPrefix } from '@/lib/format'
import { faArrowLeft, faCircleCheck } from '@/lib/icons'
import { NO_VULNERABILITIES } from '@/lib/severity'
const store = usePackageStore()
const router = useRouter()
@@ -267,21 +223,28 @@ const groupedPackages = computed(() => {
})
// Calculate total counts across all packages
const criticalCount = computed(() =>
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.critical || 0), 0)
const totalCounts = computed(() =>
vulnerablePackages.value.reduce(
(sum, pkg) => {
const counts = pkg.vulnerabilities?.counts ?? NO_VULNERABILITIES
return {
critical: sum.critical + counts.critical,
high: sum.high + counts.high,
moderate: sum.moderate + counts.moderate,
low: sum.low + counts.low,
}
},
{ ...NO_VULNERABILITIES },
),
)
const highCount = computed(() =>
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.high || 0), 0)
)
const moderateCount = computed(() =>
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.moderate || 0), 0)
)
const lowCount = computed(() =>
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.low || 0), 0)
)
const versionColumns: DataTableColumn<Package>[] = [
{ key: 'version', header: 'Version', rowHeader: true, accessor: (pkg) => withVersionPrefix(pkg.version) },
{ key: 'download_count', header: 'Downloads', numeric: true, accessor: (pkg) => formatNumber(pkg.download_count) },
{ key: 'size', header: 'Size', numeric: true, accessor: (pkg) => formatBytes(pkg.size) },
{ key: 'cached_at', header: 'Cached', accessor: (pkg) => formatDate(pkg.cached_at) },
{ key: 'vulnerabilities', header: 'Vulnerabilities', accessor: () => '' },
]
function navigateToPackage(pkg: Package) {
router.push(`/package/${pkg.registry}/${pkg.name}/${pkg.version}`)
@@ -290,32 +253,4 @@ function navigateToPackage(pkg: Package) {
function goBack() {
router.push('/stats')
}
function formatNumber(num: number): string {
return new Intl.NumberFormat().format(num)
}
function formatBytes(bytes: number): string {
if (bytes === 0) return '0 B'
const k = 1024
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]
}
function formatDate(dateString: string): string {
if (!dateString) return 'N/A'
try {
const date = new Date(dateString)
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
})
} catch {
return dateString
}
}
</script>