import { ManagementSection , RegisterManagementSectionArgs } from './utils' ; import { IngestSection , DataSection , InsightsAndAlertingSection , SecuritySection , OpenSearchDashboardsSection , StackSection , } from './components/management_sections' ; import { ManagementSectionId , SectionsServiceSetup , SectionsServiceStartDeps , DefinedSections , ManagementSectionsStartPrivate , } from './types' ; import { createGetterSetter } from '../../opensearch_dashboards_utils/public' ; const [ getSectionsServiceStartPrivate , setSectionsServiceStartPrivate ] = createGetterSetter < ManagementSectionsStartPrivate > ( 'SectionsServiceStartPrivate' ) ; export { getSectionsServiceStartPrivate } ; export class ManagementSectionsService { definedSections : DefinedSections ; constructor ( ) { this . definedSections = { ingest : this . registerSection ( IngestSection ) , data : this . registerSection ( DataSection ) , insightsAndAlerting : this . registerSection ( InsightsAndAlertingSection ) , security : this . registerSection ( SecuritySection ) , opensearchDashboards : this . registerSection ( OpenSearchDashboardsSection ) , stack : this . registerSection ( StackSection ) , } ; } private sections : Map < ManagementSectionId | string , ManagementSection > = new Map ( ) ; private getAllSections = ( ) => [ ... this . sections . values ( ) ] ; private registerSection = ( section ) => { if ( this . sections . has ( section . id ) ) { throw Error ( `ManagementSection '${ section . id }' already registered` ) ; } const newSection = new ManagementSection ( section ) ; this . sections . set ( section . id , newSection ) ; return newSection ; } ; setup ( ) { return { register : this . registerSection , section : { ... this . definedSections , } , } ; } start ( { capabilities } ) { this . getAllSections ( ) . forEach ( ( section ) => { if ( capabilities . management . hasOwnProperty ( section . id ) ) { const sectionCapabilities = capabilities . management [ section . id ] ; section . apps . forEach ( ( app ) => { if ( sectionCapabilities . hasOwnProperty ( app . id ) && sectionCapabilities [ app . id ] !== true ) { app . disable ( ) ; } } ) ; } } ) ; setSectionsServiceStartPrivate ( { getSectionsEnabled : ( ) => this . getAllSections ( ) . filter ( ( section ) => section . enabled ) , } ) ; return { } ; } }