diff --git a/ui/litellm-dashboard/src/components/guardrails.tsx b/ui/litellm-dashboard/src/components/guardrails.tsx index fee9d02d3ae..8e4f2567696 100644 --- a/ui/litellm-dashboard/src/components/guardrails.tsx +++ b/ui/litellm-dashboard/src/components/guardrails.tsx @@ -1,6 +1,13 @@ -import React, { useState, useEffect } from "react"; -import { Button, Dropdown, Tabs } from "antd"; -import { DownOutlined, PlusOutlined, CodeOutlined } from "@ant-design/icons"; +import React, { useCallback, useState, useEffect } from "react"; +import { Tabs } from "antd"; +import { Button } from "@/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { ChevronDown, Code, Plus } from "lucide-react"; import { getGuardrailsList, deleteGuardrailCall } from "./networking"; import AddGuardrailForm from "./guardrails/add_guardrail_form"; import GuardrailTable from "./guardrails/guardrail_table"; @@ -49,7 +56,7 @@ const GuardrailsPanel: React.FC = ({ accessToken, userRole const [selectedGuardrailId, setSelectedGuardrailId] = useState(null); const isAdmin = userRole ? isAdminRole(userRole) : false; - const fetchGuardrails = async () => { + const fetchGuardrails = useCallback(async () => { if (!accessToken) { return; } @@ -57,18 +64,17 @@ const GuardrailsPanel: React.FC = ({ accessToken, userRole setIsLoading(true); try { const response: GuardrailsResponse = await getGuardrailsList(accessToken); - console.log(`guardrails: ${JSON.stringify(response)}`); setGuardrailsList(response.guardrails); } catch (error) { console.error("Error fetching guardrails:", error); } finally { setIsLoading(false); } - }; + }, [accessToken]); useEffect(() => { fetchGuardrails(); - }, [accessToken]); + }, [fetchGuardrails]); const handleAddGuardrail = () => { if (selectedGuardrailId) { @@ -96,8 +102,9 @@ const GuardrailsPanel: React.FC = ({ accessToken, userRole fetchGuardrails(); }; - const handleDeleteClick = (guardrailId: string, guardrailName: string) => { - const guardrail = guardrailsList.find((g) => g.guardrail_id === guardrailId) || null; + const handleDeleteClick = (guardrailId: string, _guardrailName: string) => { + const guardrail = + guardrailsList.find((g) => g.guardrail_id === guardrailId) || null; setGuardrailToDelete(guardrail); setIsDeleteModalOpen(true); }; @@ -153,30 +160,28 @@ const GuardrailsPanel: React.FC = ({ accessToken, userRole children: ( <>
- , - label: "Add Provider Guardrail", - onClick: handleAddGuardrail, - }, - { - key: "custom_code", - icon: , - label: "Create Custom Code Guardrail", - onClick: handleAddCustomCodeGuardrail, - }, - ], - }} - trigger={["click"]} - disabled={!accessToken} - > - - + + + + + + + + Add Provider Guardrail + + + + Create Custom Code Guardrail + + +
{selectedGuardrailId ? (