import { useQuery } from 'react-query' ; import { i18n } from '@kbn/i18n' ; import { useKibana } from '../common/lib/kibana' ; import { useErrorToast } from '../common/hooks/use_error_toast' ; interface UseAgentPolicy { policyId ? : string ; silent ? : boolean ; skip ? : boolean ; } export const useAgentPolicy = ( { policyId , skip , silent } ) => { const { http } = useKibana ( ) . services ; const setErrorToast = useErrorToast ( ) ; return useQuery < any , Error > ( [ 'agentPolicy' , { policyId } ] , ( ) => http . get ( `/internal/osquery/fleet_wrapper/agent_policies/${ policyId }` ) , { enabled : ! ! ( policyId && ! skip ) , keepPreviousData : true , select : ( response ) => response . item , onSuccess : ( ) => setErrorToast ( ) , onError : ( error ) => ! silent && setErrorToast ( error , { title : i18n . translate ( 'xpack.osquery.agent_policy_details.fetchError' , { defaultMessage : 'Error while fetching agent policy details' , } ) , } ) , refetchOnReconnect : false , refetchOnWindowFocus : false , } ) ; } ;