Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Clicking on logo goes to correct url

yuneng-jiang4ea3c527c2f6
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/healthReadiness/useHealthReadiness.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/healthReadiness/useHealthReadiness.ts
new file mode 100644
index 00000000000..e7e599d08be
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/healthReadiness/useHealthReadiness.ts
@@ -0,0 +1,27 @@
+import { useQuery, UseQueryResult } from "@tanstack/react-query";
+import { createQueryKeys } from "../common/queryKeysFactory";
+import { getProxyBaseUrl } from "@/components/networking";
+
+const healthReadinessKeys = createQueryKeys("healthReadiness");
+
+interface HealthReadinessResponse {
+ litellm_version?: string;
+ [key: string]: any;
+}
+
+const fetchHealthReadiness = async (): Promise<HealthReadinessResponse> => {
+ const baseUrl = getProxyBaseUrl();
+ const response = await fetch(`${baseUrl}/health/readiness`);
+ if (!response.ok) {
+ throw new Error(`Failed to fetch health readiness: ${response.statusText}`);
+ }
+ return response.json();
+};
+
+export const useHealthReadiness = (): UseQueryResult<HealthReadinessResponse> => {
+ return useQuery<HealthReadinessResponse>({
+ queryKey: healthReadinessKeys.detail("readiness"),
+ queryFn: fetchHealthReadiness,
+ staleTime: 5 * 60 * 1000, // 5 minutes
+ });
+};
diff --git a/ui/litellm-dashboard/src/components/navbar.test.tsx b/ui/litellm-dashboard/src/components/navbar.test.tsx
new file mode 100644
index 00000000000..711f17da32e
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/navbar.test.tsx
@@ -0,0 +1,181 @@
+import { describe, it, expect, vi } from "vitest";
+import { renderWithProviders, screen, waitFor } from "../../tests/test-utils";
+import userEvent from "@testing-library/user-event";
+import Navbar from "./navbar";
+
+// Mock the hooks and utilities
+vi.mock("@/components/networking", () => ({
+ getProxyBaseUrl: vi.fn(() => "http://localhost:4000"),
+}));
+
+vi.mock("@/utils/proxyUtils", () => ({
+ fetchProxySettings: vi.fn(),
+}));
+
+// Create mock functions that can be controlled in tests
+let mockUseThemeImpl = () => ({ logoUrl: null as string | null });
+let mockUseHealthReadinessImpl = () => ({ data: null as any });
+let mockGetLocalStorageItemImpl = () => null as string | null;
+
+vi.mock("@/contexts/ThemeContext", () => ({
+ useTheme: () => mockUseThemeImpl(),
+}));
+
+vi.mock("@/app/(dashboard)/hooks/healthReadiness/useHealthReadiness", () => ({
+ useHealthReadiness: () => mockUseHealthReadinessImpl(),
+}));
+
+vi.mock("@/utils/localStorageUtils", () => ({
+ getLocalStorageItem: () => mockGetLocalStorageItemImpl(),
+ setLocalStorageItem: vi.fn(),
+ removeLocalStorageItem: vi.fn(),
+ emitLocalStorageChange: vi.fn(),
+}));
+
+vi.mock("@/utils/cookieUtils", () => ({
+ clearTokenCookies: vi.fn(),
+}));
+
+// Mock window.location.href for logout testing
+Object.defineProperty(window, "location", {
+ value: { href: "" },
+ writable: true,
+});
+
+describe("Navbar", () => {
+ const defaultProps = {
+ userID: "test-user",
+ userEmail: "[email protected]",
+ userRole: "Admin",
+ premiumUser: false,
+ proxySettings: {},
+ setProxySettings: vi.fn(),
+ accessToken: "test-token",
+ isPublicPage: false,
+ };
+
+ it("should render without crashing", () => {
+ renderWithProviders(<Navbar {...defaultProps} />);
+
+ expect(screen.getByText("Docs")).toBeInTheDocument();
+ expect(screen.getByText("User")).toBeInTheDocument();
+ });
+
+ it("should display user information in dropdown", async () => {
+ const user = userEvent.setup();
+ renderWithProviders(<Navbar {...defaultProps} />);
+
+ await user.click(screen.getByText("User"));
+
+ await waitFor(() => {
+ expect(screen.getByText("test-user")).toBeInTheDocument();
+ });
+ expect(screen.getByText("Admin")).toBeInTheDocument();
+ expect(screen.getByText("[email protected]")).toBeInTheDocument();
+ });
+
+ it("should show sidebar toggle button when onToggleSidebar is provided", () => {
+ const mockToggle = vi.fn();
+ renderWithProviders(<Navbar {...defaultProps} onToggleSidebar={mockToggle} />);
+
+ const toggleButton = screen.getByTitle("Collapse sidebar");
+ expect(toggleButton).toBeInTheDocument();
+ });
+
+ it("should call onToggleSidebar when sidebar button is clicked", async () => {
+ const mockToggle = vi.fn();
+ const user = userEvent.setup();
+ renderWithProviders(<Navbar {...defaultProps} onToggleSidebar={mockToggle} />);
+
+ const toggleButton = screen.getByTitle("Collapse sidebar");
+ await user.click(toggleButton);
+
+ expect(mockToggle).toHaveBeenCalledTimes(1);
+ });
+
+ it("should show premium user badge when premiumUser is true", async () => {
+ const user = userEvent.setup();
+ const premiumProps = { ...defaultProps, premiumUser: true };
+ renderWithProviders(<Navbar {...premiumProps} />);
+
+ await user.click(screen.getByText("User"));
+
+ await waitFor(() => {
+ expect(screen.getByText("Premium")).toBeInTheDocument();
+ });
+ });
+
+ it("should show version badge when health data contains version", () => {
+ mockUseHealthReadinessImpl = () => ({ data: { litellm_version: "1.0.0" } });
+
+ renderWithProviders(<Navbar {...defaultProps} />);
+
+ expect(screen.getByText("v1.0.0")).toBeInTheDocument();
+
+ // Reset mock
+ mockUseHealthReadinessImpl = () => ({ data: null });
+ });
+
+ it("should use custom logo from theme context", () => {
+ mockUseThemeImpl = () => ({ logoUrl: "https://example.com/custom-logo.png" });
+
+ renderWithProviders(<Navbar {...defaultProps} />);
+
+ const logoImg = screen.getByAltText("LiteLLM Brand");
+ expect(logoImg).toHaveAttribute("src", "https://example.com/custom-logo.png");
+
+ // Reset mock
+ mockUseThemeImpl = () => ({ logoUrl: null });
+ });
+
+ it("should hide user dropdown on public pages", () => {
+ const publicPageProps = { ...defaultProps, isPublicPage: true };
+ renderWithProviders(<Navbar {...publicPageProps} />);
+
+ expect(screen.queryByText("User")).not.toBeInTheDocument();
+ });
+
+ it("should handle hide new features toggle", async () => {
+ const user = userEvent.setup();
+
+ // Initially disabled
+ mockGetLocalStorageItemImpl = () => "false";
+
+ renderWithProviders(<Navbar {...defaultProps} />);
+
+ await user.click(screen.getByText("User"));
+
+ await waitFor(() => {
+ expect(screen.getByText("test-user")).toBeInTheDocument();
+ });
+
+ // Find and click the toggle switch
+ const toggleSwitch = screen.getByLabelText("Toggle hide new feature indicators");
+ await user.click(toggleSwitch);
+
+ // The functions are mocked globally, so we can check if they were called
+ // by accessing them through the mock registry
+ const localStorageUtils = vi.mocked(await import("@/utils/localStorageUtils"));
+ expect(localStorageUtils.setLocalStorageItem).toHaveBeenCalledWith("disableShowNewBadge", "true");
+ expect(localStorageUtils.emitLocalStorageChange).toHaveBeenCalledWith("disableShowNewBadge");
+ });
+
+ it("should handle logout functionality", async () => {
+ const user = userEvent.setup();
+
+ renderWithProviders(<Navbar {...defaultProps} />);
+
+ await user.click(screen.getByText("User"));
+
+ await waitFor(() => {
+ expect(screen.getByText("test-user")).toBeInTheDocument();
+ });
+
+ // Click logout
+ await user.click(screen.getByText("Logout"));
+
+ const cookieUtils = vi.mocked(await import("@/utils/cookieUtils"));
+ expect(cookieUtils.clearTokenCookies).toHaveBeenCalled();
+ expect(window.location.href).toBe("");
+ });
+});
diff --git a/ui/litellm-dashboard/src/components/navbar.tsx b/ui/litellm-dashboard/src/components/navbar.tsx
index 23b31ec4821..7d5ee3dd6f4 100644
--- a/ui/litellm-dashboard/src/components/navbar.tsx
+++ b/ui/litellm-dashboard/src/components/navbar.tsx
@@ -17,6 +17,7 @@ import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from
import { fetchProxySettings } from "@/utils/proxyUtils";
import { useTheme } from "@/contexts/ThemeContext";
import { emitLocalStorageChange } from "@/utils/localStorageUtils";
+import { useHealthReadiness } from "@/app/(dashboard)/hooks/healthReadiness/useHealthReadiness";
interface NavbarProps {
userID: string | null;
@@ -44,30 +45,16 @@ const Navbar: React.FC<NavbarProps> = ({
onToggleSidebar,
}) => {
const baseUrl = getProxyBaseUrl();
+ console.log("baseUrl", baseUrl);
const [logoutUrl, setLogoutUrl] = useState("");
- const [version, setVersion] = useState("");
const [disableShowNewBadge, setDisableShowNewBadge] = useState(false);
const { logoUrl } = useTheme();
+ const { data: healthData } = useHealthReadiness();
+ const version = healthData?.litellm_version;
// Simple logo URL: use custom logo if available, otherwise default
const imageUrl = logoUrl || `${baseUrl}/get_image`;
- useEffect(() => {
- const fetchVersion = async () => {
- try {
- const response = await fetch(`${baseUrl}/health/readiness`);
- const data = await response.json();
- if (data.litellm_version) {
- setVersion(data.litellm_version);
- }
- } catch (error) {
- console.error("Failed to fetch version:", error);
- }
- };
-
- fetchVersion();
- }, [baseUrl]);
-
useEffect(() => {
const initializeProxySettings = async () => {
if (accessToken) {
@@ -190,7 +177,7 @@ const Navbar: React.FC<NavbarProps> = ({
)}
<div className="flex items-center">
- <Link href="/" className="flex items-center">
+ <Link href={baseUrl ? baseUrl : "/"} className="flex items-center">
<div className="relative">
<img src={imageUrl} alt="LiteLLM Brand" className="h-10 w-auto" />
<span