import { isNumber } from 'lodash' ; import { getFieldFormats } from '../../../services' ; import { isEmptyValue , DISPLAY_EMPTY_VALUE } from '../../../../common/last_value_utils' ; import { FIELD_FORMAT_IDS } from '../../../../../../field_formats/common' ; import type { FieldFormatMap } from '../../../../../../data/common' ; import type { FieldFormatsContentType } from '../../../../../../field_formats/common' ; const DEFAULT_FIELD_FORMAT = { id : 'number' } ; export const createFieldFormatter = ( fieldName = '' , fieldFormatMap ? , contextType ? , hasColorRules = false ) => { const serializedFieldFormat = fieldFormatMap ?. [ fieldName ] ; const shouldSkipFormatting = ! serializedFieldFormat || ( hasColorRules && serializedFieldFormat ?. id === FIELD_FORMAT_IDS . COLOR ) ; const fieldFormat = getFieldFormats ( ) . deserialize ( shouldSkipFormatting ? DEFAULT_FIELD_FORMAT : serializedFieldFormat ) ; return ( value ) => { if ( isEmptyValue ( value ) ) { return DISPLAY_EMPTY_VALUE ; } return isNumber ( value ) || ! shouldSkipFormatting ? fieldFormat . convert ( value , contextType ) : value ; } ; } ;