Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Extend MlUrlGenerator to support other ML pages #75696

Merged
merged 35 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5efa8cd
[ML] Extend MlUrlGenerator to support other pages
qn895 Aug 13, 2020
9faedfd
[ML] Change destructuring & index based ml generator
qn895 Aug 21, 2020
7d8aba8
[ML] Make createIndexBasedMlUrl check more explicit
qn895 Aug 21, 2020
40cc3c5
[ML] Remove commented code
qn895 Aug 21, 2020
c1f8cde
[ML] Update type for TimeRange
qn895 Aug 21, 2020
98dd2e5
[ML] Update redirect for dfa wizard to use constants
qn895 Aug 21, 2020
0e4ddd6
Merge remote-tracking branch 'upstream/master' into ml-url-generator-…
qn895 Aug 21, 2020
7c9318e
[ML] Rename ML_TABS to ML_PAGES
qn895 Aug 24, 2020
aa9398d
Merge remote-tracking branch 'upstream/master' into new-ml-url-generator
qn895 Aug 24, 2020
7360f32
[ML] Update core API docs
qn895 Aug 24, 2020
7ce5a5b
[ML] Fix perPartitionStopOnWarn typo
qn895 Aug 24, 2020
9e93c9d
Merge remote-tracking branch 'upstream/master' into new-ml-url-generator
qn895 Aug 25, 2020
8179168
[ML] Update redirect func name & fix for url with base path
qn895 Aug 25, 2020
c552644
[ML] Change ml url state types to its own
qn895 Aug 25, 2020
d8c5716
[ML] Change timeseriesexplorer to SINGLE_METRIC_VIEWER
qn895 Aug 25, 2020
3a1a7cb
[ML] Rename/update descriptions
qn895 Aug 25, 2020
ff528e5
[ML] Update calendar and filter manage
qn895 Aug 25, 2020
60d6799
[ML] Rename ANOMALY_DETECTION -> ANOMALY_DETECTION_JOBS_MANAGE
qn895 Aug 25, 2020
18b9093
[ML] Rename DATA_FRAME_ANALYTICS -> DATA_FRAME_ANALYTICS_JOBS_MANAGE
qn895 Aug 25, 2020
b7f1920
[ML] Update imports after moving
qn895 Aug 25, 2020
b7cd7fd
[ML] Update import from file instead of from context
qn895 Aug 25, 2020
49e56ed
[ML] Have dedicated functions for createIndexDataVisualizerUrl and cr…
qn895 Aug 25, 2020
64b936b
[ML] Remove hash based path in initSampleDataSets
qn895 Aug 25, 2020
689f0f6
Merge remote-tracking branch 'upstream/master' into new-ml-url-generator
qn895 Aug 27, 2020
4d6a5a0
[ML] Refactor to own folder
qn895 Aug 31, 2020
3751f4a
Merge remote-tracking branch 'upstream/master' into new-ml-url-generator
qn895 Aug 31, 2020
5eefb05
[ML] Revert changes to data/common/types
qn895 Aug 31, 2020
a1e9118
[ML] Fix createAnomalyDetectionCreateJobSelectType name and update ap…
qn895 Sep 1, 2020
2abee97
[ML] Change shape to use `page` and `pageState`
qn895 Sep 1, 2020
8148a6c
[ML] Remove commented block code
qn895 Sep 1, 2020
9962c25
[ML] Rename dataframe -> data frame, update types for MLPagestype
qn895 Sep 2, 2020
8248d7f
[ML] Rename DataFrameAnalyticsType
qn895 Sep 2, 2020
67214cd
Merge remote-tracking branch 'upstream/master' into new-ml-url-generator
qn895 Sep 2, 2020
a6cb7da
[ML] Update typings
qn895 Sep 2, 2020
8489ded
[ML] fix base type
darnautov Sep 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface RefreshInterval

| Property | Type | Description |
| --- | --- | --- |
| [display](./kibana-plugin-plugins-data-public.refreshinterval.display.md) | <code>string</code> | |
| [pause](./kibana-plugin-plugins-data-public.refreshinterval.pause.md) | <code>boolean</code> | |
| [value](./kibana-plugin-plugins-data-public.refreshinterval.value.md) | <code>number</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export interface TimeRange
| Property | Type | Description |
| --- | --- | --- |
| [from](./kibana-plugin-plugins-data-public.timerange.from.md) | <code>string</code> | |
| [mode](./kibana-plugin-plugins-data-public.timerange.mode.md) | <code>'absolute' &#124; 'relative'</code> | |
| [mode](./kibana-plugin-plugins-data-public.timerange.mode.md) | <code>'absolute' &#124; 'relative' &#124; 'quick'</code> | |
| [to](./kibana-plugin-plugins-data-public.timerange.to.md) | <code>string</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
mode?: 'absolute' | 'relative';
mode?: 'absolute' | 'relative' | 'quick';
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface RefreshInterval

