feat(vulnerable): filter vulnerable packages by severity

The four severity tiles on the vulnerable packages page are now toggle
buttons with aria-pressed. Each tile shows "Filter on" while active.
A tile selects packages with at least one vulnerability of that
severity. Several tiles combine with OR. A second click clears the
tile, and a Clear filters control clears all of them.

The selection lives in the URL (?severity=critical,high), so it
survives a reload and works as a link. An empty result shows the
library empty state with a clear action.

GET /api/packages accepts a severity list. The page uses it to load
only vulnerable packages instead of the whole cache. The filter is a
subquery on the latest scan result, so the statement count does not
grow with the number of rows. An unknown severity returns 400.
This commit is contained in:
2026-11-23 14:54:44 +00:00
parent 4d31e535ff
commit bd9d686383
12 changed files with 652 additions and 24 deletions
+15
View File
@@ -39,6 +39,21 @@ describe('package store paging', () => {
])
})
it('fetchPackages asks for the listed severities only, and for everything without them', async () => {
vi.mocked(axios.get).mockResolvedValue({ data: { packages: [] } })
const store = usePackageStore()
await store.fetchPackages()
await store.fetchPackages({ severity: [] })
await store.fetchPackages({ severity: ['critical', 'high'] })
expect(vi.mocked(axios.get).mock.calls.map((c) => c[0])).toEqual([
'/api/packages',
'/api/packages',
'/api/packages?severity=critical,high',
])
})
it('keeps the server group count, and counts groups itself when the server sends none', async () => {
const store = usePackageStore()
vi.mocked(axios.get).mockResolvedValueOnce({ data: { packages: [pkg(1, '2026-01-01T00:00:00Z')], total_groups: 80 } })
+7 -3
View File
@@ -95,11 +95,15 @@ export const usePackageStore = defineStore('packages', () => {
}
let pageRequest = 0
/** Every package, unpaginated. Only views that filter on scan results need it. */
async function fetchPackages() {
/**
* Every package, unpaginated. Only views that filter on scan results need it.
* `severity` keeps the packages whose latest scan has a vulnerability of any listed severity.
*/
async function fetchPackages(options: { severity?: readonly string[] } = {}) {
begin()
try {
const response = await axios.get('/api/packages')
const query = options.severity?.length ? `?severity=${options.severity.join(',')}` : ''
const response = await axios.get(`/api/packages${query}`)
// Only update packages if we got valid data
if (response.data && Array.isArray(response.data.packages)) {
packages.value = response.data.packages