1- import { type QueryClient , useQuery } from '@tanstack/react-query' ;
1+ import { useQuery } from '@tanstack/react-query' ;
22import { generateFilter } from '@redhat-cloud-services/frontend-components-utilities/helpers' ;
33import { getHostList , getHostTags } from '../../../api/hostInventoryApiTyped' ;
4- import pAll from 'p-all' ;
54
65type FetchSystemsReturnedValue = Awaited < ReturnType < typeof fetchSystems > > ;
76export type System = FetchSystemsReturnedValue [ 'results' ] [ number ] ;
@@ -10,7 +9,6 @@ interface FetchSystemsParams {
109 page : number ;
1110 perPage : number ;
1211}
13-
1412const fetchSystems = async ( { page, perPage } : FetchSystemsParams ) => {
1513 const state = { filters : { filter : { } } } ;
1614 const fields = {
@@ -54,39 +52,10 @@ const fetchSystems = async ({ page, perPage }: FetchSystemsParams) => {
5452 return { results, total } ;
5553} ;
5654
57- const MAX_CONCURRENT_FETCHES = 5 ;
58- interface FetchAllSystemsParams {
59- total ?: number ;
55+ interface UseSystemsQueryParams {
56+ page : number ;
6057 perPage : number ;
61- queryClient : QueryClient ;
6258}
63-
64- export const fetchAllSystems = async ( {
65- total,
66- perPage,
67- queryClient,
68- } : FetchAllSystemsParams ) => {
69- if ( ! total ) return [ ] ;
70-
71- const totalPages = Math . ceil ( total / perPage ) ;
72-
73- const allPages = ( await pAll (
74- Array . from (
75- { length : totalPages } ,
76- ( _ , i ) => ( ) =>
77- queryClient . fetchQuery ( {
78- queryKey : [ 'systems' , i + 1 , perPage ] ,
79- queryFn : ( ) => fetchSystems ( { page : i + 1 , perPage } ) ,
80- } ) ,
81- ) ,
82- { concurrency : MAX_CONCURRENT_FETCHES } ,
83- ) ) as FetchSystemsReturnedValue [ ] ;
84-
85- return allPages . flatMap ( ( page ) => page . results ) ;
86- } ;
87-
88- type UseSystemsQueryParams = FetchSystemsParams ;
89-
9059export const useSystemsQuery = ( { page, perPage } : UseSystemsQueryParams ) => {
9160 const { data, isLoading, isError, error } = useQuery ( {
9261 queryKey : [ 'systems' , page , perPage ] ,
0 commit comments