import { identity } from 'lodash' ; import { SerializedFieldFormat } from '../../../../expressions/common/types' ; import { FieldFormat } from '../../../common' ; import { FormatFactory } from '../../../common/field_formats/utils' ; import { getFormatWithAggs } from '../../../common/search/aggs' ; import { DataPublicPluginStart , IFieldFormat } from '../../../public' ; import { getUiSettings } from '../../../public/services' ; const getConfig = ( key , defaultOverride ? ) : any => getUiSettings ( ) . get ( key , defaultOverride ) ; const DefaultFieldFormat = FieldFormat . from ( identity ) ; export const deserializeFieldFormat = function ( this , serializedFieldFormat ? ) { if ( ! serializedFieldFormat ) { return new DefaultFieldFormat ( ) ; } const getFormat = ( mapping ) : IFieldFormat => { const { id , params = { } } = mapping ; if ( id ) { const Format = this . getType ( id ) ; if ( Format ) { return new Format ( params , getConfig ) ; } } return new DefaultFieldFormat ( ) ; } ; const getFieldFormat = getFormatWithAggs ( getFormat ) ; return getFieldFormat ( serializedFieldFormat ) ; } ;