mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
## Problem The Query Performance page loaded all results in a single query with a fixed limit of 20 rows, giving users no way to browse beyond the first page. There was also no way to control how many rows were shown at once. ## Fix adds pagination ## How to test - Navigate to `/observability/query-performance` in Studio - scroll to bottom - should automatically load more results --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { isAtBottom } from 'lib/helpers'
|
|
import { UIEvent, useCallback, useRef } from 'react'
|
|
|
|
interface UseInfiniteScrollOptions {
|
|
isLoading?: boolean
|
|
isFetchingNextPage?: boolean
|
|
hasNextPage?: boolean
|
|
fetchNextPage: (options?: { cancelRefetch?: boolean }) => void
|
|
}
|
|
|
|
/**
|
|
* Returns a scroll handler that triggers fetchNextPage when the user scrolls
|
|
* to the bottom of a scrollable container. Includes horizontal scroll detection
|
|
* to avoid triggering loads when the user scrolls horizontally.
|
|
*/
|
|
export function useInfiniteScroll({
|
|
isLoading = false,
|
|
isFetchingNextPage = false,
|
|
hasNextPage = false,
|
|
fetchNextPage,
|
|
}: UseInfiniteScrollOptions) {
|
|
const xScroll = useRef(0)
|
|
|
|
return useCallback(
|
|
(event: UIEvent<HTMLDivElement>) => {
|
|
const isScrollingHorizontally = xScroll.current !== event.currentTarget.scrollLeft
|
|
xScroll.current = event.currentTarget.scrollLeft
|
|
|
|
const shouldFetchNextPage =
|
|
!isLoading &&
|
|
!isFetchingNextPage &&
|
|
!isScrollingHorizontally &&
|
|
isAtBottom(event) &&
|
|
hasNextPage
|
|
|
|
if (!shouldFetchNextPage) {
|
|
return
|
|
}
|
|
|
|
fetchNextPage({ cancelRefetch: false })
|
|
},
|
|
[isLoading, isFetchingNextPage, hasNextPage, fetchNextPage]
|
|
)
|
|
}
|