import { i18n } from '@kbn/i18n' ; import { ChromeStart , CoreStart , PluginInitializerContext , SavedObjectsClientContract , ToastsStart , OverlayStart , AppMountParameters , IUiSettingsClient , Capabilities , ScopedHistory , } from 'kibana/public' ; import ReactDOM from 'react-dom' ; import React from 'react' ; import { DataPlugin , IndexPatternsContract } from '../../../../src/plugins/data/public' ; import { LicensingPluginStart } from '../../licensing/public' ; import { checkLicense } from '../common/check_license' ; import { NavigationPublicPluginStart as NavigationStart } from '../../../../src/plugins/navigation/public' ; import { Storage } from '../../../../src/plugins/kibana_utils/public' ; import './index.scss' ; import ( './font_awesome' ) ; import { SavedObjectsStart } from '../../../../src/plugins/saved_objects/public' ; import { GraphSavePolicy } from './types' ; import { graphRouter } from './router' ; import { SpacesApi } from '../../spaces/public' ; import { KibanaThemeProvider } from '../../../../src/plugins/kibana_react/public' ; /**
 * These are dependencies of the Graph app besides the base dependencies
 * provided by the application service. Some of those still rely on non-shimmed
 * plugins in LP-world, but if they are migrated only the import path in the plugin
 * itself changes
 */ export interface GraphDependencies { pluginInitializerContext : PluginInitializerContext ; core : CoreStart ; coreStart : CoreStart ; element : HTMLElement ; appBasePath : string ; capabilities : Capabilities ; navigation : NavigationStart ; licensing : LicensingPluginStart ; chrome : ChromeStart ; toastNotifications : ToastsStart ; indexPatterns : IndexPatternsContract ; data : ReturnType < DataPlugin [ 'start' ] > ; savedObjectsClient : SavedObjectsClientContract ; addBasePath : ( url : string ) => string ; getBasePath : ( ) => string ; storage : Storage ; canEditDrillDownUrls : boolean ; graphSavePolicy : GraphSavePolicy ; overlays : OverlayStart ; savedObjects : SavedObjectsStart ; setHeaderActionMenu : AppMountParameters [ 'setHeaderActionMenu' ] ; uiSettings : IUiSettingsClient ; history : ScopedHistory < unknown > ; spaces ? : SpacesApi ; } export type GraphServices = Omit < GraphDependencies , 'element' | 'history' > ; export const renderApp = ( { history , element , ... deps } ) => { const { chrome , capabilities , core } = deps ; const { theme$ } = core . theme ; if ( ! capabilities . graph . save ) { chrome . setBadge ( { text : i18n . translate ( 'xpack.graph.badge.readOnly.text' , { defaultMessage : 'Read only' , } ) , tooltip : i18n . translate ( 'xpack.graph.badge.readOnly.tooltip' , { defaultMessage : 'Unable to save Graph workspaces' , } ) , iconType : 'glasses' , } ) ; } const licenseSubscription = deps . licensing . license$ . subscribe ( ( license ) => { const info = checkLicense ( license ) ; const licenseAllowsToShowThisPage = info . showAppLink && info . enableAppLink ; if ( ! licenseAllowsToShowThisPage ) { if ( info . message ) { deps . core . notifications . toasts . addDanger ( info . message ) ; } setTimeout ( ( ) => { deps . core . application . navigateToApp ( 'home' ) ; } , 0 ) ; } } ) ; const unlistenParentHistory = history . listen ( ( ) => { window . dispatchEvent ( new HashChangeEvent ( 'hashchange' ) ) ; } ) ; const app = < KibanaThemeProvider theme$ = { theme$ } > { graphRouter ( deps ) } < /KibanaThemeProvider>; ReactDOM . render ( app , element ) ; element . setAttribute ( 'class' , 'gphAppWrapper' ) ; return ( ) => { licenseSubscription . unsubscribe ( ) ; unlistenParentHistory ( ) ; ReactDOM . unmountComponentAtNode ( element ) ; } ; } ;