Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
97 changes: 54 additions & 43 deletions static/js/publisher/components/SectionNav/SectionNav.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,66 @@
import { Link } from "react-router-dom";
import { Tabs } from "@canonical/react-components";

import { usePublisher } from "../../hooks";

type Props = {
activeTab: string;
snapName: string | undefined;
};

function SectionNav({ activeTab, snapName }: Props): React.JSX.Element {
return (
<Tabs
listClassName="u-no-margin--bottom"
links={[
{
label: "Listing",
active: activeTab === "listing" || !activeTab,
to: `/${snapName}/listing`,
component: Link,
},
{
label: "Builds",
active: activeTab === "builds",
to: `/${snapName}/builds`,
component: Link,
},
{
label: "Releases",
active: activeTab === "releases",
to: `/${snapName}/releases`,
component: Link,
},
{
label: "Metrics",
active: activeTab === "metrics",
to: `/${snapName}/metrics`,
component: Link,
},
{
label: "Publicise",
active: activeTab === "publicise",
to: `/${snapName}/publicise`,
component: Link,
},
{
label: "Settings",
active: activeTab === "settings",
to: `/${snapName}/settings`,
component: Link,
},
]}
/>
);
const { data: publisherData } = usePublisher();

const links = [
{
label: "Listing",
active: activeTab === "listing" || !activeTab,
to: `/${snapName}/listing`,
component: Link,
},
{
label: "Builds",
active: activeTab === "builds",
to: `/${snapName}/builds`,
component: Link,
},
{
label: "Releases",
active: activeTab === "releases",
to: `/${snapName}/releases`,
component: Link,
},
{
label: "Metrics",
active: activeTab === "metrics",
to: `/${snapName}/metrics`,
component: Link,
},
{
label: "Publicise",
active: activeTab === "publicise",
to: `/${snapName}/publicise`,
component: Link,
},
{
label: "Settings",
active: activeTab === "settings",
to: `/${snapName}/settings`,
component: Link,
},
];

// TODO: verify if the snap has CVE data before adding the link
if (publisherData?.publisher?.is_canonical) {
links.splice(3, 0, {
label: "Vulnerabilities",
active: activeTab === "vulnerabilities",
to: `/${snapName}/cves`,
component: Link,
});
}

return <Tabs listClassName="u-no-margin--bottom" links={links} />;
}

export default SectionNav;
20 changes: 20 additions & 0 deletions static/js/publisher/hooks/useCves.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useQuery } from "react-query";

function useCves() {
return useQuery({
queryKey: ["cves"],
queryFn: async () => {
const response = await fetch(`/api/docker/3213/cves`);
Comment on lines +3 to +7
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fetch path is hard-coded to /api/docker/3213/cves; parameterize or remove this placeholder to avoid confusion and support multiple snaps.

Suggested change
function useCves() {
return useQuery({
queryKey: ["cves"],
queryFn: async () => {
const response = await fetch(`/api/docker/3213/cves`);
function useCves(snapId: string) {
return useQuery({
queryKey: ["cves", snapId],
queryFn: async () => {
const response = await fetch(`/api/docker/${snapId}/cves`);

Copilot uses AI. Check for mistakes.


if (!response.ok) {
throw new Error("Unable to fetch CVEs");
}

const responseData = await response.json();

return responseData;
},
});
}

export default useCves;
Loading
Loading