mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
ui - instantly show changes to create key table
This commit is contained in:
parent
3875df666b
commit
04662c653f
3 changed files with 36 additions and 0 deletions
|
@ -32,6 +32,7 @@ interface AllKeysTableProps {
|
||||||
userRole: string | null;
|
userRole: string | null;
|
||||||
organizations: Organization[] | null;
|
organizations: Organization[] | null;
|
||||||
setCurrentOrg: React.Dispatch<React.SetStateAction<Organization | null>>;
|
setCurrentOrg: React.Dispatch<React.SetStateAction<Organization | null>>;
|
||||||
|
refresh?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define columns similar to our logs table
|
// Define columns similar to our logs table
|
||||||
|
@ -98,6 +99,7 @@ export function AllKeysTable({
|
||||||
userRole,
|
userRole,
|
||||||
organizations,
|
organizations,
|
||||||
setCurrentOrg,
|
setCurrentOrg,
|
||||||
|
refresh,
|
||||||
}: AllKeysTableProps) {
|
}: AllKeysTableProps) {
|
||||||
const [selectedKeyId, setSelectedKeyId] = useState<string | null>(null);
|
const [selectedKeyId, setSelectedKeyId] = useState<string | null>(null);
|
||||||
const [userList, setUserList] = useState<UserResponse[]>([]);
|
const [userList, setUserList] = useState<UserResponse[]>([]);
|
||||||
|
@ -131,6 +133,22 @@ export function AllKeysTable({
|
||||||
}
|
}
|
||||||
}, [accessToken, keys]);
|
}, [accessToken, keys]);
|
||||||
|
|
||||||
|
// Add a useEffect to call refresh when a key is created
|
||||||
|
useEffect(() => {
|
||||||
|
if (refresh) {
|
||||||
|
const handleStorageChange = () => {
|
||||||
|
refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Listen for storage events that might indicate a key was created
|
||||||
|
window.addEventListener('storage', handleStorageChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('storage', handleStorageChange);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [refresh]);
|
||||||
|
|
||||||
const columns: ColumnDef<KeyResponse>[] = [
|
const columns: ColumnDef<KeyResponse>[] = [
|
||||||
{
|
{
|
||||||
id: "expander",
|
id: "expander",
|
||||||
|
|
|
@ -266,6 +266,11 @@ const CreateKey: React.FC<CreateKeyProps> = ({
|
||||||
message.success("API Key Created");
|
message.success("API Key Created");
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
localStorage.removeItem("userData" + userID);
|
localStorage.removeItem("userData" + userID);
|
||||||
|
|
||||||
|
// Add this line to refresh the keys list immediately
|
||||||
|
if (window.refreshKeysList) {
|
||||||
|
window.refreshKeysList();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error in create key:", error);
|
console.log("error in create key:", error);
|
||||||
message.error(`Error creating the key: ${error}`);
|
message.error(`Error creating the key: ${error}`);
|
||||||
|
|
|
@ -182,6 +182,11 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
|
||||||
accessToken,
|
accessToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Make refresh function available globally so CreateKey can access it
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.refreshKeysList = refresh;
|
||||||
|
}
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => {
|
const handlePageChange = (newPage: number) => {
|
||||||
refresh({ page: newPage });
|
refresh({ page: newPage });
|
||||||
};
|
};
|
||||||
|
@ -421,6 +426,7 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
|
||||||
userRole={userRole}
|
userRole={userRole}
|
||||||
organizations={organizations}
|
organizations={organizations}
|
||||||
setCurrentOrg={setCurrentOrg}
|
setCurrentOrg={setCurrentOrg}
|
||||||
|
refresh={refresh}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{isDeleteModalOpen && (
|
{isDeleteModalOpen && (
|
||||||
|
@ -619,4 +625,11 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add this type declaration at the top of the file to avoid TypeScript errors
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
refreshKeysList?: () => void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default ViewKeyTable;
|
export default ViewKeyTable;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue