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] Migrate internal urls to non-hash paths #76735

Merged
merged 81 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
5ff3100
[ML] Update internal links
qn895 Sep 2, 2020
df33079
[ML] Update internal links
qn895 Sep 2, 2020
8c3adc1
[ML] Update links to datavisualizer results page
qn895 Sep 2, 2020
0333310
[ML] Update links to datavisualizer results page
qn895 Sep 2, 2020
65de961
[ML] Update links to filter list
qn895 Sep 2, 2020
4ec96fd
[ML] Update browser doc title whenever tab changes
qn895 Sep 3, 2020
49d0e7d
[ML] Update manageCalendarsHref
qn895 Sep 3, 2020
6827517
[ML] Update jobList and data frame list
qn895 Sep 3, 2020
6f86f70
[ML] Remove get_selected_ids_url
qn895 Sep 3, 2020
7f8decf
[ML] Update globalState to appropriate url states & retain only _g st…
qn895 Sep 3, 2020
ce2f3ec
[ML] Update link for register feature
qn895 Sep 3, 2020
6fbb599
[ML] Add i18n to main tabs
qn895 Sep 3, 2020
195929f
[ML] Add link to DFA list, remove commented preserve search, move aro…
qn895 Sep 4, 2020
f175d27
[ML] Update import for const ANALYSIS_CONFIG_TYPE
qn895 Sep 4, 2020
8ffd123
[ML] Revert change to APM
qn895 Sep 4, 2020
a30ec90
[ML] Fix broken Start trial link in data visualizer
qn895 Sep 4, 2020
0e9915b
[ML] Redirect to main job page if _g for global for dfa exploration i…
qn895 Sep 4, 2020
5b8c82e
[ML] Inject basepath to preConfiguredJobRedirect
qn895 Sep 4, 2020
7742303
[ML] Inject basepath to preConfiguredJobRedirect + update mock for Ti…
qn895 Sep 4, 2020
f56525c
[ML] Change to useNavigateToPath instead of href to avoid full page r…
qn895 Sep 4, 2020
25272ca
[ML] Update links within settings
qn895 Sep 4, 2020
adc1047
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 8, 2020
5d0c800
[ML] Fix eslint
qn895 Sep 8, 2020
c62a924
[ML] Change to using `docTitle.change`
qn895 Sep 8, 2020
ac70ed2
[ML] Update RecognizedResult
qn895 Sep 8, 2020
ad88c4e
[ML] Update redirectToTab to only retain refreshInterval + tab name c…
qn895 Sep 8, 2020
fb40acb
[ML] Only retain refresh interval for now
qn895 Sep 8, 2020
738f0b7
[ML] Update onClick to href with react-router Link
qn895 Sep 8, 2020
2d317c1
[ML] Update links for AD View Results, Recognize redirects, DFAnalyti…
qn895 Sep 8, 2020
df40e5f
[ML] Update links for recognize to also honor user's advanced setting…
qn895 Sep 8, 2020
a10374a
[ML] Remove # in fallback
qn895 Sep 8, 2020
4ee28a9
[ML] Replace usage of getResultsUrl
qn895 Sep 8, 2020
0e2ed56
[ML] Update links to group of AD jobs after Add sample data & create …
qn895 Sep 8, 2020
bb8230c
[ML] Update viewResults when AD job wizard finishes
qn895 Sep 8, 2020
7176749
[ML] Navigate to path /jobs as fallback
qn895 Sep 8, 2020
f561cf4
[ML] Preserve refreshInterval state even after navigating to settings…
qn895 Sep 8, 2020
ffa623a
[ML] Add refresh inerval to new job button
qn895 Sep 8, 2020
9272d37
[ML] Update mocks for jest tests
qn895 Sep 8, 2020
dd3517b
[ML] Refactor ANALYSIS_CONFIG_TYPE from enum -> const
qn895 Sep 9, 2020
4a50f1f
[ML] Fix issues with mlFilterListsTable
qn895 Sep 9, 2020
5eda3bf
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 9, 2020
fe633ae
[ML] Update returnToFiltersList
qn895 Sep 9, 2020
6461407
[ML] Add ANOMALY_DETECTION_CREATE_JOB
qn895 Sep 9, 2020
cf3edb7
[ML] Replace checkGetJobsCapabilitiesResolver
qn895 Sep 9, 2020
787bade
[ML] Update calendar & filter lists
qn895 Sep 9, 2020
de7c268
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 9, 2020
d0e20a4
[ML] Update broken DFA imports
qn895 Sep 9, 2020
853d5a3
[ML] Fix unnecessary links in MainTabs & add keys
qn895 Sep 9, 2020
662c756
[ML] Speed up DFA links from overview & extend MlUrlGen with exclude…
qn895 Sep 10, 2020
b530216
[ML] Improve breadcrumbs for settings page, introduce another level
qn895 Sep 10, 2020
a58a477
[ML] Fix broken navigation breadcrumbs
qn895 Sep 10, 2020
b76adb0
[ML] Fix jest tests
qn895 Sep 11, 2020
13abdba
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 11, 2020
dc3ba76
[ML] Update tst subjects, data frame, recently accessed, double elastic
qn895 Sep 14, 2020
40f8845
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 14, 2020
733e9fa
[ML] Fix i18n
qn895 Sep 14, 2020
1fa7026
[ML] Fix mlFilterListsRow
qn895 Sep 14, 2020
68e7519
[ML] Move ML_APP_NAME to constants ML_APP_NAME
qn895 Sep 14, 2020
3439383
[ML] Dima's feedback
qn895 Sep 14, 2020
cea397e
[ML] Misc fixes
qn895 Sep 14, 2020
0c29605
Merge branch 'ml-replace-internal-urls' of https://github.com/qn895/k…
qn895 Sep 14, 2020
e224267
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 14, 2020
f85413f
[ML] Update registerManagementSection, test for explorer_no_jobs_found
qn895 Sep 14, 2020
1efaed2
[ML] Update imports from discover plugins and fix i18n duplicate
qn895 Sep 14, 2020
29d8674
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 15, 2020
d3edff7
[ML] Rename DataFrameAnalyticsType -> DataFrameAnalysisConfigType
qn895 Sep 15, 2020
42313ae
[ML] Update useMlLink
qn895 Sep 15, 2020
f762277
[ML] Change redirectToMlAccessDeniedPage to using deps
qn895 Sep 15, 2020
ba56a81
[ML] Fix recently_accessed not working from non-ml pages
qn895 Sep 15, 2020
0d83eac
[ML] Add message
qn895 Sep 15, 2020
cc8f5dd
[ML] Use getAnalysisType, reorder import Link, rename AdJobLink
qn895 Sep 16, 2020
92dad64
[ML] Update clearSelectedJobIdFromUrl, update forecast tables linking…
qn895 Sep 16, 2020
0a4a559
[ML] Update links inside annotations_table
qn895 Sep 16, 2020
efe49ea
[ML] Update links in ExplorerChartContainerUI
qn895 Sep 16, 2020
abe0ce6
[ML] Rename single metric viewer links
qn895 Sep 16, 2020
b7f9be7
[ML] Update switch link btw SMV and AE
qn895 Sep 16, 2020
5dd7373
[ML] Update tests
qn895 Sep 16, 2020
0a0436b
Merge remote-tracking branch 'upstream/master' into ml-replace-intern…
qn895 Sep 16, 2020
75352f9
[ML] Fix model list linking
qn895 Sep 16, 2020
ee507b4
[ML] Update linking in AE Anomalies table
qn895 Sep 16, 2020
a39face
Merge branch 'master' into ml-replace-internal-urls
elasticmachine Sep 17, 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
11 changes: 11 additions & 0 deletions x-pack/plugins/ml/common/constants/data_frame_analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 ANALYSIS_CONFIG_TYPE = {
OUTLIER_DETECTION: 'outlier_detection',
REGRESSION: 'regression',
CLASSIFICATION: 'classification',
} as const;
Comment on lines +7 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same as an enum already in plugins/ml/public/application/data_frame_analytics/common/analytics.ts. This one using the const approach as well as the location here LGTM so suggest to try to get rid of the on mentioned in this comment.

