/**
 * TODO:
 * IMPORTANT: Please see how  BreadcrumbService is set up for an example of how these services should be set up
 * in future. The pattern in this file is legacy and should be updated to conform to the plugin lifecycle.
  import { UsageCollectionSetup } from 'src/plugins/usage_collection/public' ; import { UiCounterMetricType } from '@kbn/analytics' ; import { UIM_APP_NAME , UIM_CONFIG_COLD_PHASE , UIM_CONFIG_SET_PRIORITY , UIM_CONFIG_WARM_PHASE , defaultIndexPriority , } from '../constants' ; import { Phases } from '../../../common/types' ; export let trackUiMetric = ( metricType , eventName ) => { } ; export function init ( usageCollection ? ) { if ( usageCollection ) { trackUiMetric = usageCollection . reportUiCounter . bind ( usageCollection , UIM_APP_NAME ) ; } } export function getUiMetricsForPhases ( phases ) { const phaseUiMetrics = [ { metric : UIM_CONFIG_COLD_PHASE , isTracked : ( ) => Boolean ( phases . cold ) , } , { metric : UIM_CONFIG_WARM_PHASE , isTracked : ( ) => Boolean ( phases . warm ) , } , { metric : UIM_CONFIG_SET_PRIORITY , isTracked : ( ) => { const isHotPhasePriorityChanged = phases . hot && phases . hot . actions . set_priority && phases . hot . actions . set_priority . priority !== parseInt ( defaultIndexPriority . hot , 10 ) ; const isWarmPhasePriorityChanged = phases . warm && phases . warm . actions . set_priority && phases . warm . actions . set_priority . priority !== parseInt ( defaultIndexPriority . warm , 10 ) ; const isColdPhasePriorityChanged = phases . cold && phases . cold . actions . set_priority && phases . cold . actions . set_priority . priority !== parseInt ( defaultIndexPriority . cold , 10 ) ; return ( isHotPhasePriorityChanged || isWarmPhasePriorityChanged || isColdPhasePriorityChanged ) ; } , } , ] ; return phaseUiMetrics . reduce ( ( tracked , { metric , isTracked } ) => { if ( isTracked ( ) ) { tracked . push ( metric ) ; } return tracked ; } , [ ] ) ; }