feat(web): 任务发现 tab 支持严重度筛选与排序

对齐全局发现页:共用 severity chip、Case 列表 sort=severity,
原始上报列表前端按严重度过滤并排序。
This commit is contained in:
RuoJi6 committed 2026-10-26 09:14:28 +08:00
1 parent 620ca5d96c
commit 0ecaea2fb2
5 files changed
+134 -26

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
import { filterAndSortFindings } from "./finding-severity.ts";
import assert from "node:assert/strict";
import test from "node:test";
const finding = (id, severity, ts, extra = {}) => ({
id,
severity,
ts,
vulnclass: "XSS",
status: "confirmed",
summary: id,
evidence: "",
...extra,
});
const rows = [
finding("1", "low", "2026-10-26T12:00:00Z"),
finding("2", "high", "2026-10-25T12:00:00Z"),
finding("3", "critical", "2026-10-24T12:00:00Z"),
finding("4", "medium", "2026-10-26T12:00:00Z"),
finding("5", "high", "2026-10-26T12:00:00Z", { inherited: true, source_task_id: "source" }),
];
test("all keeps every report and orders severity before newest time", () => {
assert.deepEqual(
filterAndSortFindings(rows, "all", "desc").map((row) => row.id),
["3", "5", "2", "4", "1"],
);
});
test("each severity filters reports including inherited reports", () => {
for (const severity of ["critical", "high", "medium", "low"]) {
const items = filterAndSortFindings(rows, severity, "desc");
assert.equal(items.length, severity === "high" ? 2 : 1);
assert.ok(items.every((row) => row.severity === severity));
}
assert.equal(filterAndSortFindings(rows, "high", "desc")[0].source_task_id, "source");
});
test("ascending time changes only the order within a severity", () => {
assert.deepEqual(
filterAndSortFindings(rows, "all", "asc").map((row) => row.id),
["3", "2", "5", "4", "1"],
);
});
test("matching severity and timestamp use descending numeric IDs", () => {
const tied = [finding("2", "high", rows[0].ts), finding("10", "high", rows[0].ts)];
for (const direction of ["asc", "desc"]) {
assert.deepEqual(
filterAndSortFindings(tied, "all", direction).map((row) => row.id),
["10", "2"],
);
}
});
test("empty input and a severity without matches return an empty list", () => {
assert.deepEqual(filterAndSortFindings([], "all", "desc"), []);
assert.deepEqual(filterAndSortFindings([rows[0]], "critical", "desc"), []);
});
test("filtering and sorting preserve the polling snapshot", () => {
const snapshot = Object.freeze(rows.map((row) => Object.freeze({ ...row })));
const before = [...snapshot];
assert.notEqual(filterAndSortFindings(snapshot, "all", "desc"), snapshot);
filterAndSortFindings(snapshot, "high", "asc");
assert.deepEqual(snapshot, before);
});
+19
View File
@@ -0,0 +1,19 @@
import type { Finding, Severity } from "./types";
const SEVERITY_RANK: Record<Severity, number> = { critical: 4, high: 3, medium: 2, low: 1 };
export function filterAndSortFindings(
findings: readonly Finding[],
severity: "all" | Severity,
timeDirection: "asc" | "desc",
): Finding[] {
return findings
.filter((finding) => severity === "all" || finding.severity === severity)
.sort((a, b) => {
const severityCompared = (SEVERITY_RANK[b.severity] ?? 0) - (SEVERITY_RANK[a.severity] ?? 0);
if (severityCompared !== 0) return severityCompared;
const timeCompared = Date.parse(a.ts) - Date.parse(b.ts);
if (timeCompared !== 0) return timeDirection === "asc" ? timeCompared : -timeCompared;
return b.id.localeCompare(a.id, undefined, { numeric: true });
});
}
+8
View File
@@ -63,6 +63,14 @@ const severity: Record<string, StatusMeta> = {
low: { label: "低危", tone: "slate" },
};
export const SEVERITY_FILTER_OPTIONS = [
["all", "全部"],
["critical", severity.critical.label],
["high", severity.high.label],
["medium", severity.medium.label],
["low", severity.low.label],
] as const;
const finding: Record<string, StatusMeta> = {
pending: { label: "待处理", tone: "amber" },
in_progress: { label: "处理中", tone: "blue" },