Copy link
Member Author

@qn895 qn895 Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went through and updated the usage of enum ANALYSIS_CONFIG_TYPE to const ANALYSIS_CONFIG_TYPE here dd3517b

7 changes: 7 additions & 0 deletions x-pack/plugins/ml/common/constants/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ export const ML_PAGES = {
*/
DATA_VISUALIZER_INDEX_VIEWER: 'jobs/new_job/datavisualizer',
ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE: `jobs/new_job/step/job_type`,
ANOMALY_DETECTION_CREATE_JOB_SELECT_INDEX: `jobs/new_job/step/index_or_search`,
SETTINGS: 'settings',
CALENDARS_MANAGE: 'settings/calendars_list',
CALENDARS_NEW: 'settings/calendars_list/new_calendar',
CALENDARS_EDIT: 'settings/calendars_list/edit_calendar',
FILTER_LISTS_MANAGE: 'settings/filter_lists',
FILTER_LISTS_NEW: 'settings/filter_lists/new_filter_list',
FILTER_LISTS_EDIT: 'settings/filter_lists/edit_filter_list',
ACCESS_DENIED: 'access-denied',
OVERVIEW: 'overview',
} as const;
3 changes: 3 additions & 0 deletions x-pack/plugins/ml/common/types/data_frame_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { CustomHttpResponseOptions, ResponseError } from 'kibana/server';
import { ANALYSIS_CONFIG_TYPE } from '../constants/data_frame_analytics';

