Skip to content

Commit

Permalink
fix bug causing 100% cpu (#1157)
Browse files Browse the repository at this point in the history
* fix bug causing 100% cpu

* fix lint errors
  • Loading branch information
nilsgstrabo authored Dec 18, 2024
1 parent fbfa162 commit 846c67c
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/components/vulnerability-details/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Accordion } from '@equinor/eds-core-react';
import { type FunctionComponent, useEffect, useState } from 'react';
import type { FunctionComponent } from 'react';

import type { Vulnerability } from '../../store/scan-api';
import {
Expand All @@ -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 846c67c

Please sign in to comment.