import React , { FC , Fragment } from 'react' ; import { i18n } from '@kbn/i18n' ; import { EuiCallOut } from '@elastic/eui' ; interface Props { error : string | JSX . Element ; } export const ErrorCallout = ( { error } ) => { let errorCallout = ( < EuiCallOut title = { i18n . translate ( 'xpack.ml.dataframe.analytics.errorCallout.generalErrorTitle' , { defaultMessage : 'An error occurred loading the data.' , } ) } color = "danger" iconType = "cross" > < p > { error } < /p> < /EuiCallOut>); if ( typeof error === 'string' && error . includes ( 'index_not_found' ) ) { errorCallout = ( < EuiCallOut title = { i18n . translate ( 'xpack.ml.dataframe.analytics.errorCallout.evaluateErrorTitle' , { defaultMessage : 'An error occurred loading the data.' , } ) } color = "danger" iconType = "cross" > < p > { i18n . translate ( 'xpack.ml.dataframe.analytics.errorCallout.noIndexCalloutBody' , { defaultMessage : 'The query for the index returned no results. Please make sure the destination index exists and contains documents.' , } ) } < /p> < /EuiCallOut>); } else if ( typeof error === 'string' && error . includes ( 'No documents found' ) ) { errorCallout = ( < EuiCallOut title = { i18n . translate ( 'xpack.ml.dataframe.analytics.errorCallout.noDataCalloutTitle' , { defaultMessage : 'Empty index query result.' , } ) } color = "primary" > < p > { i18n . translate ( 'xpack.ml.dataframe.analytics.errorCallout.noDataCalloutBody' , { defaultMessage : 'The query for the index returned no results. Please make sure the job has completed and the index contains documents.' , } ) } < /p> < /EuiCallOut>); } else if ( typeof error === 'string' && error . includes ( 'userProvidedQueryBuilder' ) ) { errorCallout = ( < EuiCallOut title = { i18n . translate ( 'xpack.ml.dataframe.analytics.errorCallout.queryParsingErrorTitle' , { defaultMessage : 'Unable to parse query.' , } ) } color = "primary" > < p > { i18n . translate ( 'xpack.ml.dataframe.analytics.errorCallout.queryParsingErrorBody' , { defaultMessage : 'The query syntax is invalid and returned no results. Please check the query syntax and try again.' , } ) } < /p> < /EuiCallOut>); } return < Fragment > { errorCallout } < /Fragment>; } ;