export interface DeleteDataFrameAnalyticsWithIndexStatus {
success: boolean;
Expand Down Expand Up @@ -79,3 +80,5 @@ export interface DataFrameAnalyticsConfig {
version: string;
allow_lazy_start?: boolean;
}

export type DataFrameAnalyticsType = typeof ANALYSIS_CONFIG_TYPE[keyof typeof ANALYSIS_CONFIG_TYPE];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we use the Type postfix in other places so suggest to just name this DataFrameAnalytics.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed here d3edff7

48 changes: 25 additions & 23 deletions x-pack/plugins/ml/common/types/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import { RefreshInterval, TimeRange } from '../../../../../src/plugins/data/common/query';
import { JobId } from '../../../reporting/common/types';
import { JobId } from './anomaly_detection_jobs/job';
import { ML_PAGES } from '../constants/ml_url_generator';
import { DataFrameAnalyticsType } from './data_frame_analytics';

type OptionalPageState = object | undefined;

Expand All @@ -16,16 +17,9 @@ export type MLPageState<PageType, PageState> = PageState extends OptionalPageSta
? { page: PageType; pageState: PageState }
: { page: PageType };

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

type DataFrameAnalyticsType = typeof ANALYSIS_CONFIG_TYPE[keyof typeof ANALYSIS_CONFIG_TYPE];

export interface MlCommonGlobalState {
time?: TimeRange;
refreshInterval?: RefreshInterval;
}
export interface MlCommonAppState {
[key: string]: any;
Expand All @@ -42,16 +36,29 @@ export interface MlGenericUrlPageState extends MlIndexBasedSearchState {
[key: string]: any;
}

export interface MlGenericUrlState {
page:
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_VIEWER
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE;
pageState: MlGenericUrlPageState;
}
export type MlGenericUrlState = MLPageState<
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_VIEWER
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_INDEX
| typeof ML_PAGES.OVERVIEW
| typeof ML_PAGES.CALENDARS_MANAGE
| typeof ML_PAGES.CALENDARS_EDIT
| typeof ML_PAGES.CALENDARS_NEW
| typeof ML_PAGES.FILTER_LISTS_MANAGE
| typeof ML_PAGES.FILTER_LISTS_EDIT
| typeof ML_PAGES.FILTER_LISTS_NEW
| typeof ML_PAGES.SETTINGS
| typeof ML_PAGES.ACCESS_DENIED
| typeof ML_PAGES.DATA_VISUALIZER
| typeof ML_PAGES.DATA_VISUALIZER_FILE
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_SELECT,
MlGenericUrlPageState | undefined
>;

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

export type AnomalyDetectionUrlState = MLPageState<
Expand Down Expand Up @@ -145,24 +152,19 @@ export type TimeSeriesExplorerUrlState = MLPageState<
export interface DataFrameAnalyticsQueryState {
jobId?: JobId | JobId[];
groupIds?: string[];
globalState?: MlCommonGlobalState;
}

export type DataFrameAnalyticsUrlState = MLPageState<
typeof ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE,
DataFrameAnalyticsQueryState | undefined
>;

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: DataFrameAnalyticsType;
globalState?: MlCommonGlobalState;
};
}

Expand All @@ -171,6 +173,7 @@ export type DataFrameAnalyticsExplorationUrlState = MLPageState<
{
jobId: JobId;
analysisType: DataFrameAnalyticsType;
globalState?: MlCommonGlobalState;
}
>;

Expand All @@ -183,5 +186,4 @@ export type MlUrlGeneratorState =
| TimeSeriesExplorerUrlState
| DataFrameAnalyticsUrlState
| DataFrameAnalyticsExplorationUrlState
| DataVisualizerUrlState
| MlGenericUrlState;
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC, useState } from 'react';
import { encode } from 'rison-node';
import React, { FC, useState, useEffect } from 'react';

