import { i18n } from '@osd/i18n' ; import { BehaviorSubject } from 'rxjs' ; import { ManagementSetup , ManagementStart } from './types' ; import { FeatureCatalogueCategory , HomePublicPluginSetup } from '../../home/public' ; import { CoreSetup , CoreStart , Plugin , DEFAULT_APP_CATEGORIES , PluginInitializerContext , AppMountParameters , AppUpdater , AppStatus , AppNavLinkStatus , } from '../../../core/public' ; import { MANAGEMENT_APP_ID } from '../common/contants' ; import { ManagementSectionsService , getSectionsServiceStartPrivate , } from './management_sections_service' ; interface ManagementSetupDependencies { home ? : HomePublicPluginSetup ; } export class ManagementPlugin implements Plugin < ManagementSetup , ManagementStart > { private readonly managementSections = new ManagementSectionsService ( ) ; private readonly appUpdater = new BehaviorSubject < AppUpdater > ( ( ) => ( { } ) ) ; private hasAnyEnabledApps = true ; constructor ( private initializerContext ) { } public setup ( core , { home } ) { const opensearchDashboardsVersion = this . initializerContext . env . packageInfo . version ; if ( home ) { home . featureCatalogue . register ( { id : 'stack-management' , title : i18n . translate ( 'management.stackManagement.managementLabel' , { defaultMessage : 'Stack Management' , } ) , description : i18n . translate ( 'management.stackManagement.managementDescription' , { defaultMessage : 'Your center console for managing the OpenSearch Stack.' , } ) , icon : 'managementApp' , path : '/app/management' , showOnHomePage : false , category : FeatureCatalogueCategory . ADMIN , visible : ( ) => this . hasAnyEnabledApps , } ) ; } core . application . register ( { id : MANAGEMENT_APP_ID , title : i18n . translate ( 'management.stackManagement.title' , { defaultMessage : 'Stack Management' , } ) , order : 9040 , euiIconType : '/plugins/home/assets/logos/opensearch_mark_default.svg' , category : DEFAULT_APP_CATEGORIES . management , updater$ : this . appUpdater , async mount ( params ) { const { renderApp } = await import ( './application' ) ; const [ coreStart ] = await core . getStartServices ( ) ; return renderApp ( params , { sections : getSectionsServiceStartPrivate ( ) , opensearchDashboardsVersion , setBreadcrumbs : coreStart . chrome . setBreadcrumbs , } ) ; } , } ) ; return { sections : this . managementSections . setup ( ) , } ; } public start ( core ) { this . managementSections . start ( { capabilities : core . application . capabilities } ) ; this . hasAnyEnabledApps = getSectionsServiceStartPrivate ( ) . getSectionsEnabled ( ) . some ( ( section ) => section . getAppsEnabled ( ) . length > 0 ) ; if ( ! this . hasAnyEnabledApps ) { this . appUpdater . next ( ( ) => { return { status : AppStatus . inaccessible , navLinkStatus : AppNavLinkStatus . hidden , } ; } ) ; } return { } ; } }