diff --git a/packages/manager-react-components/src/hooks/datagrid/useIcebergV2.tsx b/packages/manager-react-components/src/hooks/datagrid/useIcebergV2.tsx index 88c3944560e0..14c433cc43dc 100644 --- a/packages/manager-react-components/src/hooks/datagrid/useIcebergV2.tsx +++ b/packages/manager-react-components/src/hooks/datagrid/useIcebergV2.tsx @@ -1,11 +1,19 @@ import { useEffect, useState } from 'react'; -import { IcebergFetchParamsV2, fetchIcebergV2 } from '@ovh-ux/manager-core-api'; -import { useInfiniteQuery } from '@tanstack/react-query'; +import { + IcebergFetchParamsV2, + IcebergFetchResultV2, + fetchIcebergV2, +} from '@ovh-ux/manager-core-api'; +import { Query, useInfiniteQuery } from '@tanstack/react-query'; import { ColumnSort } from '../../components'; interface IcebergV2Hook { queryKey: string[]; defaultSorting?: ColumnSort; + refetchInterval?: + | number + | false + | ((query: Query) => number | false | undefined); } export const defaultPageSize = 10; @@ -20,6 +28,7 @@ export function useResourcesIcebergV2({ pageSize = defaultPageSize, queryKey, defaultSorting = undefined, + refetchInterval = false, }: IcebergFetchParamsV2 & IcebergV2Hook) { const [flattenData, setFlattenData] = useState([]); const [sorting, setSorting] = useState(defaultSorting); @@ -37,12 +46,16 @@ export function useResourcesIcebergV2({ queryFn: ({ pageParam }) => fetchIcebergV2({ route, pageSize, cursor: pageParam }), staleTime: Infinity, + refetchInterval, retry: false, - getNextPageParam: (lastPage) => lastPage.cursorNext, + getNextPageParam: (lastPage: IcebergFetchResultV2) => + lastPage.cursorNext, }); useEffect(() => { - const flatten = data?.pages.map((page) => page.data).flat(); + const flatten = data?.pages + .map((page: IcebergFetchResultV2) => page.data) + .flat(); setFlattenData(flatten); }, [data]);