diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx index e437d27372a3e..b6b335afa53f5 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx @@ -7,29 +7,38 @@ import React, { FC, Fragment } from 'react'; import { EuiCard, EuiHorizontalRule, EuiIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import { useMlKibana } from '../../../../../contexts/kibana'; -function redirectToAnalyticsManagementPage() { - window.location.href = '#/data_frame_analytics?'; -} +export const BackToListPanel: FC = () => { + const { + services: { + application: { navigateToUrl }, + }, + } = useMlKibana(); -export const BackToListPanel: FC = () => ( - - - } - title={i18n.translate('xpack.ml.dataframe.analytics.create.analyticsListCardTitle', { - defaultMessage: 'Data Frame Analytics', - })} - description={i18n.translate( - 'xpack.ml.dataframe.analytics.create.analyticsListCardDescription', - { - defaultMessage: 'Return to the analytics management page.', - } - )} - onClick={redirectToAnalyticsManagementPage} - data-test-subj="analyticsWizardCardManagement" - /> - -); + const redirectToAnalyticsManagementPage = async () => { + await navigateToUrl('#/data_frame_analytics?'); + }; + + return ( + + + } + title={i18n.translate('xpack.ml.dataframe.analytics.create.analyticsListCardTitle', { + defaultMessage: 'Data Frame Analytics', + })} + description={i18n.translate( + 'xpack.ml.dataframe.analytics.create.analyticsListCardDescription', + { + defaultMessage: 'Return to the analytics management page.', + } + )} + onClick={redirectToAnalyticsManagementPage} + data-test-subj="analyticsWizardCardManagement" + /> + + ); +}; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx index e8b1cd1a5696a..df7dce7217fd4 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx @@ -360,7 +360,14 @@ export const CloneAction: FC = ({ createAnalyticsForm, item }) defaultMessage: 'Clone job', }); - const { notifications, savedObjects } = useMlKibana().services; + const { + services: { + application: { navigateToUrl }, + notifications: { toasts }, + savedObjects, + }, + } = useMlKibana(); + const savedObjectsClient = savedObjects.client; const onClick = async () => { @@ -385,7 +392,6 @@ export const CloneAction: FC = ({ createAnalyticsForm, item }) sourceIndexId = ip.id; } } catch (e) { - const { toasts } = notifications; const error = extractErrorMessage(e); toasts.addDanger( @@ -401,9 +407,11 @@ export const CloneAction: FC = ({ createAnalyticsForm, item }) } if (sourceIndexId) { - window.location.href = `ml#/data_frame_analytics/new_job?index=${encodeURIComponent( - sourceIndexId - )}&jobId=${item.config.id}`; + await navigateToUrl( + `ml#/data_frame_analytics/new_job?index=${encodeURIComponent(sourceIndexId)}&jobId=${ + item.config.id + }` + ); } }; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx index d20afe93d2b9d..b03a58a02309d 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx @@ -26,12 +26,20 @@ interface Props { } export const SourceSelection: FC = ({ onClose }) => { - const { uiSettings, savedObjects } = useMlKibana().services; + const { + services: { + application: { navigateToUrl }, + savedObjects, + uiSettings, + }, + } = useMlKibana(); - const onSearchSelected = (id: string, type: string) => { - window.location.href = `ml#/data_frame_analytics/new_job?${ - type === 'index-pattern' ? 'index' : 'savedSearchId' - }=${encodeURIComponent(id)}`; + const onSearchSelected = async (id: string, type: string) => { + await navigateToUrl( + `ml#/data_frame_analytics/new_job?${ + type === 'index-pattern' ? 'index' : 'savedSearchId' + }=${encodeURIComponent(id)}` + ); }; return (