import { HttpFetchQuery } from 'kibana/public' ; import { API_BASE_PATH } from '../../../../common' ; import { UIM_SNAPSHOT_DELETE , UIM_SNAPSHOT_DELETE_MANY } from '../../constants' ; import { SnapshotListParams } from '../../lib' ; import { UiMetricService } from '../ui_metric' ; import { sendRequest , useRequest } from './use_request' ; let uiMetricService ; export const setUiMetricServiceSnapshot = ( _uiMetricService ) => { uiMetricService = _uiMetricService ; } ; export const useLoadSnapshots = ( query ) => useRequest ( { path : `${ API_BASE_PATH }snapshots` , method : 'get' , initialData : [ ] , query : query as unknown as HttpFetchQuery , } ) ; export const useLoadSnapshot = ( repositoryName , snapshotId ) => useRequest ( { path : `${ API_BASE_PATH }snapshots/${ encodeURIComponent ( repositoryName ) }/${ encodeURIComponent ( snapshotId ) }` , method : 'get' , } ) ; export const deleteSnapshots = async ( snapshotIds ) => { const result = await sendRequest ( { path : `${ API_BASE_PATH }snapshots/bulk_delete` , method : 'post' , body : snapshotIds , } ) ; uiMetricService . trackUiMetric ( snapshotIds . length > 1 ? UIM_SNAPSHOT_DELETE_MANY : UIM_SNAPSHOT_DELETE ) ; return result ; } ;