diff --git a/public/app/features/alerting/unified/rule-list/hooks/usePaginatedPrometheusGroups.tsx b/public/app/features/alerting/unified/rule-list/hooks/usePaginatedPrometheusGroups.tsx deleted file mode 100644 index 8110a871d3a..00000000000 --- a/public/app/features/alerting/unified/rule-list/hooks/usePaginatedPrometheusGroups.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import { useState } from 'react'; -import { useEffectOnce } from 'react-use'; - -import { PromRuleGroupDTO } from 'app/types/unified-alerting-dto'; - -import { isLoading as isLoadingState, isUninitialized as isUninitializedState, useAsync } from '../../hooks/useAsync'; - -/** - * Provides pagination functionality for rule groups with lazy loading. - * Instead of loading all groups at once, it uses a generator to fetch them in batches as needed, - * which helps with performance when dealing with large numbers of rules. - * - * @param groupsGenerator - An async generator that yields rule groups in batches - * @param pageSize - Number of groups to display per page - * @returns Groups loaded so far and controls for navigating through rule groups - */ -export function useLazyLoadPrometheusGroups( - groupsGenerator: AsyncIterator, - pageSize: number -) { - const [groups, setGroups] = useState([]); - const [hasMoreGroups, setHasMoreGroups] = useState(true); - - const [{ execute: fetchMoreGroups }, groupsRequestState] = useAsync(async () => { - let done = false; - const currentGroups: TGroup[] = []; - - while (currentGroups.length < pageSize) { - const generatorResult = await groupsGenerator.next(); - if (generatorResult.done) { - done = true; - break; - } - const group = generatorResult.value; - currentGroups.push(group); - } - - if (done) { - setHasMoreGroups(false); - } - - setGroups((groups) => groups.concat(currentGroups)); - }); - - // make sure we only load the initial group exactly once - useEffectOnce(() => { - fetchMoreGroups(); - }); - - const isLoading = isLoadingState(groupsRequestState); - const isUninitialized = isUninitializedState(groupsRequestState); - - return { - isLoading, - groups, - hasMoreGroups: !isUninitialized && hasMoreGroups, - fetchMoreGroups, - }; -}