mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
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).
This commit is contained in:
parent
8a3dabb09f
commit
cb099ee75c
1 changed files with 38 additions and 1 deletions
|
|
@ -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<TeamsResponse>({
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue