import { useQuery } from 'react-query' ; import { useKibana } from '../common/lib/kibana' ; import { useErrorToast } from '../common/hooks/use_error_toast' ; import { SAVED_QUERIES_ID } from './constants' ; export const useSavedQueries = ( { isLive = false , pageIndex = 0 , pageSize = 10000 , sortField = 'updated_at' , sortDirection = 'desc' , } ) => { const { http } = useKibana ( ) . services ; const setErrorToast = useErrorToast ( ) ; return useQuery ( [ SAVED_QUERIES_ID , { pageIndex , pageSize , sortField , sortDirection } ] , ( ) => http . get < any > ( '/internal/osquery/saved_query' , { query : { pageIndex , pageSize , sortField , sortDirection } , } ) , { keepPreviousData : true , refetchInterval : isLive ? 10000 : false , onError : ( error ) => { setErrorToast ( error , { title : error . body . error , toastMessage : error . body . message , } ) ; } , refetchOnWindowFocus : ! ! isLive , } ) ; } ;