11import React , { useState , useEffect } from "react" ;
22import { Button , TabGroup , TabList , Tab , TabPanels , TabPanel } from "@tremor/react" ;
3- import { Modal } from "antd" ;
43import { getGuardrailsList , deleteGuardrailCall } from "./networking" ;
54import AddGuardrailForm from "./guardrails/add_guardrail_form" ;
65import GuardrailTable from "./guardrails/guardrail_table" ;
@@ -9,6 +8,8 @@ import GuardrailInfoView from "./guardrails/guardrail_info";
98import GuardrailTestPlayground from "./guardrails/GuardrailTestPlayground" ;
109import NotificationsManager from "./molecules/notifications_manager" ;
1110import { Guardrail , GuardrailDefinitionLocation } from "./guardrails/types" ;
11+ import DeleteResourceModal from "./common_components/DeleteResourceModal" ;
12+ import { getGuardrailLogoAndName } from "./guardrails/guardrail_info_helpers" ;
1213
1314interface GuardrailsPanelProps {
1415 accessToken : string | null ;
@@ -38,7 +39,8 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken, userRole
3839 const [ isAddModalVisible , setIsAddModalVisible ] = useState ( false ) ;
3940 const [ isLoading , setIsLoading ] = useState ( false ) ;
4041 const [ isDeleting , setIsDeleting ] = useState ( false ) ;
41- const [ guardrailToDelete , setGuardrailToDelete ] = useState < { id : string ; name : string } | null > ( null ) ;
42+ const [ guardrailToDelete , setGuardrailToDelete ] = useState < Guardrail | null > ( null ) ;
43+ const [ isDeleteModalOpen , setIsDeleteModalOpen ] = useState ( false ) ;
4244 const [ selectedGuardrailId , setSelectedGuardrailId ] = useState < string | null > ( null ) ;
4345 const [ activeTab , setActiveTab ] = useState < number > ( 0 ) ;
4446
@@ -81,7 +83,9 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken, userRole
8183 } ;
8284
8385 const handleDeleteClick = ( guardrailId : string , guardrailName : string ) => {
84- setGuardrailToDelete ( { id : guardrailId , name : guardrailName } ) ;
86+ const guardrail = guardrailsList . find ( ( g ) => g . guardrail_id === guardrailId ) || null ;
87+ setGuardrailToDelete ( guardrail ) ;
88+ setIsDeleteModalOpen ( true ) ;
8589 } ;
8690
8791 const handleDeleteConfirm = async ( ) => {
@@ -90,22 +94,29 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken, userRole
9094 // Log removed to maintain clean production code
9195 setIsDeleting ( true ) ;
9296 try {
93- await deleteGuardrailCall ( accessToken , guardrailToDelete . id ) ;
94- NotificationsManager . success ( `Guardrail "${ guardrailToDelete . name } " deleted successfully` ) ;
95- fetchGuardrails ( ) ; // Refresh the list
97+ await deleteGuardrailCall ( accessToken , guardrailToDelete . guardrail_id ) ;
98+ NotificationsManager . success ( `Guardrail "${ guardrailToDelete . guardrail_name } " deleted successfully` ) ;
99+ await fetchGuardrails ( ) ; // Refresh the list
96100 } catch ( error ) {
97101 console . error ( "Error deleting guardrail:" , error ) ;
98102 NotificationsManager . fromBackend ( "Failed to delete guardrail" ) ;
99103 } finally {
100104 setIsDeleting ( false ) ;
105+ setIsDeleteModalOpen ( false ) ;
101106 setGuardrailToDelete ( null ) ;
102107 }
103108 } ;
104109
105110 const handleDeleteCancel = ( ) => {
111+ setIsDeleteModalOpen ( false ) ;
106112 setGuardrailToDelete ( null ) ;
107113 } ;
108114
115+ const providerDisplayName =
116+ guardrailToDelete && guardrailToDelete . litellm_params
117+ ? getGuardrailLogoAndName ( guardrailToDelete . litellm_params . guardrail ) . displayName
118+ : undefined ;
119+
109120 return (
110121 < div className = "w-full mx-auto flex-auto overflow-y-auto m-8 p-2" >
111122 < TabGroup index = { activeTab } onIndexChange = { setActiveTab } >
@@ -148,20 +159,25 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken, userRole
148159 onSuccess = { handleSuccess }
149160 />
150161
151- { guardrailToDelete && (
152- < Modal
153- title = "Delete Guardrail"
154- open = { guardrailToDelete !== null }
155- onOk = { handleDeleteConfirm }
156- onCancel = { handleDeleteCancel }
157- confirmLoading = { isDeleting }
158- okText = "Delete"
159- okButtonProps = { { danger : true } }
160- >
161- < p > Are you sure you want to delete guardrail: { guardrailToDelete . name } ?</ p >
162- < p > This action cannot be undone.</ p >
163- </ Modal >
164- ) }
162+ < DeleteResourceModal
163+ isOpen = { isDeleteModalOpen }
164+ title = "Delete Guardrail"
165+ message = { `Are you sure you want to delete guardrail: ${ guardrailToDelete ?. guardrail_name } ? This action cannot be undone.` }
166+ resourceInformationTitle = "Guardrail Information"
167+ resourceInformation = { [
168+ { label : "Name" , value : guardrailToDelete ?. guardrail_name } ,
169+ { label : "ID" , value : guardrailToDelete ?. guardrail_id , code : true } ,
170+ { label : "Provider" , value : providerDisplayName } ,
171+ { label : "Mode" , value : guardrailToDelete ?. litellm_params . mode } ,
172+ {
173+ label : "Default On" ,
174+ value : guardrailToDelete ?. litellm_params . default_on ? "Yes" : "No" ,
175+ } ,
176+ ] }
177+ onCancel = { handleDeleteCancel }
178+ onOk = { handleDeleteConfirm }
179+ confirmLoading = { isDeleting }
180+ />
165181 </ TabPanel >
166182
167183 < TabPanel >
0 commit comments