import React from 'react' ; import { CoreStart } from 'kibana/public' ; import { VIEW_BY_JOB_LABEL } from '../../application/explorer/explorer_constants' ; import { toMountPoint , wrapWithTheme } from '../../../../../../src/plugins/kibana_react/public' ; import { AnomalyDetectorService } from '../../application/services/anomaly_detector_service' ; import { getDefaultExplorerChartsPanelTitle } from './anomaly_charts_embeddable' ; import { HttpService } from '../../application/services/http_service' ; import { AnomalyChartsEmbeddableInput } from '..' ; import { resolveJobSelection } from '../common/resolve_job_selection' ; import { AnomalyChartsInitializer } from './anomaly_charts_initializer' ; export async function resolveEmbeddableAnomalyChartsUserInput ( coreStart , input ? ) { const { http , overlays } = coreStart ; const anomalyDetectorService = new AnomalyDetectorService ( new HttpService ( http ) ) ; return new Promise ( async ( resolve , reject ) => { try { const { jobIds } = await resolveJobSelection ( coreStart , input ?. jobIds ) ; const title = input ?. title ?? getDefaultExplorerChartsPanelTitle ( jobIds ) ; const jobs = await anomalyDetectorService . getJobs$ ( jobIds ) . toPromise ( ) ; const influencers = anomalyDetectorService . extractInfluencers ( jobs ) ; influencers . push ( VIEW_BY_JOB_LABEL ) ; const { theme$ } = coreStart . theme ; const modalSession = overlays . openModal ( toMountPoint ( wrapWithTheme ( < AnomalyChartsInitializer defaultTitle = { title } initialInput = { input } onCreate = { ( { panelTitle , maxSeriesToPlot } ) => { modalSession . close ( ) ; resolve ( { jobIds , title : panelTitle , maxSeriesToPlot , } ) ; } } onCancel = { ( ) => { modalSession . close ( ) ; reject ( ) ; } } />, theme$))); } catch ( error ) { reject ( error ) ; } } ) ; }