Skip to content

Commit

Permalink
feat: display version in UI (#99)
Browse files Browse the repository at this point in the history
Signed-off-by: guillaume <[email protected]>
  • Loading branch information
gruyaume authored Sep 26, 2024
1 parent 072e945 commit 5464d0b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
14 changes: 13 additions & 1 deletion ui/src/app/nav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ vi.mock('next/navigation', () => ({
}));
vi.mock('./auth/authContext', () => ({
useAuth: () => {
return { "user": {"id": 0, "username": "adman" } as User}
return { "user": { "id": 0, "username": "adman" } as User }
}
}))

// Mock the queries module to include deleteCSR, postCSR, and getStatus
vi.mock('./queries', () => {
return {
getStatus: vi.fn(() => Promise.resolve({ version: "1.0.0" })),
deleteCSR: vi.fn(() => Promise.resolve()),
postCSR: vi.fn(() => Promise.resolve()),
rejectCSR: vi.fn(() => Promise.resolve()),
revokeCertificate: vi.fn(() => Promise.resolve()),
};
});


describe('Navigation', () => {
it('should open aside when clicking button', () => {
render(<Navigation><CertificateRequestsTable csrs={[]} /></Navigation>)
Expand Down
22 changes: 20 additions & 2 deletions ui/src/app/nav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client"

import { SetStateAction, Dispatch, useState } from "react"
import { SetStateAction, Dispatch, useState, useEffect } from "react"
import { QueryClient, QueryClientProvider } from "react-query";
import Image from "next/image";
import { Aside, AsideContext } from "./aside";
Expand All @@ -9,10 +9,21 @@ import { usePathname } from "next/navigation";
import { useAuth } from "./auth/authContext";
import UploadCSRAsidePanel from "./certificate_requests/asideForm";
import UploadUserAsidePanel from "./users/asideForm";
import { getStatus } from "./queries"
import { ChangePasswordModalData, ChangePasswordModal, ChangePasswordModalContext } from "./users/components";

export function SideBar({ activePath, sidebarVisible, setSidebarVisible }: { activePath: string, sidebarVisible: boolean, setSidebarVisible: Dispatch<SetStateAction<boolean>> }) {
const [status, setStatus] = useState<{ version: string } | null>(null);
const auth = useAuth()

useEffect(() => {
const fetchStatus = async () => {
const statusData = await getStatus();
setStatus(statusData);
};
fetchStatus();
}, []);

return (
<header className={sidebarVisible ? "l-navigation" : "l-navigation is-collapsed"}>
<div className="l-navigation__drawer">
Expand Down Expand Up @@ -47,11 +58,18 @@ export function SideBar({ activePath, sidebarVisible, setSidebarVisible }: { act
</li>
}
</ul>
<ul className="p-side-navigation__list" style={{ bottom: 0, position: "absolute", width: "100%" }}>
<ul className="p-side-navigation__list" style={{ bottom: "64px", position: "absolute", width: "100%" }}>
<li className="p-side-navigation__item" >
<AccountTab />
</li>
</ul>
<ul className="p-side-navigation__list" style={{ bottom: 0, position: "absolute", width: "100%" }}>
<li className="p-side-navigation__item">
<span className="p-side-navigation__text">
Version {status?.version}
</span>
</li>
</ul>
</nav>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export type UserEntry = {

export type statusResponse = {
initialized: boolean
version: string
}

0 comments on commit 5464d0b

Please sign in to comment.