Skip to content

Commit

Permalink
fix bug causing 100% cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsgstrabo committed Dec 18, 2024
1 parent fbfa162 commit dd2aa8c
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/components/vulnerability-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,16 @@ const severityOrder: Record<string, number> = {
low: 4,
};

function useGroupVulnerabilities(
vulnerabilities: Array<Vulnerability>
): Record<string, Array<Vulnerability>> {
const [groupedList, setGroupedList] = useState<
Record<string, Array<Vulnerability>>
>({});

useEffect(() => {
const list = dataSorter(vulnerabilities, [
(a, b) => sortCompareNumber(a.cvss, b.cvss, 'descending'),
]).reduce<Record<string, Array<Vulnerability>>>((obj, x) => {
const key = x.severity.toLowerCase();
(obj[key] = obj[key] ?? []).push(x);
return obj;
}, {});

setGroupedList(list);
}, [vulnerabilities]);

return groupedList;
}

export const VulnerabilityDetails: FunctionComponent<
VulnerabilityDetailsProps
> = ({ vulnerabilities, direction = 'ascending' }) => {
const groupedList = useGroupVulnerabilities(vulnerabilities ?? []);
const groupedList = dataSorter(vulnerabilities, [
(a, b) => sortCompareNumber(a.cvss, b.cvss, 'descending'),
]).reduce<Record<string, Array<Vulnerability>>>((obj, x) => {
const key = x.severity.toLowerCase();
(obj[key] = obj[key] ?? []).push(x);
return obj;
}, {});
const keys = Object.keys(groupedList);

return keys.length > 0 ? (
Expand Down

0 comments on commit dd2aa8c

Please sign in to comment.