/**
 * Creates URL to the DataFrameAnalytics page
 */ import { isEmpty } from 'lodash' ; import { formatGenericMlUrl } from './common' ; import { DataFrameAnalyticsExplorationQueryState , DataFrameAnalyticsExplorationUrlState , DataFrameAnalyticsUrlState , ExplorationPageUrlState , MlGenericUrlState , MlCommonGlobalState , } from '../../../common/types/locator' ; import { ML_PAGES } from '../../../common/constants/locator' ; import { setStateToKbnUrl } from '../../../../../../src/plugins/kibana_utils/public' ; import { getGroupQueryText , getJobQueryText } from '../../../common/util/string_utils' ; import { AppPageState , ListingPageUrlState } from '../../../common/types/common' ; export function formatDataFrameAnalyticsJobManagementUrl ( appBasePath , mlUrlGeneratorState ) { let url = `${ appBasePath }/${ ML_PAGES . DATA_FRAME_ANALYTICS_JOBS_MANAGE }` ; if ( mlUrlGeneratorState ) { const { jobId , groupIds , globalState } = mlUrlGeneratorState ; if ( jobId || groupIds ) { const queryTextArr = [ ] ; if ( jobId ) { queryTextArr . push ( getJobQueryText ( jobId ) ) ; } if ( groupIds ) { queryTextArr . push ( getGroupQueryText ( groupIds ) ) ; } const jobsListState = { ... ( queryTextArr . length > 0 ? { queryText : queryTextArr . join ( ' ' ) } : { } ) , } ; const queryState = { [ ML_PAGES . DATA_FRAME_ANALYTICS_JOBS_MANAGE ] : jobsListState , } ; url = setStateToKbnUrl < AppPageState < ListingPageUrlState > > ( '_a' , queryState , { useHash : false , storeInHashQuery : false } , url ) ; } if ( globalState ) { url = setStateToKbnUrl < Partial < MlCommonGlobalState > > ( '_g' , globalState , { useHash : false , storeInHashQuery : false } , url ) ; } } return url ; } /**
 * Creates URL to the DataFrameAnalytics Exploration page
 */ export function formatDataFrameAnalyticsExplorationUrl ( appBasePath , mlUrlGeneratorState ) { let url = `${ appBasePath }/${ ML_PAGES . DATA_FRAME_ANALYTICS_EXPLORATION }` ; if ( mlUrlGeneratorState ) { const { jobId , analysisType , queryText , globalState } = mlUrlGeneratorState ; const queryState = { ml : { jobId , analysisType , } , ... globalState , } ; const appState = { [ ML_PAGES . DATA_FRAME_ANALYTICS_EXPLORATION ] : { ... ( queryText ? { queryText } : { } ) , } , } ; if ( ! isEmpty ( appState [ ML_PAGES . DATA_FRAME_ANALYTICS_EXPLORATION ] ) ) { url = setStateToKbnUrl < AppPageState < ExplorationPageUrlState > > ( '_a' , appState , { useHash : false , storeInHashQuery : false } , url ) ; } url = setStateToKbnUrl < DataFrameAnalyticsExplorationQueryState > ( '_g' , queryState , { useHash : false , storeInHashQuery : false } , url ) ; } return url ; } /**
 * Creates URL to the DataFrameAnalytics creation wizard
 */ export function formatDataFrameAnalyticsCreateJobUrl ( appBasePath , pageState ) { return formatGenericMlUrl ( appBasePath , ML_PAGES . DATA_FRAME_ANALYTICS_CREATE_JOB , pageState ) ; } /**
 * Creates URL to the DataFrameAnalytics Map page
 */ export function formatDataFrameAnalyticsMapUrl ( appBasePath , mlUrlGeneratorState ) { let url = `${ appBasePath }/${ ML_PAGES . DATA_FRAME_ANALYTICS_MAP }` ; if ( mlUrlGeneratorState ) { const { jobId , modelId , analysisType , globalState , queryText } = mlUrlGeneratorState ; const queryState = { ml : { jobId , modelId , analysisType , } , ... globalState , } ; const appState = { [ ML_PAGES . DATA_FRAME_ANALYTICS_MAP ] : { ... ( queryText ? { queryText } : { } ) , } , } ; if ( ! isEmpty ( appState [ ML_PAGES . DATA_FRAME_ANALYTICS_MAP ] ) ) { url = setStateToKbnUrl < AppPageState < ExplorationPageUrlState > > ( '_a' , appState , { useHash : false , storeInHashQuery : false } , url ) ; } url = setStateToKbnUrl < DataFrameAnalyticsExplorationQueryState > ( '_g' , queryState , { useHash : false , storeInHashQuery : false } , url ) ; } return url ; }