import { CoreStart } from 'kibana/public' ; import moment from 'moment' ; import { takeUntil } from 'rxjs/operators' ; import { from } from 'rxjs' ; import React from 'react' ; import { getInitialGroupsMap } from '../../application/components/job_selector/job_selector' ; import { KibanaContextProvider , toMountPoint , wrapWithTheme , } from '../../../../../../src/plugins/kibana_react/public' ; import { getMlGlobalServices } from '../../application/app' ; import { DashboardConstants } from '../../../../../../src/plugins/dashboard/public' ; import { JobId } from '../../../common/types/anomaly_detection_jobs' ; import { JobSelectorFlyout } from './components/job_selector_flyout' ; param coreStart param selectedJobIds export async function resolveJobSelection ( coreStart , selectedJobIds ? ) { const { http , uiSettings , theme , application : { currentAppId$ } , } = coreStart ; return new Promise ( async ( resolve , reject ) => { try { const maps = { groupsMap : getInitialGroupsMap ( [ ] ) , jobsMap : { } , } ; const tzConfig = uiSettings . get ( 'dateFormat:tz' ) ; const dateFormatTz = tzConfig !== 'Browser' ? tzConfig : moment . tz . guess ( ) ; const onFlyoutClose = ( ) => { flyoutSession . close ( ) ; reject ( ) ; } ; const onSelectionConfirmed = async ( { jobIds , groups , } ) => { await flyoutSession . close ( ) ; resolve ( { jobIds , groups , } ) ; } ; const flyoutSession = coreStart . overlays . openFlyout ( toMountPoint ( wrapWithTheme ( < KibanaContextProvider services = { { ... coreStart , mlServices : getMlGlobalServices ( http ) } } > < JobSelectorFlyout selectedIds = { selectedJobIds } withTimeRangeSelector = { false } dateFormatTz = { dateFormatTz } singleSelection = { false } timeseriesOnly = { true } onFlyoutClose = { onFlyoutClose } onSelectionConfirmed = { onSelectionConfirmed } maps = { maps } / > < /KibanaContextProvider>, theme.theme$)), { 'data-test-subj' : 'mlFlyoutJobSelector' , ownFocus : true , closeButtonAriaLabel : 'jobSelectorFlyout' , } ) ; currentAppId$ . pipe ( takeUntil ( from ( flyoutSession . onClose ) ) ) . subscribe ( ( appId ) => { if ( appId !== DashboardConstants . DASHBOARDS_ID ) { flyoutSession . close ( ) ; } } ) ; } catch ( error ) { reject ( error ) ; } } ) ; }