Skip to content

Commit

Permalink
fix: sbom details-vulnerability tab-render "affected dependencies"
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 committed Nov 25, 2024
1 parent 4e1ed64 commit 24bcbac
Showing 1 changed file with 75 additions and 23 deletions.
98 changes: 75 additions & 23 deletions client/src/app/pages/sbom-details/vulnerabilities-by-sbom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ import {

import { getSeverityPriority } from "@app/api/model-utils";
import { VulnerabilityStatus } from "@app/api/models";
import { SbomAdvisory, SbomPackage, SbomStatus } from "@app/client";
import {
PurlSummary,
SbomAdvisory,
SbomPackage,
SbomStatus,
} from "@app/client";
import { LoadingWrapper } from "@app/components/LoadingWrapper";
import { PackageQualifiers } from "@app/components/PackageQualifiers";
import { SbomVulnerabilitiesDonutChart } from "@app/components/SbomVulnerabilitiesDonutChart";
Expand Down Expand Up @@ -328,29 +333,76 @@ export const VulnerabilitiesBySbom: React.FC<VulnerabilitiesBySbomProps> = ({
</Thead>
<Tbody>
{item.summary.allPackages
.flatMap((item) => item.purl)
.flatMap((item) => {
// Workaround against https://github.com/trustification/trustify/issues/1043
// Some packages do not have purl neither ID. So we render only the parent name meanwhile
type EnrichedPurlSummary = {
parentName: string;
purlSummary?: PurlSummary;
};

const hasNoPurlsButOnlyName =
item.name && item.purl.length == 0;

if (hasNoPurlsButOnlyName) {
const result: EnrichedPurlSummary = {
parentName: item.name,
};
return [result];
} else {
return item.purl.map((i) => {
const result: EnrichedPurlSummary =
{
...i,
parentName: item.name,
};
return result;
});
}
})
.map((purl, index) => {
const decomposedPurl = decomposePurl(
purl.purl
);
return (
<Tr key={index}>
<Td>{decomposedPurl?.type}</Td>
<Td>{decomposedPurl?.namespace}</Td>
<Td>{decomposedPurl?.name}</Td>
<Td>{decomposedPurl?.version}</Td>
<Td>{decomposedPurl?.path}</Td>
<Td>
{decomposedPurl?.qualifiers && (
<PackageQualifiers
value={
decomposedPurl?.qualifiers
}
/>
)}
</Td>
</Tr>
);
if (purl.purlSummary) {
const decomposedPurl = decomposePurl(
purl.purlSummary.purl
);
return (
<Tr key={`${index}-purl`}>
<Td>{decomposedPurl?.type}</Td>
<Td>
{decomposedPurl?.namespace}
</Td>
<Td>
<Link
to={`/packages/${purl.purlSummary.uuid}`}
>
{decomposedPurl?.name}
</Link>
</Td>
<Td>{decomposedPurl?.version}</Td>
<Td>{decomposedPurl?.path}</Td>
<Td>
{decomposedPurl?.qualifiers && (
<PackageQualifiers
value={
decomposedPurl?.qualifiers
}
/>
)}
</Td>
</Tr>
);
} else {
return (
<Tr key={`${index}-name`}>
<Td></Td>
<Td></Td>
<Td>{purl.parentName}</Td>
<Td></Td>
<Td></Td>
<Td></Td>
</Tr>
);
}
})}
</Tbody>
</Table>
Expand Down

0 comments on commit 24bcbac

Please sign in to comment.