import { EuiCallOut } from '@elastic/eui' ; import { i18n } from '@osd/i18n' ; import React from 'react' ; import { CoreStart } from 'opensearch-dashboards/public' ; import { toMountPoint } from '../../../../opensearch_dashboards_react/public' ; let bannerId ; export const onRedirectNoIndexPattern = ( capabilities , navigateToApp , overlays ) => ( ) => { const canManageIndexPatterns = capabilities . management . opensearchDashboards . indexPatterns ; const redirectTarget = canManageIndexPatterns ? '/management/opensearch-dashboards/indexPatterns' : '/home' ; let timeoutId ; if ( timeoutId ) { clearTimeout ( timeoutId ) ; } const bannerMessage = i18n . translate ( 'data.indexPatterns.ensureDefaultIndexPattern.bannerLabel' , { defaultMessage : 'To visualize and explore data in OpenSearch Dashboards, you must create an index pattern to retrieve data from OpenSearch.' , } ) ; bannerId = overlays . banners . replace ( bannerId , toMountPoint ( < EuiCallOut color = "warning" iconType = "iInCircle" title = { bannerMessage } / > ) ) ; timeoutId = setTimeout ( ( ) => { overlays . banners . remove ( bannerId ) ; timeoutId = undefined ; } , 15000 ) ; if ( redirectTarget === '/home' ) { navigateToApp ( 'home' ) ; } else { navigateToApp ( 'management' , { path : `/opensearch-dashboards/indexPatterns?bannerMessage=${ bannerMessage }` , } ) ; } return new Promise ( ( ) => { } ) ; } ;