| Property | Type | Description |
| --- | --- | --- |
| [display](./kibana-plugin-plugins-data-server.refreshinterval.display.md) | <code>string</code> | |
| [pause](./kibana-plugin-plugins-data-server.refreshinterval.pause.md) | <code>boolean</code> | |
| [value](./kibana-plugin-plugins-data-server.refreshinterval.value.md) | <code>number</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export interface TimeRange
| Property | Type | Description |
| --- | --- | --- |
| [from](./kibana-plugin-plugins-data-server.timerange.from.md) | <code>string</code> | |
| [mode](./kibana-plugin-plugins-data-server.timerange.mode.md) | <code>'absolute' &#124; 'relative'</code> | |
| [mode](./kibana-plugin-plugins-data-server.timerange.mode.md) | <code>'absolute' &#124; 'relative' &#124; 'quick'</code> | |
| [to](./kibana-plugin-plugins-data-server.timerange.to.md) | <code>string</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
mode?: 'absolute' | 'relative';
mode?: 'absolute' | 'relative' | 'quick';
```
4 changes: 3 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,8 @@ export interface RangeFilterParams {
//
// @public (undocumented)
export interface RefreshInterval {
// (undocumented)
display?: string;
// (undocumented)
pause: boolean;
// (undocumented)
Expand Down Expand Up @@ -1924,7 +1926,7 @@ export interface TimeRange {
// (undocumented)
from: string;
// (undocumented)
mode?: 'absolute' | 'relative';
mode?: 'absolute' | 'relative' | 'quick';
// (undocumented)
to: string;
}
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,8 @@ export interface Query {
//
// @public (undocumented)
export interface RefreshInterval {
// (undocumented)
display?: string;
// (undocumented)
pause: boolean;
// (undocumented)
Expand Down Expand Up @@ -1016,7 +1018,7 @@ export interface TimeRange {
// (undocumented)
from: string;
// (undocumented)
mode?: 'absolute' | 'relative';
mode?: 'absolute' | 'relative' | 'quick';
// (undocumented)
to: string;
}
Expand Down
42 changes: 42 additions & 0 deletions x-pack/plugins/ml/common/constants/ml_url_generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 const ML_APP_URL_GENERATOR = 'ML_APP_URL_GENERATOR';

export const ML_PAGES = {
ANOMALY_DETECTION_JOBS_MANAGE: 'jobs',
ANOMALY_EXPLORER: 'explorer',
SINGLE_METRIC_VIEWER: 'timeseriesexplorer',
DATA_FRAME_ANALYTICS_JOBS_MANAGE: 'data_frame_analytics',
DATA_FRAME_ANALYTICS_EXPLORATION: 'data_frame_analytics/exploration',
/**
* Page: Data Visualizer
*/
DATA_VISUALIZER: 'datavisualizer',
/**
* Page: Data Visualizer
* Open data visualizer by selecting a Kibana index pattern or saved search
*/
DATA_VISUALIZER_INDEX_SELECT: 'datavisualizer_index_select',
/**
* Page: Data Visualizer
* Open data visualizer by importing data from a log file
*/
DATA_VISUALIZER_FILE: 'filedatavisualizer',
/**
* Page: Data Visualizer
* Open index data visualizer viewer page
*/
get DATA_VISUALIZER_INDEX_VIEWER() {
return `jobs/new_job/${this.DATA_VISUALIZER}`;
},
get ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE() {
return `jobs/new_job/step/job_type`;
},
SETTINGS: 'settings',
CALENDARS_MANAGE: 'settings/calendars_list',
FILTER_LISTS_MANAGE: 'settings/filter_lists',
} as const;
173 changes: 173 additions & 0 deletions x-pack/plugins/ml/common/types/ml_url_generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* 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 { RefreshInterval, TimeRange } from '../../../../../src/plugins/data/common/query';
import { JobId } from '../../../reporting/common/types';
import { ML_PAGES } from '../constants/ml_url_generator';

export const ANALYSIS_CONFIG_TYPE = {
OUTLIER_DETECTION: 'outlier_detection',
REGRESSION: 'regression',
CLASSIFICATION: 'classification',
} as const;

export interface MlCommonGlobalState {
time?: TimeRange;
}
export interface MlCommonAppState {
[key: string]: any;
}

export interface MlIndexBasedSearchState {
index?: string;
savedSearchId?: string;
}

export interface MlGenericUrlState extends MlIndexBasedSearchState {
page:
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_VIEWER
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE;
globalState?: MlCommonGlobalState;
appState?: MlCommonAppState;
[key: string]: any;
}

export interface AnomalyDetectionQueryState {
jobId?: JobId;
groupIds?: string[];
}

export interface AnomalyDetectionUrlState {
page: typeof ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE;
jobId?: JobId;
groupIds?: string[];
}

export interface ExplorerAppState {
mlExplorerSwimlane: {
selectedType?: string;
selectedLanes?: string[];
selectedTimes?: number[];
showTopFieldValues?: boolean;
viewByFieldName?: string;
viewByPerPage?: number;
viewByFromPage?: number;
};
mlExplorerFilter: {
influencersFilterQuery?: unknown;
filterActive?: boolean;
filteredFields?: string[];
queryString?: string;
};
query?: any;
}
export interface ExplorerGlobalState {
ml: { jobIds: JobId[] };
time?: TimeRange;
refreshInterval?: RefreshInterval;
}

export interface ExplorerUrlState {
/**
* ML App Page
*/
page: typeof ML_PAGES.ANOMALY_EXPLORER;
/**
* Job IDs
*/
jobIds: JobId[];
/**
* Optionally set the time range in the time picker.
*/
timeRange?: TimeRange;
/**
* Optionally set the refresh interval.
*/
refreshInterval?: RefreshInterval;
/**
* Optionally set the query.
*/
query?: any;
/**
* Optional state for the swim lane
*/
mlExplorerSwimlane?: ExplorerAppState['mlExplorerSwimlane'];
mlExplorerFilter?: ExplorerAppState['mlExplorerFilter'];
}

export interface TimeSeriesExplorerGlobalState {
ml: {
jobIds: JobId[];
};
time?: TimeRange;
refreshInterval?: RefreshInterval;
}

export interface TimeSeriesExplorerAppState {
zoom?: {
from?: string;
to?: string;
};
mlTimeSeriesExplorer?: {
detectorIndex?: number;
entities?: Record<string, string>;
};
query?: any;
}

export interface TimeSeriesExplorerUrlState
extends Pick<TimeSeriesExplorerAppState, 'zoom' | 'query'>,
Pick<TimeSeriesExplorerGlobalState, 'refreshInterval'> {
/**
* ML App Page
*/
page: typeof ML_PAGES.SINGLE_METRIC_VIEWER;
jobIds: JobId[];
timeRange?: TimeRange;
detectorIndex?: number;
entities?: Record<string, string>;
}

export interface DataFrameAnalyticsQueryState {
jobId?: JobId | JobId[];
groupIds?: string[];
}

export interface DataFrameAnalyticsUrlState extends DataFrameAnalyticsQueryState {
page: typeof ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE;
}

export interface DataVisualizerUrlState {
page:
| typeof ML_PAGES.DATA_VISUALIZER
| typeof ML_PAGES.DATA_VISUALIZER_FILE
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_SELECT;
}

export interface DataFrameAnalyticsExplorationQueryState {
ml: {
jobId: JobId;
analysisType: typeof ANALYSIS_CONFIG_TYPE;
};
}

export interface DataFrameAnalyticsExplorationUrlState {
page: typeof ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION;
jobId: JobId;
analysisType: typeof ANALYSIS_CONFIG_TYPE;
}

/**
* Union type of ML URL state based on page
*/
export type MlUrlGeneratorState =
| AnomalyDetectionUrlState
| ExplorerUrlState
| TimeSeriesExplorerUrlState
| DataFrameAnalyticsUrlState
| DataFrameAnalyticsExplorationUrlState
| DataVisualizerUrlState
| MlGenericUrlState;
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { useNavigateToPath, NavigateToPath } from './use_navigate_to_path';
export { useUiSettings } from './use_ui_settings_context';
export { useTimefilter } from './use_timefilter';
export { useNotifications } from './use_notifications_context';
export { useMlUrlGenerator } from './use_create_url';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { useMlKibana } from './kibana_context';
import { ML_APP_URL_GENERATOR } from '../../../../common/constants/ml_url_generator';

export const useMlUrlGenerator = () => {
const {
services: {
share: {
urlGenerators: { getUrlGenerator },
},
},
} = useMlKibana();

return getUrlGenerator(ML_APP_URL_GENERATOR);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ export const useNavigateToPath = () => {

const location = useLocation();

return useMemo(
() => (path: string | undefined, preserveSearch = false) => {
navigateToUrl(
getUrlForApp(PLUGIN_ID, {
path: `${path}${preserveSearch === true ? location.search : ''}`,
})
);
},
[location]
);
return useMemo(() => {
return (path: string | undefined, preserveSearch = false) => {
if (path === undefined) return;
const modifiedPath = `${path}${preserveSearch === true ? location.search : ''}`;
/**
* Handle urls generated by MlUrlGenerator where '/app/ml' is automatically prepended
*/
const url = modifiedPath.includes('/app/ml')
? modifiedPath
: getUrlForApp(PLUGIN_ID, {
path: modifiedPath,
});
navigateToUrl(url);
};
}, [location]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
import React, { FC, Fragment } from 'react';
import { EuiCard, EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useNavigateToPath } from '../../../../../contexts/kibana';
import { useMlKibana, useMlUrlGenerator } from '../../../../../contexts/kibana';
import { ML_PAGES } from '../../../../../../../common/constants/ml_url_generator';

export const BackToListPanel: FC = () => {
const navigateToPath = useNavigateToPath();
const urlGenerator = useMlUrlGenerator();
const {
services: {
application: { navigateToUrl },
},
} = useMlKibana();

const redirectToAnalyticsManagementPage = async () => {
await navigateToPath('/data_frame_analytics');
const url = await urlGenerator.createUrl({ page: ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE });
await navigateToUrl(url);
};

return (
Expand Down
Loading