import { i18n } from '@kbn/i18n' ; import { CoreSetup , Plugin , CoreStart , PluginInitializerContext } from 'kibana/public' ; import { PLUGIN } from '../common/constants' ; import { init as initBreadcrumbs } from './application/services/breadcrumb' ; import { init as initDocumentation } from './application/services/documentation' ; import { init as initHttp } from './application/services/http' ; import { init as initUiMetric } from './application/services/ui_metric' ; import { init as initNotification } from './application/services/notification' ; import { init as initRedirect } from './application/services/redirect' ; import { Dependencies , ClientConfigType } from './types' ; export interface RemoteClustersPluginSetup { isUiEnabled : boolean ; } export class RemoteClustersUIPlugin implements Plugin < RemoteClustersPluginSetup , void , Dependencies , any > { constructor ( private readonly initializerContext ) { } setup ( { notifications : { toasts } , http , getStartServices } , { management , usageCollection , cloud } ) { const { ui : { enabled : isRemoteClustersUiEnabled } , } = this . initializerContext . config . get < ClientConfigType > ( ) ; if ( isRemoteClustersUiEnabled ) { const esSection = management . sections . section . data ; esSection . registerApp ( { id : 'remote_clusters' , title : i18n . translate ( 'xpack.remoteClusters.appTitle' , { defaultMessage : 'Remote Clusters' , } ) , order : 7 , mount : async ( { element , setBreadcrumbs , history , theme$ } ) => { const [ core ] = await getStartServices ( ) ; const { chrome : { docTitle } , i18n : { Context : i18nContext } , docLinks , fatalErrors , } = core ; docTitle . change ( PLUGIN . getI18nName ( ) ) ; initBreadcrumbs ( setBreadcrumbs ) ; initDocumentation ( docLinks ) ; initUiMetric ( usageCollection ) ; initNotification ( toasts , fatalErrors ) ; initHttp ( http ) ; const isCloudEnabled = Boolean ( cloud ?. isCloudEnabled ) ; const cloudBaseUrl = cloud ?. baseUrl ?? '' ; const { renderApp } = await import ( './application' ) ; const unmountAppCallback = await renderApp ( element , i18nContext , { isCloudEnabled , cloudBaseUrl } , history , theme$ ) ; return ( ) => { docTitle . reset ( ) ; unmountAppCallback ( ) ; } ; } , } ) ; } return { isUiEnabled : isRemoteClustersUiEnabled , } ; } start ( { application } ) { const { ui : { enabled : isRemoteClustersUiEnabled } , } = this . initializerContext . config . get < ClientConfigType > ( ) ; if ( isRemoteClustersUiEnabled ) { initRedirect ( application . navigateToApp ) ; } } stop ( ) { } }