From 7844b22f95bdaabc0be5fbb186f30bd0d83fa15d Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Mon, 28 Sep 2026 10:51:20 +0200 Subject: [PATCH] Refactor useOAuthGrantsQuery to use infinite list --- .../data/oauth-apps/oauth-apps-grants-query.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts b/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts index f5f300fc160..bea46826f85 100644 --- a/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts +++ b/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts @@ -1,9 +1,9 @@ -import { useQuery } from '@tanstack/react-query' +import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query' import { oauthAppsKeys } from './keys' import { getMockOAuthOwnGrants, USE_MOCKS } from './mocks' import type { ListOwnGrantsResponse } from './types' -import type { ResponseError, UseCustomQueryOptions } from '@/types' +import type { ResponseError, UseCustomInfiniteQueryOptions } from '@/types' export type OAuthGrantsVariables = { cursor?: string @@ -27,11 +27,19 @@ export const useOAuthGrantsQuery = ( { enabled = true, ...options - }: UseCustomQueryOptions = {} + }: UseCustomInfiniteQueryOptions< + OAuthGrantsData, + OAuthGrantsError, + InfiniteData, + readonly unknown[], + string | undefined + > = {} ) => - useQuery({ + useInfiniteQuery({ queryKey: oauthAppsKeys.grants(cursor), - queryFn: () => getOAuthGrants({ cursor }), + queryFn: ({ pageParam }) => getOAuthGrants({ cursor: pageParam }), + initialPageParam: cursor, + getNextPageParam: (lastPage) => lastPage.pagination.next_cursor, enabled: enabled && USE_MOCKS, ...options, })