import { i18n } from '@osd/i18n' ; import { IIndexPattern } from '../..' ; import { getIndexPatternFromFilter } from './get_index_pattern_from_filter' ; import { Filter } from '../filters' ; function getValueFormatter ( indexPattern ? , key ? ) { if ( ! indexPattern || ! indexPattern . getFormatterForField || ! key ) return ; const field = indexPattern . fields . find ( ( f ) => f . name === key ) ; if ( ! field ) { throw new Error ( i18n . translate ( 'data.filter.filterBar.fieldNotFound' , { defaultMessage : 'Field {key} not found in index pattern {indexPattern}' , values : { key , indexPattern : indexPattern . title } , } ) ) ; } return indexPattern . getFormatterForField ( field ) ; } export function getDisplayValueFromFilter ( filter , indexPatterns ) { if ( typeof filter . meta . value === 'function' ) { const indexPattern = getIndexPatternFromFilter ( filter , indexPatterns ) ; const valueFormatter = getValueFormatter ( indexPattern , filter . meta . key ) ; return ( filter . meta . value as any ) ( valueFormatter ) ; } else { return filter . meta . value || '' ; } }