import moment from 'moment' ; import { EuiSelectProps } from '@elastic/eui' ; import { i18n } from '@kbn/i18n' ; import { ChartData } from './components/analytics_chart' ; import { SERVER_DATE_FORMAT } from './constants' ; interface ConvertToChartData { data : number [ ] ; startDate : string ; } export const convertToChartData = ( { data , startDate } ) : ChartData => { const date = moment ( startDate , SERVER_DATE_FORMAT ) ; return data . map ( ( y , index ) => ( { x : moment ( date ) . add ( index , 'days' ) . format ( SERVER_DATE_FORMAT ) , y , } ) ) ; } ; export const convertTagsToSelectOptions = ( tags ) : EuiSelectProps [ 'options' ] => { tags = tags . slice ( 1 ) ; const DEFAULT_OPTION = { value : '' , text : i18n . translate ( 'xpack.enterpriseSearch.appSearch.engine.analytics.allTagsDropDownOptionLabel' , { defaultMessage : 'All analytics tags' } ) , } ; return [ DEFAULT_OPTION , ... tags . map ( ( tag ) => ( { value : tag , text : tag , } ) ) , ] ; } ;