Skip to content

Commit

Permalink
use navigateToUrl instead of window location (#69167)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 authored Jun 16, 2020
1 parent 9f7620b commit efbb4cc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
<Fragment>
<EuiHorizontalRule />
<EuiCard
// @ts-ignore
style={{ width: '300px' }}
icon={<EuiIcon size="xxl" type="list" />}
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"
/>
</Fragment>
);
const redirectToAnalyticsManagementPage = async () => {
await navigateToUrl('#/data_frame_analytics?');
};

return (
<Fragment>
<EuiHorizontalRule />
<EuiCard
// @ts-ignore
style={{ width: '300px' }}
icon={<EuiIcon size="xxl" type="list" />}
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"
/>
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,14 @@ export const CloneAction: FC<CloneActionProps> = ({ 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 () => {
Expand All @@ -385,7 +392,6 @@ export const CloneAction: FC<CloneActionProps> = ({ createAnalyticsForm, item })
sourceIndexId = ip.id;
}
} catch (e) {
const { toasts } = notifications;
const error = extractErrorMessage(e);

toasts.addDanger(
Expand All @@ -401,9 +407,11 @@ export const CloneAction: FC<CloneActionProps> = ({ 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
}`
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ interface Props {
}

export const SourceSelection: FC<Props> = ({ 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 (
Expand Down

0 comments on commit efbb4cc

Please sign in to comment.