import React , { ReactNode } from 'react' ; import { i18n } from '@kbn/i18n' ; import { EuiIcon , EuiToolTip } from '@elastic/eui' ; import { Filter } from '@kbn/es-query' ; import { ITooltipProperty } from './tooltip_property' ; import { InnerJoin } from '../joins/inner_join' ; export class JoinTooltipProperty implements ITooltipProperty { private readonly _tooltipProperty : ITooltipProperty ; private readonly _innerJoins : InnerJoin [ ] ; constructor ( tooltipProperty , innerJoins ) { this . _tooltipProperty = tooltipProperty ; this . _innerJoins = innerJoins ; } isFilterable ( ) { return true ; } getPropertyKey ( ) { return this . _tooltipProperty . getPropertyKey ( ) ; } getPropertyName ( ) { const content = i18n . translate ( 'xpack.maps.tooltip.joinPropertyTooltipContent' , { defaultMessage : `Shared key '{leftFieldName}' is joined with {rightSources}` , values : { leftFieldName : this . _tooltipProperty . getPropertyName ( ) as string , rightSources : this . _innerJoins . map ( ( innerJoin ) => { const rightSource = innerJoin . getRightJoinSource ( ) ; const termField = rightSource . getTermField ( ) ; return `'${ termField . getName ( ) }'` ; } ) . join ( ',' ) , } , } ) ; return ( < > { this . _tooltipProperty . getPropertyName ( ) } < EuiToolTip position = "bottom" content = { content } > < EuiIcon type = "link" / > < /EuiToolTip> < />); } getRawValue ( ) { return this . _tooltipProperty . getRawValue ( ) ; } getHtmlDisplayValue ( ) { return this . _tooltipProperty . getHtmlDisplayValue ( ) ; } async getESFilters ( ) { const esFilters = [ ] ; for ( let i = 0 ; i < this . _innerJoins . length ; i ++ ) { const rightSource = this . _innerJoins [ i ] . getRightJoinSource ( ) ; const termField = rightSource . getTermField ( ) ; try { const esTooltipProperty = await termField . createTooltipProperty ( this . _tooltipProperty . getRawValue ( ) ) ; if ( esTooltipProperty ) { const filters = await esTooltipProperty . getESFilters ( ) ; esFilters . push ( ... filters ) ; } } catch ( e ) { console . error ( 'Cannot create joined filter' , e ) ; } } return esFilters ; } }