From 2f7d118c5433efd9f29eb75f3bbdcbc66dc05621 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 13 Mar 2025 19:21:59 -0700 Subject: [PATCH] working modal --- .../src/components/key_page_wrapper.tsx | 50 ++++++++++++++ .../src/components/top_key_view.tsx | 65 ++++++++++--------- 2 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 ui/litellm-dashboard/src/components/key_page_wrapper.tsx diff --git a/ui/litellm-dashboard/src/components/key_page_wrapper.tsx b/ui/litellm-dashboard/src/components/key_page_wrapper.tsx new file mode 100644 index 00000000000..5870e00fe73 --- /dev/null +++ b/ui/litellm-dashboard/src/components/key_page_wrapper.tsx @@ -0,0 +1,50 @@ +import React, { useState } from "react"; +import TopKeyView from "./top_key_view"; +import KeyInfoView from "./key_info_view"; +import { KeyResponse } from "./key_team_helpers/key_list"; + +interface KeyPageWrapperProps { + topKeys: any[]; + accessToken: string | null; + userID: string | null; + userRole: string | null; + teams: any[] | null; +} + +const KeyPageWrapper: React.FC = ({ + topKeys, + accessToken, + userID, + userRole, + teams, +}) => { + const [selectedKeyData, setSelectedKeyData] = useState(null); + + if (selectedKeyData) { + return ( +
+ setSelectedKeyData(null)} + accessToken={accessToken} + userID={userID} + userRole={userRole} + teams={teams} + /> +
+ ); + } + + return ( + + ); +}; + +export default KeyPageWrapper; \ No newline at end of file diff --git a/ui/litellm-dashboard/src/components/top_key_view.tsx b/ui/litellm-dashboard/src/components/top_key_view.tsx index b031ef1fa3e..ab943a6cb10 100644 --- a/ui/litellm-dashboard/src/components/top_key_view.tsx +++ b/ui/litellm-dashboard/src/components/top_key_view.tsx @@ -19,58 +19,63 @@ const TopKeyView: React.FC = ({ userRole, teams }) => { + const [isModalOpen, setIsModalOpen] = useState(false); const [selectedKey, setSelectedKey] = useState(null); const [keyData, setKeyData] = useState(undefined); const handleKeyClick = async (item: any) => { if (!accessToken) return; - console.log("Clicked item:", item); try { - // Use item.key instead of item.api_key const keyInfo = await keyInfoV1Call(accessToken, item.api_key); const transformedKeyData = transformKeyInfo(keyInfo); setKeyData(transformedKeyData); setSelectedKey(item.key); + setIsModalOpen(true); // Open modal when key is clicked } catch (error) { console.error("Error fetching key info:", error); } }; const handleClose = () => { + setIsModalOpen(false); setSelectedKey(null); setKeyData(undefined); }; - if (selectedKey && keyData) { - return ( - - ); - } - return ( - `$${value.toFixed(2)}`} - onValueChange={(item) => handleKeyClick(item)} - /> + <> + `$${value.toFixed(2)}`} + onValueChange={(item) => handleKeyClick(item)} + /> + + {isModalOpen && selectedKey && keyData && ( +
+
+ +
+
+ )} + ); };