import React from 'react' ; import { EuiButton , EuiFlexGroup , EuiFlexItem } from '@elastic/eui' ; import { i18n } from '@kbn/i18n' ; import { FormattedMessage } from '@kbn/i18n-react' ; import type { HttpStart , NotificationsStart } from '../..' ; import type { DocLinksStart } from '../../doc_links' ; import { mountReactNode } from '../../utils' ; /** Only exported for tests */ export const MISSING_CONFIG_STORAGE_KEY = `core.warnings.publicBaseUrlMissingDismissed` ; interface Deps { docLinks : DocLinksStart ; http : HttpStart ; notifications : NotificationsStart ; storage ? : Storage ; location ? : Location ; } export const setupPublicBaseUrlConfigWarning = ( { docLinks , http , notifications , storage = window . localStorage , location = window . location , } ) => { if ( location . hostname === 'localhost' || location . hostname === '127.0.0.1' ) { return ; } const missingWarningSeen = storage . getItem ( MISSING_CONFIG_STORAGE_KEY ) === 'true' ; if ( missingWarningSeen || http . basePath . publicBaseUrl ) { return ; } const toast = notifications . toasts . addWarning ( { title : i18n . translate ( 'core.ui.publicBaseUrlWarning.configMissingTitle' , { defaultMessage : 'Configuration missing' , } ) , text : mountReactNode ( < > < p > < FormattedMessage id = "core.ui.publicBaseUrlWarning.configMissingDescription" defaultMessage = "{configKey} is missing and should be configured when running in a production environment. Some features may not behave correctly." values = { { configKey : < code > server . publicBaseUrl < /code>, } } / > { ' ' } < a href = { `${ docLinks . links . settings }#server-publicBaseUrl` } target = "_blank" > < FormattedMessage id = "core.ui.publicBaseUrlWarning.seeDocumentationLinkLabel" defaultMessage = "See the documentation." / > < /a> < /p> < EuiFlexGroup justifyContent = "flexEnd" gutterSize = "s" > < EuiFlexItem grow = { false } > < EuiButton size = "s" onClick = { ( ) => { notifications . toasts . remove ( toast ) ; storage . setItem ( MISSING_CONFIG_STORAGE_KEY , 'true' ) ; } } id = "mute" > < FormattedMessage id = "core.ui.publicBaseUrlWarning.muteWarningButtonLabel" defaultMessage = "Mute warning" / > < /EuiButton> < /EuiFlexItem> < /EuiFlexGroup> < />), } ) ; } ;