import { startCase } from 'lodash' ; import { IMetricAggConfig } from '../metric_agg_type' ; export const makeNestedLabel = ( aggConfig , label ) => { const uppercaseLabel = startCase ( label ) ; const customMetric = aggConfig . getParam ( 'customMetric' ) ; const metricAgg = aggConfig . getParam ( 'metricAgg' ) ; if ( customMetric ) { let metricLabel = customMetric . makeLabel ( ) ; if ( metricLabel . includes ( `${ uppercaseLabel } of ` ) ) { metricLabel = metricLabel . substring ( `${ uppercaseLabel } of ` . length ) ; metricLabel = `2. ${ label } of ${ metricLabel }` ; } else if ( metricLabel . includes ( `${ label } of ` ) ) { metricLabel = parseInt ( metricLabel . substring ( 0 , 1 ) , 10 ) + 1 + metricLabel . substring ( 1 ) ; } else { metricLabel = `${ uppercaseLabel } of ${ metricLabel }` ; } return metricLabel ; } const metric = aggConfig . aggConfigs . byId ( metricAgg ) ; if ( ! metric ) { return '' ; } return `${ uppercaseLabel } of ${ metric . makeLabel ( ) }` ; } ;