import { last } from 'lodash' ; import { Metric } from '../../../../common/types' ; import { getAggByPredicate , isBasicAgg } from '../../../../common/agg_utils' ; export const getMetricsField = ( metrics ) => { const selectedMetric = last ( metrics ) ; if ( selectedMetric ) { const { isFieldRequired , isFieldFormattingDisabled } = getAggByPredicate ( selectedMetric . type ) ?. meta ; if ( isFieldRequired && ! isFieldFormattingDisabled ) { return isBasicAgg ( selectedMetric ) ? selectedMetric . field : metrics . find ( ( { id } ) => selectedMetric . field === id ) ?. field ; } } } ;