Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate link to the package manager in SBOM page using PURL #10625

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions src/pages/Licenses/Licenses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { useState } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";

import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
Expand All @@ -21,6 +19,24 @@ const sbomUrlMap = {
backend: "/sbom/care-sbom.json",
};

function getPackageUrl(pkgName: string, purl: string) {
if (purl) {
switch (true) {
case purl.startsWith("pkg:pypi/"):
return `https://pypi.org/project/${pkgName}`;
case purl.startsWith("pkg:npm/"):
return `https://www.npmjs.com/package/${pkgName}`;
case purl.startsWith("pkg:github/"):
return `https://github.com/${pkgName}`;
case purl.startsWith("pkg:githubactions/"):
return `https://github.com/actions/${pkgName}`;
default:
return purl;
}
}
return purl;
}

export const LicensesPage = () => {
const { t } = useTranslation();
const [tab, setTab] = useState<"frontend" | "backend">("frontend");
Expand Down Expand Up @@ -102,14 +118,14 @@ const SbomPackage = ({
}: {
pkg: LicensesSbom["sbom"]["packages"][number];
}) => {
const [showExternalRefs, setShowExternalRefs] = useState(false);
const { t } = useTranslation();
return (
<div className="block rounded-md border p-2 transition-all duration-300 hover:shadow-lg">
<a
target="_blank"
rel="noopener noreferrer"
className="hover:text-primary-dark block text-primary"
href={`${getPackageUrl(pkg.name, pkg.externalRefs?.[0].referenceLocator)}`}
>
<strong className="text-lg">{`${pkg.name} v${pkg.versionInfo}`}</strong>
</a>
Expand All @@ -127,31 +143,6 @@ const SbomPackage = ({
</a>
</p>
)}
<div>
<h4
className="block cursor-pointer font-semibold text-primary"
onClick={() => setShowExternalRefs(!showExternalRefs)}
>
<CareIcon icon="l-info-circle" />
</h4>
{showExternalRefs && (
<ul className="list-inside list-disc pl-4 text-xs">
{pkg.externalRefs.map((ref, idx) => (
<li key={idx}>
<a
href={ref.referenceLocator}
className="hover:text-primary-dark block break-words text-primary"
>
{ref.referenceLocator}
</a>
{ref.referenceCategory && (
<p>{t("category") + ": " + ref.referenceCategory}</p>
)}
</li>
))}
</ul>
)}
</div>
</div>
);
};
Loading