From 5fbc3319702080fa987bee7b0a89e1cb635dd6be Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 25 Apr 2025 12:21:05 -0700 Subject: [PATCH] fix(all_keys_table.tsx): fix filtering + search logic --- .../src/components/all_keys_table.tsx | 26 --------- .../key_team_helpers/filter_logic.tsx | 54 +------------------ 2 files changed, 1 insertion(+), 79 deletions(-) diff --git a/ui/litellm-dashboard/src/components/all_keys_table.tsx b/ui/litellm-dashboard/src/components/all_keys_table.tsx index 80892d9cbe5..f83f6f510c2 100644 --- a/ui/litellm-dashboard/src/components/all_keys_table.tsx +++ b/ui/litellm-dashboard/src/components/all_keys_table.tsx @@ -116,32 +116,6 @@ export function AllKeysTable({ }: AllKeysTableProps) { const [selectedKeyId, setSelectedKeyId] = useState(null); const [userList, setUserList] = useState([]); - const lastSearchTimestamp = useRef(0); - - // Use the filter logic hook - useEffect(() => { - const loadAllFilterData = async () => { - - // Load all teams - no organization filter needed here - const teamsData = await fetchAllTeams(accessToken); - if (teamsData.length > 0) { - setAllTeams(teamsData); - } - - // Load all organizations - const orgsData = await fetchAllOrganizations(accessToken); - if (orgsData.length > 0) { - setAllOrganizations(orgsData); - } - - // Load all keys - debouncedSearch(filters); - }; - - if (accessToken) { - loadAllFilterData(); - } - }, [accessToken]); const { filters, diff --git a/ui/litellm-dashboard/src/components/key_team_helpers/filter_logic.tsx b/ui/litellm-dashboard/src/components/key_team_helpers/filter_logic.tsx index 8bbcad3a153..99bf9c4d65c 100644 --- a/ui/litellm-dashboard/src/components/key_team_helpers/filter_logic.tsx +++ b/ui/litellm-dashboard/src/components/key_team_helpers/filter_logic.tsx @@ -78,28 +78,6 @@ export function useFilterLogic({ }, 300), [accessToken] ); - // Apply filters to keys whenever keys or filters change - useEffect(() => { - if (!keys) { - setFilteredKeys([]); - return; - } - - let result = [...keys]; - - // Apply Team ID filter - if (filters['Team ID']) { - result = result.filter(key => key.team_id === filters['Team ID']); - } - - // Apply Organization ID filter - if (filters['Organization ID']) { - result = result.filter(key => key.organization_id === filters['Organization ID']); - } - - - setFilteredKeys(result); - }, [keys, filters]); // Fetch all data for filters when component mounts useEffect(() => { @@ -154,34 +132,6 @@ export function useFilterLogic({ }, [organizations]); const handleFilterChange = (newFilters: Record) => { - // Update filters state - setFilters({ - 'Team ID': newFilters['Team ID'] || '', - 'Organization ID': newFilters['Organization ID'] || '', - 'Key Alias': newFilters['Key Alias'] || '' - }); - - // Handle Team change - if (newFilters['Team ID']) { - const selectedTeamData = allTeams?.find(team => team.team_id === newFilters['Team ID']); - if (selectedTeamData) { - setSelectedTeam(selectedTeamData); - } - } - - // Handle Org change - if (newFilters['Organization ID']) { - const selectedOrg = allOrganizations?.find(org => org.organization_id === newFilters['Organization ID']); - if (selectedOrg) { - setCurrentOrg(selectedOrg); - } - } - - const keyAlias = newFilters['Key Alias']; - const selectedKeyAlias = keyAlias - ? allKeyAliases.find((k) => k === keyAlias) || null - : null; - setSelectedKeyAlias(selectedKeyAlias) // Fetch keys based on new filters const updatedFilters = { @@ -200,9 +150,7 @@ export function useFilterLogic({ }); // Reset selections - setSelectedTeam(null); - setCurrentOrg(null); - setSelectedKeyAlias(null); + debouncedSearch(filters); }; return {