mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-26 02:11:51 +08:00
Merge pull request #48 from RuoJi6/feat/finding-dedup-1-2-3
feat(findings): 降低重复确认噪音——分组疑似重复建议、候选打分排序、放宽归并验收(方案1+2+3)
This commit is contained in:
14 files changed
+1000
-129
No files matched your search
@@ -192,15 +192,29 @@ function FindingMergeSuggestionCard({
|
||||
onResolve,
|
||||
}: {
|
||||
suggestion: FindingCaseSuggestion;
|
||||
onResolve: (s: FindingCaseSuggestion, accept: boolean) => Promise<void>;
|
||||
onResolve: (s: FindingCaseSuggestion, accept: boolean, excludeIds?: string[]) => Promise<void>;
|
||||
}) {
|
||||
const [expanded, setExpanded] = React.useState(false);
|
||||
const [busy, setBusy] = React.useState(false);
|
||||
const ids = React.useMemo(
|
||||
() => (Array.isArray(s.finding_ids) && s.finding_ids.length > 0 ? s.finding_ids : [s.left_id, s.right_id]),
|
||||
[s.finding_ids, s.left_id, s.right_id],
|
||||
);
|
||||
const [excluded, setExcluded] = React.useState<string[]>([]);
|
||||
React.useEffect(() => {
|
||||
setExcluded((current) => {
|
||||
const next = current.filter((id) => ids.includes(id));
|
||||
return next.length === current.length ? current : next;
|
||||
});
|
||||
}, [ids]);
|
||||
const validExcluded = excluded.filter((id) => ids.includes(id));
|
||||
const included = ids.filter((id) => !validExcluded.includes(id));
|
||||
async function resolve(accept: boolean) {
|
||||
if (busy) return;
|
||||
if (accept && included.length < 2) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await onResolve(s, accept);
|
||||
await onResolve(s, accept, accept ? validExcluded : []);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -209,17 +223,30 @@ function FindingMergeSuggestionCard({
|
||||
<Card size="sm" className="min-w-0">
|
||||
<CardHeader>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Badge variant="outline">疑似重复 · 待确认</Badge>
|
||||
<Badge variant="outline">疑似重复分组 · {ids.length} 条 · 待确认</Badge>
|
||||
<CardDescription>任务 #{s.task_id}</CardDescription>
|
||||
</div>
|
||||
<CardTitle className="break-words">{s.title}</CardTitle>
|
||||
<CardDescription className="flex flex-wrap gap-3">
|
||||
<Link className="underline underline-offset-4" href={`/function/findings/detail/?id=${s.left_id}`}>
|
||||
查看原报告 #{s.left_id}
|
||||
</Link>
|
||||
<Link className="underline underline-offset-4" href={`/function/findings/detail/?id=${s.right_id}`}>
|
||||
查看原报告 #{s.right_id}
|
||||
</Link>
|
||||
<CardDescription className="flex flex-col gap-1">
|
||||
{ids.map((id) => (
|
||||
<span key={id} className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
checked={!excluded.includes(id)}
|
||||
disabled={busy}
|
||||
onCheckedChange={(value) =>
|
||||
setExcluded((current) =>
|
||||
value === true
|
||||
? current.filter((item) => item !== id)
|
||||
: [...current.filter((item) => item !== id), id],
|
||||
)
|
||||
}
|
||||
aria-label={`归并时包含上报 #${id}`}
|
||||
/>
|
||||
<Link className="underline underline-offset-4" href={`/function/findings/detail/?id=${id}`}>
|
||||
查看原报告 #{id}
|
||||
</Link>
|
||||
</span>
|
||||
))}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
@@ -238,11 +265,12 @@ function FindingMergeSuggestionCard({
|
||||
</Collapsible>
|
||||
</CardContent>
|
||||
<CardFooter className="flex flex-wrap gap-2">
|
||||
<Button variant="outline" size="sm" disabled={busy} onClick={() => resolve(true)}>
|
||||
{busy ? <Spinner /> : null}确认归并
|
||||
<Button variant="outline" size="sm" disabled={busy || included.length < 2} onClick={() => resolve(true)}>
|
||||
{busy ? <Spinner /> : null}
|
||||
{included.length === ids.length ? "整组确认归并" : `确认归并所选(${included.length} 条)`}
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" disabled={busy} onClick={() => resolve(false)}>
|
||||
不是同一漏洞
|
||||
整组不是同一漏洞
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
@@ -271,21 +299,39 @@ export function FindingCaseReviewPanel({ taskId, onChange }: { taskId?: string;
|
||||
const [suggestions, setSuggestions] = React.useState<FindingCaseSuggestion[]>([]);
|
||||
const [runs, setRuns] = React.useState<FindingCaseReviewRun[]>([]);
|
||||
const [error, setError] = React.useState("");
|
||||
const [reload, setReload] = React.useState(0);
|
||||
const requestSeq = React.useRef(0);
|
||||
const taskKey = taskId ?? "";
|
||||
const taskKeyRef = React.useRef(taskKey);
|
||||
taskKeyRef.current = taskKey;
|
||||
const previousTaskKey = React.useRef(taskKey);
|
||||
React.useEffect(() => {
|
||||
if (previousTaskKey.current === taskKey) return;
|
||||
previousTaskKey.current = taskKey;
|
||||
setSuggestions([]);
|
||||
setRuns([]);
|
||||
setError("");
|
||||
}, [taskKey]);
|
||||
React.useEffect(() => {
|
||||
const seq = ++requestSeq.current;
|
||||
const requestedTask = taskKey;
|
||||
void reload;
|
||||
let active = true;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
async function load() {
|
||||
try {
|
||||
const [s, r] = await Promise.all([api.findingCaseSuggestions(taskId), api.findingCaseReviewRuns()]);
|
||||
if (active) {
|
||||
if (active && seq === requestSeq.current && requestedTask === taskKeyRef.current) {
|
||||
setSuggestions(s);
|
||||
setRuns(r.filter((x) => !taskId || x.task_id === taskId));
|
||||
setError("");
|
||||
}
|
||||
} catch (e) {
|
||||
if (active) setError((e as Error).message);
|
||||
if (active && seq === requestSeq.current && requestedTask === taskKeyRef.current)
|
||||
setError((e as Error).message);
|
||||
} finally {
|
||||
if (active) timer = setTimeout(load, 5000);
|
||||
if (active && seq === requestSeq.current && requestedTask === taskKeyRef.current)
|
||||
timer = setTimeout(load, 5000);
|
||||
}
|
||||
}
|
||||
void load();
|
||||
@@ -293,19 +339,29 @@ export function FindingCaseReviewPanel({ taskId, onChange }: { taskId?: string;
|
||||
active = false;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [taskId]);
|
||||
async function resolve(s: FindingCaseSuggestion, accept: boolean) {
|
||||
}, [reload, taskId, taskKey]);
|
||||
async function resolve(s: FindingCaseSuggestion, accept: boolean, excludeIds?: string[]) {
|
||||
const seq = ++requestSeq.current;
|
||||
const requestedTask = taskKey;
|
||||
try {
|
||||
const result = await api.resolveFindingCaseSuggestion(s.id, accept);
|
||||
setSuggestions((v) => v.filter((x) => x.id !== s.id));
|
||||
if (accept && result.case_id !== "0") {
|
||||
toast.success("已归并,请进入文件夹生成统一报告");
|
||||
} else {
|
||||
toast.success("已否决,不会自动再次归并");
|
||||
const result = await api.resolveFindingCaseSuggestion(s.id, accept, excludeIds);
|
||||
if (requestedTask === taskKeyRef.current) {
|
||||
setReload((v) => v + 1);
|
||||
if (seq === requestSeq.current) {
|
||||
setSuggestions((v) => v.filter((x) => x.id !== s.id));
|
||||
if (accept && result.case_id !== "0") {
|
||||
toast.success("已归并,请进入文件夹生成统一报告");
|
||||
} else {
|
||||
toast.success("已否决,不会自动再次归并");
|
||||
}
|
||||
onChange?.();
|
||||
}
|
||||
}
|
||||
onChange?.();
|
||||
} catch (e) {
|
||||
toast.error((e as Error).message);
|
||||
if (requestedTask === taskKeyRef.current) {
|
||||
setReload((v) => v + 1);
|
||||
if (seq === requestSeq.current) toast.error((e as Error).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user