mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 21:11:50 +08:00
feat(web): 任务发现/复测支持严重度筛选与按钮搜索
- 复测 tab:严重度 chip + sort=severity,左侧列表支持关键词搜索 - 发现/复测:输入框草稿 + 搜索按钮(或 Enter)才应用关键词 - 扩展 filterAndSortFindings 客户端关键词匹配并补充单测
This commit is contained in:
1 parent
28b40bafc8
commit
84b40f3004
4 files changed
+188
-32
No files matched your search
@@ -66,3 +66,47 @@ test("filtering and sorting preserve the polling snapshot", () => {
|
||||
filterAndSortFindings(snapshot, "high", "asc");
|
||||
assert.deepEqual(snapshot, before);
|
||||
});
|
||||
|
||||
test("keywords match each searchable field as a trimmed, case-insensitive substring", () => {
|
||||
for (const field of ["name", "vulnclass", "summary", "evidence"]) {
|
||||
const match = finding("match", "high", rows[0].ts, { [field]: "prefix NeEdLe suffix" });
|
||||
assert.deepEqual(filterAndSortFindings([rows[0], match], "all", "desc", " nEEdle "), [match]);
|
||||
}
|
||||
});
|
||||
|
||||
test("unmatched keywords and missing searchable fields return no matches", () => {
|
||||
const missing = finding("missing", "high", rows[0].ts, {
|
||||
name: undefined,
|
||||
vulnclass: undefined,
|
||||
summary: undefined,
|
||||
evidence: undefined,
|
||||
});
|
||||
assert.deepEqual(filterAndSortFindings([...rows, missing], "all", "desc", "needle"), []);
|
||||
assert.deepEqual(filterAndSortFindings([], "all", "desc", "needle"), []);
|
||||
});
|
||||
|
||||
test("undefined, empty and whitespace keywords preserve severity filtering and sorting", () => {
|
||||
for (const query of [undefined, "", " \t\n "]) {
|
||||
for (const severity of ["all", "high"]) {
|
||||
for (const direction of ["asc", "desc"]) {
|
||||
assert.deepEqual(
|
||||
filterAndSortFindings(rows, severity, direction, query),
|
||||
filterAndSortFindings(rows, severity, direction),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("keywords combine with severity and preserve time ordering for inherited reports", () => {
|
||||
const matches = rows.map((row) => ({ ...row, evidence: "Shared keyword" }));
|
||||
assert.deepEqual(
|
||||
filterAndSortFindings(matches, "high", "desc", "KEYWORD").map((row) => row.id),
|
||||
["5", "2"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
filterAndSortFindings(matches, "high", "asc", "keyword").map((row) => row.id),
|
||||
["2", "5"],
|
||||
);
|
||||
assert.deepEqual(filterAndSortFindings(matches, "high", "desc", "absent"), []);
|
||||
});
|
||||
@@ -6,9 +6,18 @@ export function filterAndSortFindings(
|
||||
findings: readonly Finding[],
|
||||
severity: "all" | Severity,
|
||||
timeDirection: "asc" | "desc",
|
||||
query?: string,
|
||||
): Finding[] {
|
||||
const keyword = query?.trim().toLowerCase() ?? "";
|
||||
return findings
|
||||
.filter((finding) => severity === "all" || finding.severity === severity)
|
||||
.filter(
|
||||
(finding) =>
|
||||
(severity === "all" || finding.severity === severity) &&
|
||||
(!keyword ||
|
||||
[finding.name, finding.vulnclass, finding.summary, finding.evidence].some((value) =>
|
||||
(value ?? "").toLowerCase().includes(keyword),
|
||||
)),
|
||||
)
|
||||
.sort((a, b) => {
|
||||
const severityCompared = (SEVERITY_RANK[b.severity] ?? 0) - (SEVERITY_RANK[a.severity] ?? 0);
|
||||
if (severityCompared !== 0) return severityCompared;
|
||||
|
||||
Reference in new issue
Block a user