import { isEmpty } from 'lodash' ; import { MlGenericUrlState } from '../../../common/types/locator' ; import { setStateToKbnUrl } from '../../../../../../src/plugins/kibana_utils/public' ; export function extractParams < UrlState > ( urlState ) { const { page , ... params } = urlState ; return { page , params } ; } /**
 * Creates generic index based search ML url
 * e.g. `jobs/new_job/datavisualizer?index=3da93760-e0af-11ea-9ad3-3bcfc330e42a`
 */ export function formatGenericMlUrl ( appBasePath , page , pageState ) { let url = `${ appBasePath }/${ page }` ; if ( pageState ) { const { globalState , appState , index , savedSearchId , ... restParams } = pageState ; if ( index !== undefined && savedSearchId === undefined ) { url = `${ url }?index=${ index }` ; } if ( index === undefined && savedSearchId !== undefined ) { url = `${ url }?savedSearchId=${ savedSearchId }` ; } if ( ! isEmpty ( restParams ) ) { Object . keys ( restParams ) . forEach ( ( key ) => { url = setStateToKbnUrl ( key , restParams [ key ] , { useHash : false , storeInHashQuery : false } , url ) ; } ) ; } if ( globalState ) { url = setStateToKbnUrl ( '_g' , globalState , { useHash : false , storeInHashQuery : false } , url ) ; } if ( appState ) { url = setStateToKbnUrl ( '_a' , appState , { useHash : false , storeInHashQuery : false } , url ) ; } } return url ; }