mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-19 00:01:29 +00:00
Merge pull request #41657 from BerriAI/litellm_remove_dead_use_key_list_hook
refactor(ui): remove dead useKeyList hook from key_list.tsx
This commit is contained in:
commit
444d345d69
2 changed files with 1 additions and 117 deletions
|
|
@ -1685,9 +1685,6 @@
|
|||
"src/components/key_team_helpers/key_list.tsx": {
|
||||
"local/filename-pascal-case": {
|
||||
"count": 1
|
||||
},
|
||||
"react-hooks/set-state-in-effect": {
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"src/components/key_team_helpers/transform_key_info.tsx": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import { Setter } from "@/types";
|
||||
import { useEffect, useState } from "react";
|
||||
import { keyListCall, Member, Organization } from "../networking";
|
||||
import { Member } from "../networking";
|
||||
import type { ObjectPermission } from "../object_permission_types";
|
||||
import type { ModelBudgetUsage, ModelMaxBudget } from "./ModelMaxBudgetEditor";
|
||||
|
||||
|
|
@ -126,114 +124,3 @@ export interface KeyResponse {
|
|||
user_alias: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
interface KeyListResponse {
|
||||
keys: KeyResponse[];
|
||||
total_count: number;
|
||||
current_page: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
interface UseKeyListProps {
|
||||
selectedTeam?: Team;
|
||||
currentOrg: Organization | null;
|
||||
selectedKeyAlias: string | null;
|
||||
accessToken: string;
|
||||
createClicked: boolean;
|
||||
expand?: string[];
|
||||
}
|
||||
|
||||
interface PaginationData {
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
totalCount: number;
|
||||
}
|
||||
|
||||
interface UseKeyListReturn {
|
||||
keys: KeyResponse[];
|
||||
isLoading: boolean;
|
||||
error: Error | null;
|
||||
pagination: PaginationData;
|
||||
refresh: (params?: Record<string, unknown>) => Promise<void>;
|
||||
setKeys: Setter<KeyResponse[]>;
|
||||
}
|
||||
|
||||
const useKeyList = ({
|
||||
selectedTeam,
|
||||
currentOrg,
|
||||
selectedKeyAlias,
|
||||
accessToken,
|
||||
createClicked,
|
||||
expand = [],
|
||||
}: UseKeyListProps): UseKeyListReturn => {
|
||||
const [keyData, setKeyData] = useState<KeyListResponse>({
|
||||
keys: [],
|
||||
total_count: 0,
|
||||
current_page: 1,
|
||||
total_pages: 0,
|
||||
});
|
||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
const fetchKeys = async (params: Record<string, unknown> = {}): Promise<void> => {
|
||||
try {
|
||||
if (!accessToken) {
|
||||
return;
|
||||
}
|
||||
setIsLoading(true);
|
||||
|
||||
const page = typeof params.page === "number" ? params.page : 1;
|
||||
const pageSize = typeof params.pageSize === "number" ? params.pageSize : 100;
|
||||
|
||||
const data = await keyListCall(
|
||||
accessToken,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
page,
|
||||
pageSize,
|
||||
null,
|
||||
null,
|
||||
expand.join(","),
|
||||
);
|
||||
setKeyData(data);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err : new Error("An error occurred"));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchKeys();
|
||||
}, [selectedTeam, currentOrg, accessToken, selectedKeyAlias, createClicked]);
|
||||
|
||||
const setKeys = (newKeysOrUpdater: KeyResponse[] | ((prevKeys: KeyResponse[]) => KeyResponse[])) => {
|
||||
setKeyData((prevData) => {
|
||||
const newKeys = typeof newKeysOrUpdater === "function" ? newKeysOrUpdater(prevData.keys) : newKeysOrUpdater;
|
||||
|
||||
return {
|
||||
...prevData,
|
||||
keys: newKeys,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
keys: keyData.keys,
|
||||
isLoading,
|
||||
error,
|
||||
pagination: {
|
||||
currentPage: keyData.current_page,
|
||||
totalPages: keyData.total_pages,
|
||||
totalCount: keyData.total_count,
|
||||
},
|
||||
refresh: fetchKeys,
|
||||
setKeys,
|
||||
};
|
||||
};
|
||||
|
||||
export default useKeyList;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue