import { AppMountParameters , CoreSetup , CoreStart , Plugin , PluginInitializerContext , } from 'opensearch-dashboards/public' ; import { i18n } from '@osd/i18n' ; import { first } from 'rxjs/operators' ; import { Branding } from 'src/core/types' ; import { EnvironmentService , EnvironmentServiceSetup , FeatureCatalogueCategory , FeatureCatalogueRegistry , FeatureCatalogueRegistrySetup , TutorialService , TutorialServiceSetup , } from './services' ; import { ConfigSchema } from '../config' ; import { setServices } from './application/opensearch_dashboards_services' ; import { DataPublicPluginStart } from '../../data/public' ; import { TelemetryPluginStart } from '../../telemetry/public' ; import { UsageCollectionSetup } from '../../usage_collection/public' ; import { UrlForwardingSetup , UrlForwardingStart } from '../../url_forwarding/public' ; import { AppNavLinkStatus } from '../../../core/public' ; import { PLUGIN_ID , HOME_APP_BASE_PATH } from '../common/constants' ; export interface HomePluginStartDependencies { data : DataPublicPluginStart ; telemetry ? : TelemetryPluginStart ; urlForwarding : UrlForwardingStart ; } export interface HomePluginSetupDependencies { usageCollection ? : UsageCollectionSetup ; urlForwarding : UrlForwardingSetup ; } export class HomePublicPlugin implements Plugin < HomePublicPluginSetup , HomePublicPluginStart , HomePluginSetupDependencies , HomePluginStartDependencies > { private readonly featuresCatalogueRegistry = new FeatureCatalogueRegistry ( ) ; private readonly environmentService = new EnvironmentService ( ) ; private readonly tutorialService = new TutorialService ( ) ; constructor ( private readonly initializerContext ) { } public setup ( core , { urlForwarding , usageCollection } ) { core . application . register ( { id : PLUGIN_ID , title : 'Home' , navLinkStatus : AppNavLinkStatus . hidden , mount : async ( params ) => { const trackUiMetric = usageCollection ? usageCollection . reportUiStats . bind ( usageCollection , 'OpenSearch_Dashboards_home' ) : ( ) => { } ; const [ coreStart , { telemetry , data , urlForwarding : urlForwardingStart } , ] = await core . getStartServices ( ) ; setServices ( { trackUiMetric , opensearchDashboardsVersion : this . initializerContext . env . packageInfo . version , http : coreStart . http , toastNotifications : core . notifications . toasts , banners : coreStart . overlays . banners , docLinks : coreStart . docLinks , savedObjectsClient : coreStart . savedObjects . client , chrome : coreStart . chrome , application : coreStart . application , telemetry , uiSettings : core . uiSettings , addBasePath : core . http . basePath . prepend , getBasePath : core . http . basePath . get , indexPatternService : data . indexPatterns , environmentService : this . environmentService , urlForwarding : urlForwardingStart , homeConfig : this . initializerContext . config . get ( ) , tutorialService : this . tutorialService , featureCatalogue : this . featuresCatalogueRegistry , injectedMetadata : coreStart . injectedMetadata , } ) ; coreStart . chrome . docTitle . change ( i18n . translate ( 'home.pageTitle' , { defaultMessage : 'Home' } ) ) ; const { renderApp } = await import ( './application' ) ; return await renderApp ( params . element , coreStart , params . history ) ; } , } ) ; urlForwarding . forwardApp ( 'home' , 'home' ) ; const featureCatalogue = { ... this . featuresCatalogueRegistry . setup ( ) } ; featureCatalogue . register ( { id : 'home_tutorial_directory' , title : i18n . translate ( 'home.tutorialDirectory.featureCatalogueTitle' , { defaultMessage : 'Add sample data' , } ) , description : i18n . translate ( 'home.tutorialDirectory.featureCatalogueDescription' , { defaultMessage : 'Get started with sample data, visualizations, and dashboards.' , } ) , icon : 'indexOpen' , showOnHomePage : true , path : `${ HOME_APP_BASE_PATH }#/tutorial_directory` , category : 'data' as FeatureCatalogueCategory . DATA , order : 500 , } ) ; return { featureCatalogue , environment : { ... this . environmentService . setup ( ) } , tutorials : { ... this . tutorialService . setup ( ) } , } ; } public start ( { application : { capabilities , currentAppId$ } , http } , { urlForwarding } ) { this . featuresCatalogueRegistry . start ( { capabilities } ) ; if ( window . location . pathname === http . basePath . prepend ( HOME_APP_BASE_PATH ) && window . location . hash === '' ) { currentAppId$ . pipe ( first ( ) ) . subscribe ( ( appId ) => { if ( appId === 'home' ) { urlForwarding . navigateToDefaultApp ( { overwriteHash : false } ) ; } } ) ; } return { featureCatalogue : this . featuresCatalogueRegistry } ; } } public export type FeatureCatalogueSetup = FeatureCatalogueRegistrySetup ; public export type EnvironmentSetup = EnvironmentServiceSetup ; public export type TutorialSetup = TutorialServiceSetup ; public export type HomePluginBranding = Branding ; public export interface HomePublicPluginSetup { tutorials : TutorialServiceSetup ; featureCatalogue : FeatureCatalogueSetup ; deprecated environment : EnvironmentSetup ; } export interface HomePublicPluginStart { featureCatalogue : FeatureCatalogueRegistry ; }