Alerting: Remove unused file (#106320)

This commit is contained in:
Gilles De Mey
2025-06-04 17:34:20 +02:00
committed by GitHub
parent 4e3e774dad
commit 8dcb8ba4ec
@@ -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<TGroup extends PromRuleGroupDTO>(
groupsGenerator: AsyncIterator<TGroup>,
pageSize: number
) {
const [groups, setGroups] = useState<TGroup[]>([]);
const [hasMoreGroups, setHasMoreGroups] = useState<boolean>(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,
};
}