From cb099ee75cfe3b2dc301457031477e8371288198 Mon Sep 17 00:00:00 2001 From: Ryan Crabbe Date: Sat, 4 Apr 2026 17:44:40 -0700 Subject: [PATCH] fix(ui): add useInfiniteTeams hook needed by team_multi_select Cherry-pick of team_multi_select.tsx imported useInfiniteTeams which didn't yet exist on this stable patch branch. Ported the hook from main (aea8e32048). --- .../app/(dashboard)/hooks/teams/useTeams.ts | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/teams/useTeams.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/teams/useTeams.ts index a86b5cd51f6..f74a71e901e 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/teams/useTeams.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/teams/useTeams.ts @@ -1,4 +1,4 @@ -import { keepPreviousData, useQuery, useQueryClient, UseQueryResult } from "@tanstack/react-query"; +import { keepPreviousData, useInfiniteQuery, useQuery, useQueryClient, UseQueryResult } from "@tanstack/react-query"; import { Team } from "@/components/key_team_helpers/key_list"; import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized"; import { fetchTeams } from "@/app/(dashboard)/networking"; @@ -124,6 +124,43 @@ export const useTeam = (teamId?: string) => { }); }; +const infiniteTeamKeys = createQueryKeys("infiniteTeams"); + +export const useInfiniteTeams = ( + pageSize: number = 50, + search?: string, + organizationId?: string | null, +) => { + const { accessToken, userId, userRole } = useAuthorized(); + const isAdmin = userRole === "Admin" || userRole === "Admin Viewer"; + + return useInfiniteQuery({ + queryKey: infiniteTeamKeys.list({ + filters: { + pageSize, + ...(search && { search }), + ...(organizationId && { organizationId }), + ...(userId && { userId }), + }, + }), + queryFn: async ({ pageParam }) => { + return await teamListCall(accessToken!, pageParam as number, pageSize, { + team_alias: search || undefined, + organizationID: organizationId, + userID: !isAdmin ? userId : undefined, + }); + }, + initialPageParam: 1, + getNextPageParam: (lastPage) => { + if (lastPage.page < lastPage.total_pages) { + return lastPage.page + 1; + } + return undefined; + }, + enabled: Boolean(accessToken), + }); +}; + const deletedTeamListCall = async ( accessToken: string, page: number,