import moment from 'moment' ; import { AUTO_INTERVAL } from '../../../common/constants' ; import { validateField } from '../../../common/fields_utils' ; import { validateInterval } from '../../../common/validate_interval' ; import type { FetchedIndexPattern , Panel , Series } from '../../../common/types' ; interface IntervalParams { min : string ; max : string ; maxBuckets : number ; } export function getIntervalAndTimefield ( panel , index , { min , max , maxBuckets } , series ? ) { let timeField = ( series ?. override_index_pattern ? series . series_time_field : panel . time_field ) || index . indexPattern ?. timeFieldName ; if ( ! panel . use_kibana_indexes && ! timeField ) { timeField = '@timestamp' ; } if ( panel . use_kibana_indexes ) { validateField ( timeField ! , index ) ; } let interval = panel . interval ; let maxBars = panel . max_bars ; if ( series ?. override_index_pattern ) { interval = series . series_interval || AUTO_INTERVAL ; maxBars = series . series_max_bars ; } validateInterval ( { min : moment . utc ( min ) , max : moment . utc ( max ) , } , interval , maxBuckets ) ; return { maxBars , timeField , interval : interval || AUTO_INTERVAL , } ; }