= ({ accessToken, userRole
return (
-
+
{isAdmin && (
<>
@@ -143,7 +152,7 @@ const GuardrailsPanel: React.FC = ({ accessToken, userRole
Guardrails
-
+
Test Playground
>
@@ -231,7 +240,7 @@ const GuardrailsPanel: React.FC = ({ accessToken, userRole
/>
-
+
, "userRole"> = {
+ isLoading: false,
+ isAuthorized: true,
token: "test-token",
accessToken: "test-token",
userId: "user-1",
userEmail: "user@example.com",
+ userRoleLabel: "",
+ isViewOnly: false,
premiumUser: false,
disabledPersonalKeyCreation: null,
showSSOBanner: false,
@@ -96,8 +101,8 @@ describe("TeamGuardrailsTab — approve/reject role gate", () => {
expect(screen.getByRole("button", { name: /reject/i })).toBeInTheDocument();
});
- it("hides Approve and Reject buttons when userRole is undefined (defaults to non-admin)", async () => {
- mockUseAuthorized.mockReturnValue({ ...baseAuth, userRole: undefined });
+ it("hides Approve and Reject buttons when the session has no role (defaults to non-admin)", async () => {
+ mockUseAuthorized.mockReturnValue({ ...baseAuth, userRole: "Undefined Role" });
renderWithProviders();
await screen.findByText("test-pending-guardrail");
@@ -140,3 +145,98 @@ describe("TeamGuardrailsTab — approve/reject role gate", () => {
expect(screen.getByLabelText("Remove x-request-id")).toBeInTheDocument();
});
});
+
+describe("TeamGuardrailsTab URL state", () => {
+ const mockUseAuthorized = vi.mocked(useAuthorized);
+ const lastUrlUpdate = (onUrlUpdate: ReturnType>) =>
+ onUrlUpdate.mock.calls.at(-1)?.[0];
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mockUseAuthorized.mockReturnValue({ ...baseAuth, userRole: "Admin" });
+ vi.mocked(listGuardrailSubmissions).mockResolvedValue({
+ submissions: [pendingSubmission],
+ summary: { total: 1, pending_review: 1, active: 0, rejected: 0 },
+ });
+ });
+
+ it("loads submissions with the search and status from ?sub_q= and ?sub_status=", async () => {
+ renderWithProviders(, {
+ searchParams: "?sub_q=pii&sub_status=pending",
+ });
+
+ expect(screen.getByPlaceholderText("Search guardrails...")).toHaveValue("pii");
+ expect(screen.getByLabelText("Filter by status")).toHaveValue("pending");
+ await waitFor(() =>
+ expect(listGuardrailSubmissions).toHaveBeenCalledWith("test-token", { status: "pending_review", search: "pii" }),
+ );
+ expect(listGuardrailSubmissions).toHaveBeenCalledTimes(1);
+ });
+
+ it("treats an unknown ?sub_status= as all statuses", async () => {
+ renderWithProviders(, { searchParams: "?sub_status=archived" });
+
+ expect(screen.getByLabelText("Filter by status")).toHaveValue("all");
+ await waitFor(() =>
+ expect(listGuardrailSubmissions).toHaveBeenCalledWith("test-token", { status: undefined, search: undefined }),
+ );
+ });
+
+ it("writes the search box to ?sub_q=", async () => {
+ const onUrlUpdate = vi.fn();
+ renderWithProviders(, { onUrlUpdate });
+ await screen.findByText("test-pending-guardrail");
+
+ fireEvent.change(screen.getByPlaceholderText("Search guardrails..."), { target: { value: "toxic" } });
+
+ await waitFor(() => expect(lastUrlUpdate(onUrlUpdate)?.searchParams.get("sub_q")).toBe("toxic"));
+ await waitFor(() =>
+ expect(listGuardrailSubmissions).toHaveBeenLastCalledWith("test-token", { status: undefined, search: "toxic" }),
+ );
+ });
+
+ it("writes the status filter to ?sub_status= and removes it for all statuses", async () => {
+ const onUrlUpdate = vi.fn();
+ renderWithProviders(, { onUrlUpdate });
+ await screen.findByText("test-pending-guardrail");
+ const statusSelect = screen.getByLabelText("Filter by status");
+
+ fireEvent.change(statusSelect, { target: { value: "rejected" } });
+ await waitFor(() => expect(lastUrlUpdate(onUrlUpdate)?.searchParams.get("sub_status")).toBe("rejected"));
+ await waitFor(() =>
+ expect(listGuardrailSubmissions).toHaveBeenLastCalledWith("test-token", {
+ status: "rejected",
+ search: undefined,
+ }),
+ );
+
+ fireEvent.change(statusSelect, { target: { value: "all" } });
+ await waitFor(() => expect(lastUrlUpdate(onUrlUpdate)?.searchParams.has("sub_status")).toBe(false));
+ });
+
+ it("opens the submission named by ?submission=", async () => {
+ renderWithProviders(, { searchParams: "?submission=guard-1" });
+
+ expect(await screen.findByText("Forward LiteLLM API Key")).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Close detail panel" })).toBeInTheDocument();
+ });
+
+ it("pushes ?submission= when a submission is opened and replaces it away when the panel is closed", async () => {
+ const onUrlUpdate = vi.fn();
+ renderWithProviders(, {
+ searchParams: "?sub_status=pending",
+ onUrlUpdate,
+ });
+
+ fireEvent.click(await screen.findByRole("button", { name: "Review" }));
+ await waitFor(() => expect(lastUrlUpdate(onUrlUpdate)?.searchParams.get("submission")).toBe("guard-1"));
+ expect(lastUrlUpdate(onUrlUpdate)?.options.history).toBe("push");
+ expect(await screen.findByText("Forward LiteLLM API Key")).toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole("button", { name: "Close detail panel" }));
+ await waitFor(() => expect(lastUrlUpdate(onUrlUpdate)?.searchParams.has("submission")).toBe(false));
+ expect(lastUrlUpdate(onUrlUpdate)?.searchParams.get("sub_status")).toBe("pending");
+ expect(lastUrlUpdate(onUrlUpdate)?.options.history).toBe("replace");
+ expect(screen.queryByText("Forward LiteLLM API Key")).not.toBeInTheDocument();
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/TeamGuardrailsTab.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/TeamGuardrailsTab.tsx
index d45cfc3fe7d..c67099ee35f 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/TeamGuardrailsTab.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/TeamGuardrailsTab.tsx
@@ -40,6 +40,7 @@ import { isValidUrl } from "@/lib/forms/urlValidation";
import { useZodForm } from "@/lib/forms/useZodForm";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
+import { useTeamGuardrailsUrlState } from "./useTeamGuardrailsUrlState";
const GUARDRAIL_MODES = [
{ value: "pre_call", label: "Pre Call" },
@@ -823,10 +824,9 @@ export function TeamGuardrailsTab({ accessToken }: TeamGuardrailsTabProps) {
active: 0,
rejected: 0,
});
- const [search, setSearch] = useState("");
+ const { search, setSearch, statusFilter, setStatusFilter, selectedId, openSubmission, closeSubmission } =
+ useTeamGuardrailsUrlState();
const [searchDebounced] = useDebouncedValue(search, { wait: DEBOUNCE_WAIT_MS });
- const [statusFilter, setStatusFilter] = useState<"all" | GuardrailStatus>("all");
- const [selectedId, setSelectedId] = useState(null);
const [expandedHeaders, setExpandedHeaders] = useState>(new Set());
const [confirmAction, setConfirmAction] = useState<{
id: string;
@@ -956,7 +956,7 @@ export function TeamGuardrailsTab({ accessToken }: TeamGuardrailsTabProps) {
try {
await approveGuardrailSubmission(accessToken, id);
setConfirmAction(null);
- if (selectedId === id) setSelectedId(null);
+ if (selectedId === id) closeSubmission();
await fetchSubmissions();
toast.success("Guardrail approved");
} catch {
@@ -969,7 +969,7 @@ export function TeamGuardrailsTab({ accessToken }: TeamGuardrailsTabProps) {
try {
await rejectGuardrailSubmission(accessToken, id);
setConfirmAction(null);
- if (selectedId === id) setSelectedId(null);
+ if (selectedId === id) closeSubmission();
await fetchSubmissions();
toast.success("Guardrail rejected");
} catch {
@@ -1009,7 +1009,7 @@ export function TeamGuardrailsTab({ accessToken }: TeamGuardrailsTabProps) {
@@ -61,7 +79,7 @@ const GuardrailGarden: React.FC = ({ accessToken, onGuardr
LiteLLM Content Filter
setShowAllLitellm(!showAllLitellm)}
+ onClick={() => void setShowAllLitellm(!showAllLitellm)}
>
{showAllLitellm ? (
<>Show less>
@@ -78,7 +96,7 @@ const GuardrailGarden: React.FC = ({ accessToken, onGuardr
{(showAllLitellm ? litellmCards : litellmCards.slice(0, CARDS_PER_ROW * VISIBLE_ROWS)).map((card) => (
- setSelectedCard(card)} />
+ openCard(card.id)} />
))}