Skip to content

Commit e97f588

Browse files
authored
fix(search): use canonical severity labels
Use the shared long-form severity vocabulary in the search filter and type the range as SeverityLevel values. Preserve the existing range interaction while eliminating the private label map that had drifted from case pages. Closes #30
1 parent 10478d7 commit e97f588

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

components/post/SearchResults.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ import { useState, useEffect, useRef } from "react";
44
import Link from "next/link";
55
import { PostCard } from "@/components/post/PostCard";
66
import { AGENTS } from "@/lib/constants/agents";
7+
import {
8+
isSeverityLevel,
9+
SEVERITY_LABELS,
10+
type SeverityLevel,
11+
} from "@/lib/constants/severity";
712
import type { Post } from "@/types";
813
import { ChevronDownIcon, ChevronUpIcon } from "@/components/ui/icons";
914

1015
interface SearchResponse {
1116
posts?: Post[];
1217
}
1318

14-
const SEVERITY_LABELS: Record<number, string> = {
15-
1: "Minimal",
16-
2: "Low",
17-
3: "Moderate",
18-
4: "Severe",
19-
5: "Critical",
20-
};
19+
const SEVERITY_LEVELS: SeverityLevel[] = [1, 2, 3, 4, 5];
2120

2221
export function SearchResults({
2322
initialQuery,
@@ -28,8 +27,8 @@ export function SearchResults({
2827
}) {
2928
const [query, setQuery] = useState(initialQuery);
3029
const [agentFilter, setAgentFilter] = useState("");
31-
const [minSeverity, setMinSeverity] = useState(1);
32-
const [maxSeverity, setMaxSeverity] = useState(5);
30+
const [minSeverity, setMinSeverity] = useState<SeverityLevel>(1);
31+
const [maxSeverity, setMaxSeverity] = useState<SeverityLevel>(5);
3332
const [filtersOpen, setFiltersOpen] = useState(false);
3433

3534
const [results, setResults] = useState<Post[]>(initialResults);
@@ -211,7 +210,7 @@ export function SearchResults({
211210
aria-labelledby="filter-severity-label"
212211
className="flex gap-1"
213212
>
214-
{[1, 2, 3, 4, 5].map((lvl) => {
213+
{SEVERITY_LEVELS.map((lvl) => {
215214
const inRange = lvl >= minSeverity && lvl <= maxSeverity;
216215
return (
217216
<button
@@ -231,9 +230,15 @@ export function SearchResults({
231230
setMinSeverity(1);
232231
setMaxSeverity(5);
233232
} else if (lvl === minSeverity) {
234-
setMinSeverity(lvl + 1);
233+
const nextLevel = lvl + 1;
234+
if (isSeverityLevel(nextLevel)) {
235+
setMinSeverity(nextLevel);
236+
}
235237
} else if (lvl === maxSeverity) {
236-
setMaxSeverity(lvl - 1);
238+
const previousLevel = lvl - 1;
239+
if (isSeverityLevel(previousLevel)) {
240+
setMaxSeverity(previousLevel);
241+
}
237242
} else {
238243
setMinSeverity(lvl);
239244
setMaxSeverity(lvl);

0 commit comments

Comments
 (0)