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]

refactor(ui): retire the tremor date range picker in favour of the shared advanced picker (#37302)

ryan-crabbe-berriceeab01b0d35
diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.json
index 69c16f2022b..d51704551e4 100644
--- a/ui/litellm-dashboard/eslint-suppressions.json
+++ b/ui/litellm-dashboard/eslint-suppressions.json
@@ -2644,9 +2644,6 @@
"local/filename-pascal-case": {
"count": 1
},
- "no-restricted-imports": {
- "count": 1
- },
"react-hooks/set-state-in-effect": {
"count": 3
}
@@ -2746,14 +2743,6 @@
"count": 1
}
},
- "src/components/shared/usage_date_picker.tsx": {
- "local/filename-pascal-case": {
- "count": 1
- },
- "no-restricted-imports": {
- "count": 1
- }
- },
"src/components/tag_management/types.tsx": {
"local/filename-pascal-case": {
"count": 1
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/caching/_components/cache_dashboard.tsx b/ui/litellm-dashboard/src/app/(dashboard)/caching/_components/cache_dashboard.tsx
index efdd4c479ee..62c456b1b38 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/caching/_components/cache_dashboard.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/caching/_components/cache_dashboard.tsx
@@ -1,7 +1,7 @@
import type { DateRangePickerValue } from "@/components/shared/date_picker_types";
import React, { useEffect, useState } from "react";
import { toast } from "@/lib/toast";
-import UsageDatePicker from "@/components/shared/usage_date_picker";
+import AdvancedDatePicker from "@/components/shared/advanced_date_picker";
import { BarChart } from "@/components/shared/charts";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@@ -190,7 +190,7 @@ const CacheDashboard: React.FC<CachePageProps> = ({ accessToken, token, userRole
Metrics&quot; on the Usage page or individual requests in the Logs page.
</p>
- <div className="mt-4 grid grid-cols-1 items-center gap-4 md:grid-cols-3">
+ <div className="mt-4 grid grid-cols-1 items-center gap-4 md:grid-cols-[1fr_1fr_auto]">
<Combobox
multiple
items={uniqueApiKeys}
@@ -251,7 +251,7 @@ const CacheDashboard: React.FC<CachePageProps> = ({ accessToken, token, userRole
</ComboboxContent>
</Combobox>
- <UsageDatePicker
+ <AdvancedDatePicker
value={dateValue}
onValueChange={(value) => {
setDateValue(value);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/old-usage/_components/usage.tsx b/ui/litellm-dashboard/src/app/(dashboard)/old-usage/_components/usage.tsx
index a0835729f1b..7fe67fb9a41 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/old-usage/_components/usage.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/old-usage/_components/usage.tsx
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
import ViewUserSpend from "@/components/view_user_spend";
import { ProxySettings } from "@/components/user_dashboard";
-import UsageDatePicker from "@/components/shared/usage_date_picker";
+import AdvancedDatePicker from "@/components/shared/advanced_date_picker";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import {
@@ -796,7 +796,8 @@ const UsagePage: React.FC<UsagePageProps> = ({ accessToken, token, userRole, use
</p>
<div className="grid grid-cols-2">
<div>
- <UsageDatePicker
+ <AdvancedDatePicker
+ align="left"
value={dateValue}
onValueChange={(value) => {
setDateValue(value);
@@ -862,7 +863,8 @@ const UsagePage: React.FC<UsagePageProps> = ({ accessToken, token, userRole, use
<TabsContent value="tag-based-usage">
<div className="grid grid-cols-2">
<div className="col-span-1">
- <UsageDatePicker
+ <AdvancedDatePicker
+ align="left"
className="mb-4"
value={dateValue}
onValueChange={(value) => {
diff --git a/ui/litellm-dashboard/src/components/shared/advanced_date_picker.test.tsx b/ui/litellm-dashboard/src/components/shared/advanced_date_picker.test.tsx
index 90d75df75e4..c907aeae035 100644
--- a/ui/litellm-dashboard/src/components/shared/advanced_date_picker.test.tsx
+++ b/ui/litellm-dashboard/src/components/shared/advanced_date_picker.test.tsx
@@ -1,4 +1,5 @@
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach, beforeAll } from "vitest";
import AdvancedDatePicker from "./advanced_date_picker";
@@ -28,9 +29,10 @@ describe("AdvancedDatePicker", () => {
mockOnValueChange.mockClear();
});
+ const getTrigger = (container: HTMLElement) => container.querySelector('[data-slot="advanced-date-picker-trigger"]');
+
const openDropdown = (container: HTMLElement) => {
- // Find the clickable div that contains the clock icon
- const trigger = container.querySelector('[role="img"][aria-label="clock-circle"]')?.closest("div.cursor-pointer");
+ const trigger = getTrigger(container);
if (trigger) {
fireEvent.click(trigger);
}
@@ -76,6 +78,39 @@ describe("AdvancedDatePicker", () => {
expect(screen.getByText("Year to date")).toBeInTheDocument();
});
+ it("anchors the panel to the trigger edge named by align", () => {
+ const { container, unmount } = render(
+ <AdvancedDatePicker value={defaultValue} onValueChange={mockOnValueChange} align="left" />,
+ );
+ openDropdown(container);
+ const leftPanel = container.querySelector('[data-slot="advanced-date-picker-panel"]');
+ expect(leftPanel).toHaveAttribute("data-align", "left");
+ unmount();
+
+ const { container: defaultContainer } = render(
+ <AdvancedDatePicker value={defaultValue} onValueChange={mockOnValueChange} />,
+ );
+ openDropdown(defaultContainer);
+ const rightPanel = defaultContainer.querySelector('[data-slot="advanced-date-picker-panel"]');
+ expect(rightPanel).toHaveAttribute("data-align", "right");
+ });
+
+ it("opens the dropdown from the keyboard alone", async () => {
+ const user = userEvent.setup();
+ const { container } = render(<AdvancedDatePicker value={defaultValue} onValueChange={mockOnValueChange} />);
+
+ await user.tab();
+
+ const trigger = getTrigger(container);
+ expect(trigger).toHaveFocus();
+ expect(trigger).toHaveAttribute("aria-expanded", "false");
+
+ await user.keyboard("{Enter}");
+
+ expect(screen.getByText("Relative time")).toBeInTheDocument();
+ expect(trigger).toHaveAttribute("aria-expanded", "true");
+ });
+
it("should show date inputs in dropdown", () => {
const { container } = render(<AdvancedDatePicker value={defaultValue} onValueChange={mockOnValueChange} />);
@@ -142,7 +177,29 @@ describe("AdvancedDatePicker", () => {
fireEvent.click(todayOption);
// The option should be highlighted (bg-blue-50)
- expect(todayOption.closest("div")).toHaveClass("bg-blue-50");
+ expect(todayOption.closest("button")).toHaveClass("bg-blue-50");
+ });
+
+ it("selects a relative range from the keyboard alone", async () => {
+ const user = userEvent.setup();
+ const { container } = render(<AdvancedDatePicker value={defaultValue} onValueChange={mockOnValueChange} />);
+
+ await user.tab();
+ await user.keyboard("{Enter}");
+
+ const presets = Array.from(container.querySelectorAll('[data-slot="advanced-date-picker-preset"]'));
+ expect(presets).toHaveLength(5);
+
+ await user.tab();
+ expect(presets[0]).toHaveFocus();
+ expect(presets[0]).toHaveAttribute("aria-pressed", "false");
+
+ await user.tab();
+ expect(presets[1]).toHaveFocus();
+
+ await user.keyboard("{Enter}");
+ expect(presets[1]).toHaveAttribute("aria-pressed", "true");
+ expect(screen.getByText("Last 7 days").closest("button")).toHaveClass("bg-blue-50");
});
it("should show validation error for invalid date range", async () => {
diff --git a/ui/litellm-dashboard/src/components/shared/advanced_date_picker.tsx b/ui/litellm-dashboard/src/components/shared/advanced_date_picker.tsx
index 03d5e1bc630..b9a4d28539b 100644
--- a/ui/litellm-dashboard/src/components/shared/advanced_date_picker.tsx
+++ b/ui/litellm-dashboard/src/components/shared/advanced_date_picker.tsx
@@ -1,5 +1,6 @@
import { CalendarOutlined, ClockCircleOutlined } from "@ant-design/icons";
-import { Button, Text } from "@tremor/react";
+import { Button } from "@/components/ui/button";
+import { cn } from "@/lib/cva.config";
import type { DateRangePickerValue } from "./date_picker_types";
import moment from "moment";
import React, { useCallback, useEffect, useRef, useState } from "react";
@@ -10,6 +11,7 @@ interface AdvancedDatePickerProps {
label?: string;
className?: string;
showTimeRange?: boolean;
+ align?: "left" | "right";
}
interface RelativeTimeOption {
@@ -68,7 +70,9 @@ const AdvancedDatePicker: React.FC<AdvancedDatePickerProps> = ({
value,
onValueChange,
label = "Select Time Range",
+ className,
showTimeRange = true,
+ align = "right",
}) => {
const [isOpen, setIsOpen] = useState(false);
const [tempValue, setTempValue] = useState<DateRangePickerValue>(value);
@@ -274,19 +278,22 @@ const AdvancedDatePicker: React.FC<AdvancedDatePickerProps> = ({
};
return (
- <div className="flex items-center gap-3">
- {label && <Text className="text-sm font-medium text-gray-700 whitespace-nowrap">{label}</Text>}
+ <div className={cn("flex items-center gap-3", className)}>
+ {label && <p className="text-sm font-medium text-gray-700 whitespace-nowrap">{label}</p>}
<div className="relative" ref={dropdownRef}>
{/* Main input display */}
- <div
- className="w-[300px] px-3 py-2 text-sm border border-gray-300 rounded-md bg-white cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500"
+ <button
+ type="button"
+ data-slot="advanced-date-picker-trigger"
+ aria-expanded={isOpen}
+ className="w-[300px] px-3 py-2 text-sm text-left border border-gray-300 rounded-md bg-white cursor-pointer hover:border-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500"
onClick={() => setIsOpen(!isOpen)}
>
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-2">
+ <span className="flex items-center justify-between">
+ <span className="flex items-center gap-2">
<ClockCircleOutlined className="text-gray-600" />
<span className="text-gray-900">{formatDisplayRange(value.from, value.to)}</span>
- </div>
+ </span>
<svg
className={`w-4 h-4 text-gray-400 transition-transform ${isOpen ? "rotate-180" : ""}`}
fill="none"
@@ -295,12 +302,19 @@ const AdvancedDatePicker: React.FC<AdvancedDatePickerProps> = ({
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
</svg>
- </div>
- </div>
+ </span>
+ </button>
{/* Dropdown panel */}
{isOpen && (
- <div className="absolute top-full right-0 z-9999 min-w-[600px] mt-1 bg-white border border-gray-200 rounded-lg shadow-xl">
+ <div
+ data-slot="advanced-date-picker-panel"
+ data-align={align}
+ className={cn(
+ "absolute top-full z-9999 min-w-[600px] mt-1 bg-white border border-gray-200 rounded-lg shadow-xl",
+ align === "left" ? "left-0" : "right-0",
+ )}
+ >
<div className="flex">
{/* Left side - Relative time options */}
<div className="w-1/2 border-r border-gray-200">
@@ -311,9 +325,12 @@ const AdvancedDatePicker: React.FC<AdvancedDatePickerProps> = ({
{relativeTimeOptions.map((option) => {
const isSelected = selectedOption === option.shortLabel;
return (
- <div
+ <button
key={option.label}
- className={`flex items-center justify-between px-5 py-4 cursor-pointer border-b border-gray-100 transition-colors ${
+ type="button"
+ data-slot="advanced-date-picker-preset"
+ aria-pressed={isSelected}
+ className={`flex w-full items-center justify-between px-5 py-4 text-left cursor-pointer border-b border-gray-100 transition-colors ${
isSelected ? "bg-blue-50 hover:bg-blue-100 border-blue-200" : "hover:bg-gray-50"
}`}
onClick={() => handleRelativeTimeSelect(option)}
@@ -328,7 +345,7 @@ const AdvancedDatePicker: React.FC<AdvancedDatePickerProps> = ({
>
{option.shortLabel}
</span>
- </div>
+ </button>
);
})}
</div>
diff --git a/ui/litellm-dashboard/src/components/shared/usage_date_picker.test.tsx b/ui/litellm-dashboard/src/components/shared/usage_date_picker.test.tsx
deleted file mode 100644
index 46fd8181560..00000000000
--- a/ui/litellm-dashboard/src/components/shared/usage_date_picker.test.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import { render, screen, within } from "@testing-library/react";
-import userEvent from "@testing-library/user-event";
-import { beforeAll, describe, expect, it, vi } from "vitest";
-import UsageDatePicker from "./usage_date_picker";
-
-beforeAll(() => {
- vi.stubGlobal("requestIdleCallback", (cb: IdleRequestCallback) => {
- cb({ didTimeout: false, timeRemaining: () => 50 } as IdleDeadline);
- return 0;
- });
-});
-
-describe("UsageDatePicker (tremor DateRangePicker on date-fns 4)", () => {
- const value = { from: new Date(2026, 5, 1), to: new Date(2026, 5, 15) };
-
- it("renders the formatted range label", () => {
- render(<UsageDatePicker value={value} onValueChange={() => {}} />);
-
- const triggerText = screen.getAllByRole("button")[0].textContent ?? "";
- expect(triggerText).toMatch(/Jun/);
- expect(triggerText).toMatch(/2026/);
- expect(triggerText).toMatch(/15/);
- });
-
- it("opens the calendar and renders a full month grid", async () => {
- const user = userEvent.setup();
- render(<UsageDatePicker value={value} onValueChange={() => {}} />);
-
- await user.click(screen.getAllByRole("button")[0]);
-
- const grid = await screen.findByRole("grid");
- const dayCells = within(grid).getAllByRole("gridcell");
- expect(dayCells.length).toBeGreaterThanOrEqual(28);
- expect(within(grid).getByText("15")).toBeInTheDocument();
- });
-
- it("fires onValueChange when a day is selected", async () => {
- const user = userEvent.setup();
- const onValueChange = vi.fn();
- render(<UsageDatePicker value={value} onValueChange={onValueChange} />);
-
- await user.click(screen.getAllByRole("button")[0]);
- const grid = await screen.findByRole("grid");
- await user.click(within(grid).getByText("10"));
-
- expect(onValueChange).toHaveBeenCalled();
- const newValue = onValueChange.mock.calls[0][0];
- expect(newValue.from).toBeInstanceOf(Date);
- });
-});
diff --git a/ui/litellm-dashboard/src/components/shared/usage_date_picker.tsx b/ui/litellm-dashboard/src/components/shared/usage_date_picker.tsx
deleted file mode 100644
index 390da4c8f88..00000000000
--- a/ui/litellm-dashboard/src/components/shared/usage_date_picker.tsx
+++ /dev/null
@@ -1,157 +0,0 @@
-import React, { useCallback, useState, useRef } from "react";
-import { DateRangePicker, Text } from "@tremor/react";
-import type { DateRangePickerValue } from "./date_picker_types";
-
-interface UsageDatePickerProps {
- value: DateRangePickerValue;
- onValueChange: (value: DateRangePickerValue) => void;
- label?: string;
- className?: string;
- showTimeRange?: boolean;
-}
-
-/**
- * Ultra responsive date picker with instant click feedback
- */
-const UsageDatePicker: React.FC<UsageDatePickerProps> = ({
- value,
- onValueChange,
- label = "Select Time Range",
- className = "",
- showTimeRange = true,
-}) => {
- const [showSelectedFeedback, setShowSelectedFeedback] = useState(false);
- const datePickerRef = useRef<HTMLDivElement>(null);
-
- // This only triggers AFTER user has actually made a selection
- const handleDateChange = useCallback(
- (newValue: DateRangePickerValue) => {
- // Show "Selected" feedback ONLY after actual selection is made
- setShowSelectedFeedback(true);
-
- // Hide the feedback after a short time
- setTimeout(() => setShowSelectedFeedback(false), 1500);
-
- // Update parent immediately
- onValueChange(newValue);
-
- // Do heavy processing in background
- requestIdleCallback(
- () => {
- if (newValue.from) {
- const adjustedValue = { ...newValue };
- const adjustedStartTime = new Date(newValue.from);
- let adjustedEndTime: Date;
-
- if (newValue.to) {
- adjustedEndTime = new Date(newValue.to);
- } else {
- adjustedEndTime = new Date(newValue.from);
- }
-
- const isSameDay = adjustedStartTime.toDateString() === adjustedEndTime.toDateString();
-
- if (isSameDay) {
- adjustedStartTime.setHours(0, 0, 0, 0);
- adjustedEndTime.setHours(23, 59, 59, 999);
- } else {
- adjustedStartTime.setHours(0, 0, 0, 0);
- adjustedEndTime.setHours(23, 59, 59, 999);
- }
-
- adjustedValue.from = adjustedStartTime;
- adjustedValue.to = adjustedEndTime;
- onValueChange(adjustedValue);
- }
- },
- { timeout: 100 },
- );
- },
- [onValueChange],
- );
-
- const formatTimeRange = useCallback((from: Date | undefined, to: Date | undefined) => {
- if (!from || !to) return "";
-
- const formatDateTime = (date: Date) => {
- return date.toLocaleString("en-US", {
- month: "short",
- day: "numeric",
- hour: "2-digit",
- minute: "2-digit",
- hour12: true,
- timeZoneName: "short",
- });
- };
-
- const isSameDay = from.toDateString() === to.toDateString();
-
- if (isSameDay) {
- const dateStr = from.toLocaleDateString("en-US", {
- month: "short",
- day: "numeric",
- year: "numeric",
- });
- const startTime = from.toLocaleTimeString("en-US", {
- hour: "2-digit",
- minute: "2-digit",
- hour12: true,
- });
- const endTime = to.toLocaleTimeString("en-US", {
- hour: "2-digit",
- minute: "2-digit",
- hour12: true,
- timeZoneName: "short",
- });
- return `${dateStr}: ${startTime} - ${endTime}`;
- } else {
- return `${formatDateTime(from)} - ${formatDateTime(to)}`;
- }
- }, []);
-
- return (
- <div className={className}>
- {label && <Text className="mb-2">{label}</Text>}
-
- {/* Container with relative positioning for absolute placement */}
- <div className="relative w-fit">
- <div ref={datePickerRef}>
- <DateRangePicker
- enableSelect={true}
- value={value}
- onValueChange={handleDateChange} // Only triggers on actual selection
- placeholder="Select date range"
- enableClear={false}
- style={{ zIndex: 100 }}
- />
- </div>
-
- {/* ONLY SHOW AFTER ACTUAL SELECTION IS COMPLETED */}
- {showSelectedFeedback && (
- <div
- className="absolute top-1/2 animate-pulse"
- style={{
- left: "calc(100% + 8px)",
- transform: "translateY(-50%)",
- zIndex: 110,
- }}
- >
- <div className="flex items-center gap-1 text-green-600 text-sm font-medium bg-white px-2 py-1 rounded-full border border-green-200 shadow-xs whitespace-nowrap">
- <div className="w-3 h-3 bg-green-500 text-white rounded-full flex items-center justify-center text-xs">
- ✓
- </div>
- <span className="text-xs">Selected</span>
- </div>
- </div>
- )}
- </div>
-
- {/* Time range display */}
- {showTimeRange && value.from && value.to && (
- <Text className="mt-2 text-xs text-gray-500">{formatTimeRange(value.from, value.to)}</Text>
- )}
- </div>
- );
-};
-
-export default UsageDatePicker;