Skip to content

Commit

Permalink
[ML] fix base type
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Sep 2, 2020
1 parent a6cb7da commit 8489ded
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 7 additions & 3 deletions x-pack/plugins/ml/common/types/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import { RefreshInterval, TimeRange } from '../../../../../src/plugins/data/comm
import { JobId } from '../../../reporting/common/types';
import { ML_PAGES } from '../constants/ml_url_generator';

export type MLPageState<PageType, PageState = undefined> = PageState extends undefined
? { page: PageType }
: { page: PageType; pageState: PageState };
type OptionalPageState = object | undefined;

export type MLPageState<PageType, PageState> = PageState extends OptionalPageState
? { page: PageType; pageState?: PageState }
: PageState extends object
? { page: PageType; pageState: PageState }
: { page: PageType };

export const ANALYSIS_CONFIG_TYPE = {
OUTLIER_DETECTION: 'outlier_detection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import isEmpty from 'lodash/isEmpty';
import {
AnomalyDetectionQueryState,
AnomalyDetectionUrlState,
ExplorerAppState,
ExplorerGlobalState,
ExplorerUrlState,
Expand All @@ -23,7 +24,7 @@ import { setStateToKbnUrl } from '../../../../../src/plugins/kibana_utils/public
*/
export function createAnomalyDetectionJobManagementUrl(
appBasePath: string,
params: AnomalyDetectionQueryState | undefined
params: AnomalyDetectionUrlState['pageState']
): string {
let url = `${appBasePath}/${ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE}`;
if (!params || isEmpty(params)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import {
DataFrameAnalyticsExplorationQueryState,
DataFrameAnalyticsExplorationUrlState,
DataFrameAnalyticsQueryState,
DataFrameAnalyticsUrlState,
} from '../../common/types/ml_url_generator';
import { ML_PAGES } from '../../common/constants/ml_url_generator';
import { setStateToKbnUrl } from '../../../../../src/plugins/kibana_utils/public';

export function createDataFrameAnalyticsJobManagementUrl(
appBasePath: string,
mlUrlGeneratorState: DataFrameAnalyticsQueryState | undefined
mlUrlGeneratorState: DataFrameAnalyticsUrlState['pageState']
): string {
let url = `${appBasePath}/${ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE}`;

Expand Down
10 changes: 2 additions & 8 deletions x-pack/plugins/ml/public/ml_url_generator/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export class MlUrlGenerator implements UrlGeneratorsDefinition<typeof ML_APP_URL
const appBasePath = this.params.appBasePath;
switch (mlUrlGeneratorState.page) {
case ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE:
return createAnomalyDetectionJobManagementUrl(
appBasePath,
'pageState' in mlUrlGeneratorState ? mlUrlGeneratorState.pageState : undefined
);
return createAnomalyDetectionJobManagementUrl(appBasePath, mlUrlGeneratorState.pageState);
case ML_PAGES.ANOMALY_EXPLORER:
return createExplorerUrl(appBasePath, mlUrlGeneratorState.pageState);
case ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE:
Expand All @@ -62,10 +59,7 @@ export class MlUrlGenerator implements UrlGeneratorsDefinition<typeof ML_APP_URL
case ML_PAGES.SINGLE_METRIC_VIEWER:
return createSingleMetricViewerUrl(appBasePath, mlUrlGeneratorState.pageState);
case ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE:
return createDataFrameAnalyticsJobManagementUrl(
appBasePath,
'pageState' in mlUrlGeneratorState ? mlUrlGeneratorState.pageState : undefined
);
return createDataFrameAnalyticsJobManagementUrl(appBasePath, mlUrlGeneratorState.pageState);
case ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION:
return createDataFrameAnalyticsExplorationUrl(appBasePath, mlUrlGeneratorState.pageState);
case ML_PAGES.DATA_VISUALIZER:
Expand Down

0 comments on commit 8489ded

Please sign in to comment.