import { AppMountParameters , CoreStart , CoreSetup , HttpSetup , Plugin , PluginInitializerContext , DEFAULT_APP_CATEGORIES , } from '../../../../src/core/public' ; import { ChartsPluginStart } from '../../../../src/plugins/charts/public' ; import { DataPublicPluginStart } from '../../../../src/plugins/data/public' ; import { FeatureCatalogueCategory , HomePublicPluginSetup , } from '../../../../src/plugins/home/public' ; import { CloudSetup } from '../../cloud/public' ; import { LicensingPluginStart } from '../../licensing/public' ; import { SecurityPluginSetup , SecurityPluginStart } from '../../security/public' ; import { APP_SEARCH_PLUGIN , ENTERPRISE_SEARCH_PLUGIN , WORKPLACE_SEARCH_PLUGIN , } from '../common/constants' ; import { InitialAppData } from '../common/types' ; import { docLinks } from './applications/shared/doc_links' ; export interface ClientConfigType { host ? : string ; } export interface ClientData extends InitialAppData { publicUrl ? : string ; errorConnectingMessage ? : string ; } interface PluginsSetup { cloud ? : CloudSetup ; home ? : HomePublicPluginSetup ; security : SecurityPluginSetup ; } export interface PluginsStart { cloud ? : CloudSetup ; licensing : LicensingPluginStart ; charts : ChartsPluginStart ; data : DataPublicPluginStart ; security : SecurityPluginStart ; } export class EnterpriseSearchPlugin implements Plugin { private config : ClientConfigType ; private hasInitialized : boolean = false ; private data : ClientData = { } as ClientData ; constructor ( initializerContext ) { this . config = initializerContext . config . get < ClientConfigType > ( ) ; } public setup ( core , plugins ) { const { cloud } = plugins ; core . application . register ( { id : ENTERPRISE_SEARCH_PLUGIN . ID , title : ENTERPRISE_SEARCH_PLUGIN . NAV_TITLE , euiIconType : ENTERPRISE_SEARCH_PLUGIN . LOGO , appRoute : ENTERPRISE_SEARCH_PLUGIN . URL , category : DEFAULT_APP_CATEGORIES . enterpriseSearch , mount : async ( params ) => { const kibanaDeps = await this . getKibanaDeps ( core , params , cloud ) ; const { chrome , http } = kibanaDeps . core ; chrome . docTitle . change ( ENTERPRISE_SEARCH_PLUGIN . NAME ) ; await this . getInitialData ( http ) ; const pluginData = this . getPluginData ( ) ; const { renderApp } = await import ( './applications' ) ; const { EnterpriseSearch } = await import ( './applications/enterprise_search' ) ; return renderApp ( EnterpriseSearch , kibanaDeps , pluginData ) ; } , } ) ; core . application . register ( { id : APP_SEARCH_PLUGIN . ID , title : APP_SEARCH_PLUGIN . NAME , euiIconType : ENTERPRISE_SEARCH_PLUGIN . LOGO , appRoute : APP_SEARCH_PLUGIN . URL , category : DEFAULT_APP_CATEGORIES . enterpriseSearch , mount : async ( params ) => { const kibanaDeps = await this . getKibanaDeps ( core , params , cloud ) ; const { chrome , http } = kibanaDeps . core ; chrome . docTitle . change ( APP_SEARCH_PLUGIN . NAME ) ; await this . getInitialData ( http ) ; const pluginData = this . getPluginData ( ) ; const { renderApp } = await import ( './applications' ) ; const { AppSearch } = await import ( './applications/app_search' ) ; return renderApp ( AppSearch , kibanaDeps , pluginData ) ; } , } ) ; core . application . register ( { id : WORKPLACE_SEARCH_PLUGIN . ID , title : WORKPLACE_SEARCH_PLUGIN . NAME , euiIconType : ENTERPRISE_SEARCH_PLUGIN . LOGO , appRoute : WORKPLACE_SEARCH_PLUGIN . URL , category : DEFAULT_APP_CATEGORIES . enterpriseSearch , mount : async ( params ) => { const kibanaDeps = await this . getKibanaDeps ( core , params , cloud ) ; const { chrome , http } = kibanaDeps . core ; chrome . docTitle . change ( WORKPLACE_SEARCH_PLUGIN . NAME ) ; if ( this . config . host ) chrome . setIsVisible ( false ) ; await this . getInitialData ( http ) ; const pluginData = this . getPluginData ( ) ; const { renderApp } = await import ( './applications' ) ; const { WorkplaceSearch } = await import ( './applications/workplace_search' ) ; return renderApp ( WorkplaceSearch , kibanaDeps , pluginData ) ; } , } ) ; if ( plugins . home ) { plugins . home . featureCatalogue . registerSolution ( { id : ENTERPRISE_SEARCH_PLUGIN . ID , title : ENTERPRISE_SEARCH_PLUGIN . NAME , icon : 'logoEnterpriseSearch' , description : ENTERPRISE_SEARCH_PLUGIN . DESCRIPTION , path : ENTERPRISE_SEARCH_PLUGIN . URL , order : 100 , } ) ; plugins . home . featureCatalogue . register ( { id : APP_SEARCH_PLUGIN . ID , title : APP_SEARCH_PLUGIN . NAME , icon : 'appSearchApp' , description : APP_SEARCH_PLUGIN . DESCRIPTION , path : APP_SEARCH_PLUGIN . URL , category : FeatureCatalogueCategory . DATA , showOnHomePage : false , } ) ; plugins . home . featureCatalogue . register ( { id : WORKPLACE_SEARCH_PLUGIN . ID , title : WORKPLACE_SEARCH_PLUGIN . NAME , icon : 'workplaceSearchApp' , description : WORKPLACE_SEARCH_PLUGIN . DESCRIPTION , path : WORKPLACE_SEARCH_PLUGIN . URL , category : FeatureCatalogueCategory . DATA , showOnHomePage : false , } ) ; } } public start ( core ) { docLinks . setDocLinks ( core . docLinks ) ; } public stop ( ) { } private async getKibanaDeps ( core , params , cloud ? ) { const [ coreStart , pluginsStart ] = await core . getStartServices ( ) ; const plugins = { ... pluginsStart , cloud } as PluginsStart ; return { params , core : coreStart , plugins } ; } private getPluginData ( ) { return { config : this . config , data : this . data } ; } private async getInitialData ( http ) { if ( ! this . config . host ) return ; if ( this . hasInitialized ) return ; try { this . data = await http . get ( '/internal/enterprise_search/config_data' ) ; this . hasInitialized = true ; } catch ( e ) { this . data . errorConnectingMessage = `${ e . res . status } ${ e . message }` ; } } }