import { i18n } from '@kbn/i18n' ; import { SERVICE_ENVIRONMENT } from './elasticsearch_fieldnames' ; import { Environment } from './environment_rt' ; const ENVIRONMENT_ALL_VALUE = 'ENVIRONMENT_ALL' as const ; const ENVIRONMENT_NOT_DEFINED_VALUE = 'ENVIRONMENT_NOT_DEFINED' as const ; export function getEnvironmentLabel ( environment ) { if ( ! environment || environment === ENVIRONMENT_NOT_DEFINED_VALUE ) { return i18n . translate ( 'xpack.apm.filter.environment.notDefinedLabel' , { defaultMessage : 'Not defined' , } ) ; } if ( environment === ENVIRONMENT_ALL_VALUE ) { return i18n . translate ( 'xpack.apm.filter.environment.allLabel' , { defaultMessage : 'All' , } ) ; } return environment ; } export const ENVIRONMENT_ALL = { value : ENVIRONMENT_ALL_VALUE , text : getEnvironmentLabel ( ENVIRONMENT_ALL_VALUE ) , } ; export const ENVIRONMENT_NOT_DEFINED = { value : ENVIRONMENT_NOT_DEFINED_VALUE , text : getEnvironmentLabel ( ENVIRONMENT_NOT_DEFINED_VALUE ) , } ; export function getEnvironmentEsField ( environment ) { if ( ! environment || environment === ENVIRONMENT_NOT_DEFINED_VALUE || environment === ENVIRONMENT_ALL_VALUE ) { return { } ; } return { [ SERVICE_ENVIRONMENT ] : environment } ; } export function getNextEnvironmentUrlParam ( { requestedEnvironment , currentEnvironmentUrlParam , } ) { const normalizedRequestedEnvironment = requestedEnvironment || ENVIRONMENT_NOT_DEFINED . value ; const normalizedQueryEnvironment = currentEnvironmentUrlParam || ENVIRONMENT_ALL . value ; if ( normalizedRequestedEnvironment === normalizedQueryEnvironment ) { return currentEnvironmentUrlParam || ENVIRONMENT_ALL . value ; } return ENVIRONMENT_ALL . value ; }