import _ from 'lodash' ; import { Filter } from '@kbn/es-query' ; import { ITooltipProperty } from './tooltip_property' ; import { IField } from '../fields/field' ; import { esFilters , IndexPattern , IndexPatternField , } from '../../../../../../src/plugins/data/public' ; export class ESTooltipProperty implements ITooltipProperty { private readonly _tooltipProperty : ITooltipProperty ; private readonly _indexPattern : IndexPattern ; private readonly _field : IField ; private readonly _applyGlobalQuery : boolean ; constructor ( tooltipProperty , indexPattern , field , applyGlobalQuery ) { this . _tooltipProperty = tooltipProperty ; this . _indexPattern = indexPattern ; this . _field = field ; this . _applyGlobalQuery = applyGlobalQuery ; } getPropertyKey ( ) { return this . _tooltipProperty . getPropertyKey ( ) ; } getPropertyName ( ) { return this . _tooltipProperty . getPropertyName ( ) ; } getRawValue ( ) { return this . _tooltipProperty . getRawValue ( ) ; } _getIndexPatternField ( ) { return this . _indexPattern . fields . getByName ( this . _field . getRootName ( ) ) ; } getHtmlDisplayValue ( ) { if ( typeof this . getRawValue ( ) === 'undefined' ) { return '-' ; } const indexPatternField = this . _getIndexPatternField ( ) ; if ( ! indexPatternField || ! this . _field . canValueBeFormatted ( ) ) { const rawValue = this . getRawValue ( ) ; if ( Array . isArray ( rawValue ) ) { return _ . escape ( rawValue . join ( ) ) ; } else { return _ . escape ( rawValue ) ; } } const formatter = this . _indexPattern . getFormatterForField ( indexPatternField ) ; const htmlConverter = formatter . getConverterFor ( 'html' ) ; return htmlConverter ? htmlConverter ( this . getRawValue ( ) ) : formatter . convert ( this . getRawValue ( ) ) ; } isFilterable ( ) { if ( ! this . _applyGlobalQuery ) { return false ; } const indexPatternField = this . _getIndexPatternField ( ) ; return ( ! ! indexPatternField && ( indexPatternField . type === 'string' || indexPatternField . type === 'date' || indexPatternField . type === 'ip' || indexPatternField . type === 'number' ) ) ; } async getESFilters ( ) { if ( ! this . _applyGlobalQuery ) { return [ ] ; } const indexPatternField = this . _getIndexPatternField ( ) ; if ( ! indexPatternField ) { return [ ] ; } const rawValue = this . getRawValue ( ) ; if ( rawValue == null ) { const existsFilter = esFilters . buildExistsFilter ( indexPatternField , this . _indexPattern ) ; existsFilter . meta . negate = true ; return [ existsFilter ] ; } else { const values = Array . isArray ( rawValue ) ? ( rawValue as string [ ] ) : [ rawValue as string ] ; return values . map ( ( value ) => { return esFilters . buildPhraseFilter ( indexPatternField , value , this . _indexPattern ) ; } ) ; } } }