import { i18n } from '@osd/i18n' ; import * as React from 'react' ; import { PluginInitializerContext , CoreSetup , CoreStart , Plugin } from '../../../core/public' ; import { toMountPoint } from '../../opensearch_dashboards_react/public' ; import { InspectorViewRegistry } from './view_registry' ; import { InspectorOptions , InspectorSession } from './types' ; import { InspectorPanel } from './ui/inspector_panel' ; import { Adapters } from '../common' ; import { getRequestsViewDescription , getDataViewDescription } from './views' ; export interface Setup { registerView : InspectorViewRegistry [ 'register' ] ; __LEGACY : { views : InspectorViewRegistry ; } ; } export interface Start { param { object } adapters returns { boolean } isAvailable : ( adapters ? : Adapters ) => boolean ; /**
     * Opens the inspector panel for the given adapters and close any previously opened
     * inspector panel. The previously panel will be closed also if no new panel will be
     * opened (e.g. because of the passed adapters no view is available). You can use
     *  InspectorSession on the return value to close that opened panel again.
     *
     *  param { object } adapters param { InspectorOptions } options return { InspectorSession } throws open : ( adapters : Adapters , options ? : InspectorOptions ) => InspectorSession ; } export class InspectorPublicPlugin implements Plugin < Setup , Start > { views : InspectorViewRegistry | undefined ; constructor ( initializerContext ) { } public async setup ( core ) { this . views = new InspectorViewRegistry ( ) ; this . views . register ( getDataViewDescription ( core . uiSettings ) ) ; this . views . register ( getRequestsViewDescription ( ) ) ; return { registerView : this . views ! . register . bind ( this . views ) , __LEGACY : { views : this . views , } , } ; } public start ( core ) { const isAvailable = ( adapters ) => this . views ! . getVisible ( adapters ) . length > 0 ; const closeButtonLabel = i18n . translate ( 'inspector.closeButton' , { defaultMessage : 'Close Inspector' , } ) ; const open = ( adapters , options = { } ) => { const views = this . views ! . getVisible ( adapters ) ; if ( ! views || views . length === 0 ) { throw new Error ( `Tried to open an inspector without views being available.
          Make sure to call Inspector.isAvailable() with the same adapters before to check
          if an inspector can be shown.` ) ; } return core . overlays . openFlyout ( toMountPoint ( < InspectorPanel views = { views } adapters = { adapters } title = { options . title } / > ) , { 'data-test-subj' : 'inspectorPanel' , closeButtonAriaLabel : closeButtonLabel , } ) ; } ; return { isAvailable , open , } ; } public stop ( ) { } }