-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
437 additions
and
345 deletions.
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
x-pack/plugins/ml/public/ml_url_generator/anomaly_detection_urls_generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import isEmpty from 'lodash/isEmpty'; | ||
import { | ||
AnomalyDetectionQueryState, | ||
AnomalyDetectionUrlState, | ||
ExplorerAppState, | ||
ExplorerGlobalState, | ||
ExplorerUrlState, | ||
MlGenericUrlState, | ||
TimeSeriesExplorerAppState, | ||
TimeSeriesExplorerGlobalState, | ||
TimeSeriesExplorerUrlState, | ||
} from '../../common/types/ml_url_generator'; | ||
import { ML_PAGES } from '../../common/constants/ml_url_generator'; | ||
import { extractParams, createIndexBasedMlUrl } from './common'; | ||
import { setStateToKbnUrl } from '../../../../../src/plugins/kibana_utils/public'; | ||
/** | ||
* Creates URL to the Anomaly Detection Job management page | ||
*/ | ||
export function createAnomalyDetectionJobManagementUrl( | ||
appBasePath: string, | ||
mlUrlGeneratorState: AnomalyDetectionUrlState | ||
): string { | ||
const { params } = extractParams<AnomalyDetectionUrlState>(mlUrlGeneratorState); | ||
let url = `${appBasePath}/${ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE}`; | ||
if (isEmpty(params)) { | ||
return url; | ||
} | ||
const { jobId, groupIds } = params; | ||
const queryState: AnomalyDetectionQueryState = { | ||
jobId, | ||
groupIds, | ||
}; | ||
|
||
url = setStateToKbnUrl<AnomalyDetectionQueryState>( | ||
'mlManagement', | ||
queryState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
return url; | ||
} | ||
|
||
export function createAnomalyDetectionCreatJobSelectType( | ||
appBasePath: string, | ||
mlGenericUrlState: MlGenericUrlState | ||
): string { | ||
return createIndexBasedMlUrl(appBasePath, mlGenericUrlState); | ||
} | ||
|
||
/** | ||
* Creates URL to the Anomaly Explorer page | ||
*/ | ||
export function createExplorerUrl( | ||
appBasePath: string, | ||
{ | ||
refreshInterval, | ||
timeRange, | ||
jobIds, | ||
query, | ||
mlExplorerSwimlane = {}, | ||
mlExplorerFilter = {}, | ||
}: ExplorerUrlState | ||
): string { | ||
let url = `${appBasePath}/${ML_PAGES.ANOMALY_EXPLORER}`; | ||
|
||
const appState: Partial<ExplorerAppState> = { | ||
mlExplorerSwimlane, | ||
mlExplorerFilter, | ||
}; | ||
if (query) appState.query = query; | ||
|
||
if (jobIds) { | ||
const queryState: Partial<ExplorerGlobalState> = { | ||
ml: { | ||
jobIds, | ||
}, | ||
}; | ||
|
||
if (timeRange) queryState.time = timeRange; | ||
if (refreshInterval) queryState.refreshInterval = refreshInterval; | ||
|
||
url = setStateToKbnUrl<Partial<ExplorerGlobalState>>( | ||
'_g', | ||
queryState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
url = setStateToKbnUrl<Partial<ExplorerAppState>>( | ||
'_a', | ||
appState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
} | ||
|
||
return url; | ||
} | ||
|
||
/** | ||
* Creates URL to the SingleMetricViewer page | ||
*/ | ||
export function createSingleMetricViewerUrl( | ||
appBasePath: string, | ||
{ | ||
timeRange, | ||
jobIds, | ||
refreshInterval, | ||
zoom, | ||
query, | ||
detectorIndex, | ||
entities, | ||
}: TimeSeriesExplorerUrlState | ||
): string { | ||
let url = `${appBasePath}/${ML_PAGES.SINGLE_METRIC_VIEWER}`; | ||
const queryState: TimeSeriesExplorerGlobalState = { | ||
ml: { | ||
jobIds, | ||
}, | ||
refreshInterval, | ||
time: timeRange, | ||
}; | ||
|
||
const appState: Partial<TimeSeriesExplorerAppState> = {}; | ||
const mlTimeSeriesExplorer: Partial<TimeSeriesExplorerAppState['mlTimeSeriesExplorer']> = {}; | ||
|
||
if (detectorIndex !== undefined) { | ||
mlTimeSeriesExplorer.detectorIndex = detectorIndex; | ||
} | ||
if (entities !== undefined) { | ||
mlTimeSeriesExplorer.entities = entities; | ||
} | ||
appState.mlTimeSeriesExplorer = mlTimeSeriesExplorer; | ||
|
||
if (zoom) appState.zoom = zoom; | ||
if (query) | ||
appState.query = { | ||
query_string: query, | ||
}; | ||
url = setStateToKbnUrl<TimeSeriesExplorerGlobalState>( | ||
'_g', | ||
queryState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
url = setStateToKbnUrl<TimeSeriesExplorerAppState>( | ||
'_a', | ||
appState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
|
||
return url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import isEmpty from 'lodash/isEmpty'; | ||
import { MlGenericUrlState } from '../../common/types/ml_url_generator'; | ||
import { setStateToKbnUrl } from '../../../../../src/plugins/kibana_utils/public'; | ||
|
||
export function extractParams<UrlState>(urlState: UrlState) { | ||
// page should be guaranteed to exist here but <UrlState> is unknown | ||
// @ts-ignore | ||
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 createIndexBasedMlUrl( | ||
appBasePath: string, | ||
mlGenericUrlState: MlGenericUrlState | ||
): string { | ||
const { globalState, appState, page, index, savedSearchId, ...restParams } = mlGenericUrlState; | ||
let url = `${appBasePath}/${page}`; | ||
|
||
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; | ||
} |
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/ml/public/ml_url_generator/data_visualizer_urls_generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/** | ||
* Creates URL to the Data Visualizer page | ||
*/ | ||
import { DataVisualizerUrlState, MlGenericUrlState } from '../../common/types/ml_url_generator'; | ||
import { createIndexBasedMlUrl } from './common'; | ||
|
||
export function createDataVisualizerUrl( | ||
appBasePath: string, | ||
{ page }: DataVisualizerUrlState | ||
): string { | ||
return `${appBasePath}/${page}`; | ||
} | ||
|
||
/** | ||
* Creates URL to the Index Data Visualizer | ||
*/ | ||
export function createIndexDataVisualizerUrl( | ||
appBasePath: string, | ||
mlGenericUrlState: MlGenericUrlState | ||
): string { | ||
return createIndexBasedMlUrl(appBasePath, mlGenericUrlState); | ||
} |
74 changes: 74 additions & 0 deletions
74
x-pack/plugins/ml/public/ml_url_generator/dataframe_analytics_urls_generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/** | ||
* Creates URL to the DataFrameAnalytics page | ||
*/ | ||
import isEmpty from 'lodash/isEmpty'; | ||
import { | ||
DataFrameAnalyticsExplorationQueryState, | ||
DataFrameAnalyticsExplorationUrlState, | ||
DataFrameAnalyticsQueryState, | ||
DataFrameAnalyticsUrlState, | ||
} from '../../common/types/ml_url_generator'; | ||
import { ML_PAGES } from '../../common/constants/ml_url_generator'; | ||
import { extractParams } from './common'; | ||
import { setStateToKbnUrl } from '../../../../../src/plugins/kibana_utils/public'; | ||
|
||
export function createDataframeAnalyticsUrl( | ||
appBasePath: string, | ||
mlUrlGeneratorState: DataFrameAnalyticsUrlState | ||
): string { | ||
let url = `${appBasePath}/${ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE}`; | ||
const { params } = extractParams<DataFrameAnalyticsUrlState>(mlUrlGeneratorState); | ||
|
||
if (!isEmpty(params)) { | ||
const { jobId, groupIds } = params; | ||
const queryState: Partial<DataFrameAnalyticsQueryState> = { | ||
jobId, | ||
groupIds, | ||
}; | ||
|
||
url = setStateToKbnUrl<Partial<DataFrameAnalyticsQueryState>>( | ||
'mlManagement', | ||
queryState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
} | ||
|
||
return url; | ||
} | ||
|
||
/** | ||
* Creates URL to the DataFrameAnalytics Exploration page | ||
*/ | ||
export function createDataframeAnalyticsExplorationUrl( | ||
appBasePath: string, | ||
mlUrlGeneratorState: DataFrameAnalyticsExplorationUrlState | ||
): string { | ||
let url = `${appBasePath}/${ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION}`; | ||
const { params } = extractParams<DataFrameAnalyticsExplorationUrlState>(mlUrlGeneratorState); | ||
|
||
if (!isEmpty(params)) { | ||
const { jobId, analysisType } = params; | ||
const queryState: DataFrameAnalyticsExplorationQueryState = { | ||
ml: { | ||
jobId, | ||
analysisType, | ||
}, | ||
}; | ||
|
||
url = setStateToKbnUrl<DataFrameAnalyticsExplorationQueryState>( | ||
'_g', | ||
queryState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
} | ||
|
||
return url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
export { MlUrlGenerator, registerUrlGenerator } from './ml_url_generator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.