import { EuiTabs, EuiTab, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { useUrlState } from '../../util/url_state';

import { TabId } from './navigation_menu';
import { useMlUrlGenerator, useNavigateToPath } from '../../contexts/kibana';
import { MlUrlGeneratorState } from '../../../../common/types/ml_url_generator';
import { useUrlState } from '../../util/url_state';

export interface Tab {
id: TabId;
Expand Down Expand Up @@ -66,17 +65,49 @@ function getTabs(disableLinks: boolean): Tab[] {
}
interface TabData {
testSubject: string;
pathId?: string;
pathId?: MlUrlGeneratorState['page'];
name: string;
}

const TAB_DATA: Record<TabId, TabData> = {
overview: { testSubject: 'mlMainTab overview' },
overview: {
testSubject: 'mlMainTab overview',
name: i18n.translate('xpack.ml.overviewTabLabel', {
defaultMessage: 'Overview',
}),
},
// Note that anomaly detection jobs list is mapped to ml#/jobs.
anomaly_detection: { testSubject: 'mlMainTab anomalyDetection', pathId: 'jobs' },
data_frame_analytics: { testSubject: 'mlMainTab dataFrameAnalytics' },
datavisualizer: { testSubject: 'mlMainTab dataVisualizer' },
settings: { testSubject: 'mlMainTab settings' },
'access-denied': { testSubject: 'mlMainTab overview' },
anomaly_detection: {
testSubject: 'mlMainTab anomalyDetection',
name: i18n.translate('xpack.ml.anomalyDetectionTabLabel', {
defaultMessage: 'Anomaly Detection',
}),
pathId: 'jobs',
},
data_frame_analytics: {
testSubject: 'mlMainTab dataFrameAnalytics',
name: i18n.translate('xpack.ml.dataFrameAnalyticsTabLabel', {
defaultMessage: 'Data Frame Analytics',
}),
},
datavisualizer: {
testSubject: 'mlMainTab dataVisualizer',
name: i18n.translate('xpack.ml.dataVisualizerTabLabel', {
defaultMessage: 'Data Visualizer',
}),
},
settings: {
testSubject: 'mlMainTab settings',
name: i18n.translate('xpack.ml.settingsTabLabel', {
defaultMessage: 'Settings',
}),
},
'access-denied': {
testSubject: 'mlMainTab overview',
name: i18n.translate('xpack.ml.accessDeniedTabLabel', {
defaultMessage: 'Access Denied',
}),
},
};

export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
Expand All @@ -87,16 +118,32 @@ export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
}

const tabs = getTabs(disableLinks);
const mlUrlGenerator = useMlUrlGenerator();
const navigateToPath = useNavigateToPath();

const redirectToTab = async (defaultPathId: MlUrlGeneratorState['page']) => {
// TODO: fix ts
// @ts-ignore
qn895 marked this conversation as resolved.
Show resolved Hide resolved
const path = await mlUrlGenerator.createUrl({
page: defaultPathId,
pageState: { globalState },
});

await navigateToPath(path, false);
};

useEffect(() => {
document.title = `ML - ${TAB_DATA[selectedTabId].name} - Kibana`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if Kibana offers a way to do this more "officially" without directly manipulating document.title?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point! I do see coreStart.docTitle.change('My Title') that the Kibana team has exposed out ... Gonna take a look to see if we an implement this using that instead 👍

Copy link
Member Author

@qn895 qn895 Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to using Kibana's chrome.docTitle.change() here c62a924

}, [selectedTabId]);

return (
<EuiTabs display="condensed">
{tabs.map((tab: Tab) => {
const { id, disabled } = tab;
const testSubject = TAB_DATA[id].testSubject;
const defaultPathId = TAB_DATA[id].pathId || id;
const defaultPathId = (TAB_DATA[id].pathId || id) as MlUrlGeneratorState['page'];
// globalState (e.g. selected jobs and time range) should be retained when changing pages.
// appState will not be considered.
const fullGlobalStateString = globalState !== undefined ? `?_g=${encode(globalState)}` : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the global state no longer necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still retaining the globalState here, just within redirectToTab instead of the encoded string.


return disabled ? (
<EuiTab key={`${id}-key`} className={'mlNavigationMenu__mainTab'} disabled={true}>
Expand All @@ -106,7 +153,7 @@ export const MainTabs: FC<Props> = ({ tabId, disableLinks }) => {
<div className="euiTab" key={`div-${id}-key`}>
<EuiLink
data-test-subj={testSubject + (id === selectedTabId ? ' selected' : '')}
href={`#/${defaultPathId}${fullGlobalStateString}`}
onClick={() => redirectToTab(defaultPathId)}
key={`${id}-key`}
color="text"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ import { ScopeExpression } from './scope_expression';
import { checkPermission } from '../../capabilities/check_capabilities';
import { getScopeFieldDefaults } from './utils';
import { FormattedMessage } from '@kbn/i18n/react';
import { ML_PAGES } from '../../../../common/constants/ml_url_generator';
import { useMlUrlGenerator, useNavigateToPath } from '../../contexts/kibana';

function NoFilterListsCallOut() {
const mlUrlGenerator = useMlUrlGenerator();
const navigateToPath = useNavigateToPath();
const redirectToFilterManagementPage = async () => {
const path = await mlUrlGenerator.createUrl({
page: ML_PAGES.FILTER_LISTS_MANAGE,
qn895 marked this conversation as resolved.
Show resolved Hide resolved
});
await navigateToPath(path, true);
};

return (
<EuiCallOut
title={
Expand All @@ -36,7 +47,7 @@ function NoFilterListsCallOut() {
to create the list of values you want to include or exclude in the rule."
values={{
filterListsLink: (
<EuiLink href="#/settings/filter_lists">
<EuiLink onClick={redirectToFilterManagementPage}>
<FormattedMessage
id="xpack.ml.ruleEditor.scopeSection.createFilterListsDescription.filterListsLinkText"
defaultMessage="Filter Lists"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +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';
export { useMlUrlGenerator, useMlLink } from './use_create_url';
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useCallback, useEffect, useState } from 'react';
import { useMlKibana } from './kibana_context';
import { ML_APP_URL_GENERATOR } from '../../../../common/constants/ml_url_generator';
import { MlUrlGeneratorState } from '../../../../common/types/ml_url_generator';

export const useMlUrlGenerator = () => {
const {
Expand All @@ -18,3 +20,37 @@ export const useMlUrlGenerator = () => {

return getUrlGenerator(ML_APP_URL_GENERATOR);
};

export const useMlLink = (params: MlUrlGeneratorState): string | undefined => {
const [href, setHref] = useState<string | undefined>(undefined);
const mlUrlGenerator = useMlUrlGenerator();

const generateUrl = useCallback(async () => {
const url = await mlUrlGenerator.createUrl(params);
setHref(url);
}, []);
useEffect(() => {
generateUrl();
darnautov marked this conversation as resolved.
Show resolved Hide resolved
}, [params]);

return href;
};

export const useCreateAndNavigateToMlLink = (
page: MlUrlGeneratorState['page']
): (() => Promise<void>) => {
const mlUrlGenerator = useMlUrlGenerator();
const {
services: {
application: { navigateToUrl },
},
} = useMlKibana();

const redirectToMlPage = async (_page: MlUrlGeneratorState['page']) => {
const url = await mlUrlGenerator.createUrl({ page: _page });
await navigateToUrl(url);
};

// returns the onClick callback
return useCallback(() => redirectToMlPage(page), [mlUrlGenerator]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@
import React, { useCallback, useMemo } from 'react';

import { getAnalysisType } from '../../../../common/analytics';
import { useNavigateToPath } from '../../../../../contexts/kibana';
import { useMlUrlGenerator, useNavigateToPath } from '../../../../../contexts/kibana';

import {
getResultsUrl,
DataFrameAnalyticsListAction,
DataFrameAnalyticsListRow,
} from '../analytics_list/common';
import { DataFrameAnalyticsListAction, DataFrameAnalyticsListRow } from '../analytics_list/common';

import { getViewLinkStatus } from './get_view_link_status';
import { viewActionButtonText, ViewButton } from './view_button';
import { DataFrameAnalyticsType } from '../../../../../../../common/types/data_frame_analytics';
import { ML_PAGES } from '../../../../../../../common/constants/ml_url_generator';

export type ViewAction = ReturnType<typeof useViewAction>;
export const useViewAction = () => {
const mlUrlGenerator = useMlUrlGenerator();
const navigateToPath = useNavigateToPath();

const redirectToTab = async (jobId: string, analysisType: DataFrameAnalyticsType) => {
const path = await mlUrlGenerator.createUrl({
page: ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION,
pageState: { jobId, analysisType },
});

await navigateToPath(path, false);
};

const clickHandler = useCallback((item: DataFrameAnalyticsListRow) => {
const analysisType = getAnalysisType(item.config.analysis);
navigateToPath(getResultsUrl(item.id, analysisType));
const analysisType = getAnalysisType(item.config.analysis) as DataFrameAnalyticsType;
redirectToTab(item.id, analysisType);
}, []);

const action: DataFrameAnalyticsListAction = useMemo(
Expand Down
Loading