diff --git a/changes/bug-6708-soft-vuln-count b/changes/bug-6708-soft-vuln-count new file mode 100644 index 0000000000..d8ccb0e19a --- /dev/null +++ b/changes/bug-6708-soft-vuln-count @@ -0,0 +1 @@ +* Render correct software vulnerabilities count on host details page \ No newline at end of file diff --git a/frontend/pages/hosts/details/cards/Software/SoftwareTableConfig.tsx b/frontend/pages/hosts/details/cards/Software/SoftwareTableConfig.tsx index b4d7741a20..4b3f0ec180 100644 --- a/frontend/pages/hosts/details/cards/Software/SoftwareTableConfig.tsx +++ b/frontend/pages/hosts/details/cards/Software/SoftwareTableConfig.tsx @@ -5,7 +5,6 @@ import ReactTooltip from "react-tooltip"; import { formatDistanceToNow } from "date-fns"; import { ISoftware } from "interfaces/software"; -import { IVulnerability } from "interfaces/vulnerability"; import PATHS from "router/paths"; import HeaderCell from "components/TableContainer/DataTable/HeaderCell/HeaderCell"; @@ -90,15 +89,12 @@ const formatSoftwareType = (source: string) => { return DICT[source] || "Unknown"; }; -const condenseVulnerabilities = (vulns: IVulnerability[]): string[] => { +const condenseVulnerabilities = (vulns: string[]): string[] => { const condensed = - (vulns?.length && - vulns - .slice(-3) - .map((v) => v.cve) - .reverse()) || - []; - return vulns?.length > 3 + (vulns?.length && vulns.length === 4 + ? vulns.slice(-4).reverse() + : vulns.slice(-3).reverse()) || []; + return vulns?.length > 4 ? condensed.concat(`+${vulns?.length - 3} more`) : condensed; }; @@ -113,7 +109,7 @@ export const generateSoftwareTableData = ( return software.map((s) => { return { ...s, - vulnerabilities: condenseVulnerabilities(s.vulnerabilities || []), + vulnerabilities: s.vulnerabilities?.map((v) => v.cve) || [], }; }); }; @@ -193,14 +189,17 @@ export const generateSoftwareTableHeaders = ( filter: "hasLength", // filters out rows where vulnerabilities has no length if filter value is `true` Cell: (cellProps: IVulnCellProps): JSX.Element => { const vulnerabilities = cellProps.cell.value || []; - const tooltipText = vulnerabilities?.map((value) => { - return ( - - {value} -
-
- ); - }); + + const tooltipText = condenseVulnerabilities(vulnerabilities).map( + (value) => { + return ( + + {value} +
+
+ ); + } + ); if (!vulnerabilities?.length) { return ---;