import React , { Fragment } from 'react' ; import { EuiTextColor } from '@elastic/eui' ; import { i18n } from '@osd/i18n' ; import { existsOperator , isOneOfOperator } from './filter_operators' ; import { Filter , FILTERS } from '../../../../../common' ; import type { FilterLabelStatus } from '../../filter_item' ; export interface FilterLabelProps { filter : Filter ; valueLabel ? : string ; filterLabelStatus ? : FilterLabelStatus ; } export default function FilterLabel ( { filter , valueLabel , filterLabelStatus } ) { const prefixText = filter . meta . negate ? ` ${ i18n . translate ( 'data.filter.filterBar.negatedFilterPrefix' , { defaultMessage : 'NOT ' , } ) }` : '' ; const prefix = filter . meta . negate && ! filter . meta . disabled ? ( < EuiTextColor color = "danger" > { prefixText } < /EuiTextColor>) : (prefixText); const getValue = ( text ? ) => { return < span className = "globalFilterLabel__value" > { text } < /span>; } ; if ( filter . meta . alias !== null ) { return ( < Fragment > { prefix } { filter . meta . alias } { filterLabelStatus && < > : { getValue ( valueLabel ) } < />} < /Fragment>); } switch ( filter . meta . type ) { case FILTERS . EXISTS : return ( < Fragment > { prefix } { filter . meta . key } : { getValue ( `${ existsOperator . message }` ) } < /Fragment>); case FILTERS . GEO_BOUNDING_BOX : return ( < Fragment > { prefix } { filter . meta . key } : { getValue ( valueLabel ) } < /Fragment>); case FILTERS . GEO_POLYGON : return ( < Fragment > { prefix } { filter . meta . key } : { getValue ( valueLabel ) } < /Fragment>); case FILTERS . PHRASES : return ( < Fragment > { prefix } { filter . meta . key } : { getValue ( `${ isOneOfOperator . message } ${ valueLabel }` ) } < /Fragment>); case FILTERS . QUERY_STRING : return ( < Fragment > { prefix } { getValue ( `${ valueLabel }` ) } < /Fragment>); case FILTERS . PHRASE : case FILTERS . RANGE : return ( < Fragment > { prefix } { filter . meta . key } : { getValue ( valueLabel ) } < /Fragment>); default : return ( < Fragment > { prefix } { getValue ( `${ JSON . stringify ( filter . query ) || filter . meta . value }` ) } < /Fragment>); } }