-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ML] Fix regression with some links not opening in new tab #80785
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
Changes from 9 commits
65e86d4
257835a
b8052fe
36cc49a
9e68a05
66e775a
b5418b6
0064254
ac8ffcc
df14a3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,15 +4,15 @@ | |
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { FC, useState, useEffect, useCallback } from 'react'; | ||
| import React, { FC, useState, useEffect } from 'react'; | ||
| import moment from 'moment'; | ||
| import { FormattedMessage } from '@kbn/i18n/react'; | ||
| import { EuiFlexGroup, EuiFlexItem, EuiCard, EuiIcon } from '@elastic/eui'; | ||
| import { ml } from '../../../../services/ml_api_service'; | ||
| import { isFullLicense } from '../../../../license'; | ||
| import { checkPermission } from '../../../../capabilities/check_capabilities'; | ||
| import { mlNodesAvailable } from '../../../../ml_nodes_check/check_ml_nodes'; | ||
| import { useMlKibana, useMlUrlGenerator, useNavigateToPath } from '../../../../contexts/kibana'; | ||
| import { useMlKibana, useMlUrlGenerator } from '../../../../contexts/kibana'; | ||
| import { ML_PAGES } from '../../../../../../common/constants/ml_url_generator'; | ||
| import { MlCommonGlobalState } from '../../../../../../common/types/ml_url_generator'; | ||
| import { | ||
|
|
@@ -45,12 +45,16 @@ export const ResultsLinks: FC<Props> = ({ | |
| const [globalState, setGlobalState] = useState<MlCommonGlobalState | undefined>(); | ||
|
|
||
| const [discoverLink, setDiscoverLink] = useState(''); | ||
| const [indexManagementLink, setIndexManagementLink] = useState(''); | ||
| const [indexPatternManagementLink, setIndexPatternManagementLink] = useState(''); | ||
| const [dataVisualizerLink, setDataVisualizerLink] = useState(''); | ||
| const [createJobsSelectTypePage, setCreateJobsSelectTypePage] = useState(''); | ||
|
|
||
| const mlUrlGenerator = useMlUrlGenerator(); | ||
| const navigateToPath = useNavigateToPath(); | ||
|
|
||
| const { | ||
| services: { | ||
| application: { navigateToApp, navigateToUrl }, | ||
| application: { getUrlForApp }, | ||
| share: { | ||
| urlGenerators: { getUrlGenerator }, | ||
| }, | ||
|
|
@@ -84,35 +88,52 @@ export const ResultsLinks: FC<Props> = ({ | |
| setDiscoverLink(discoverUrl); | ||
| } | ||
| }; | ||
|
|
||
| const getDataVisualizerLink = async (): Promise<void> => { | ||
| const _dataVisualizerLink = await mlUrlGenerator.createUrl({ | ||
| page: ML_PAGES.DATA_VISUALIZER_INDEX_VIEWER, | ||
| pageState: { | ||
| index: indexPatternId, | ||
| globalState, | ||
| }, | ||
| }); | ||
| if (!unmounted) { | ||
| setDataVisualizerLink(_dataVisualizerLink); | ||
| } | ||
| }; | ||
| const getADCreateJobsSelectTypePage = async (): Promise<void> => { | ||
| const _createJobsSelectTypePage = await mlUrlGenerator.createUrl({ | ||
| page: ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE, | ||
| pageState: { | ||
| index: indexPatternId, | ||
| globalState, | ||
| }, | ||
| }); | ||
| if (!unmounted) { | ||
| setCreateJobsSelectTypePage(_createJobsSelectTypePage); | ||
| } | ||
| }; | ||
|
|
||
| getDiscoverUrl(); | ||
| getDataVisualizerLink(); | ||
| getADCreateJobsSelectTypePage(); | ||
|
|
||
| if (!unmounted) { | ||
| setIndexManagementLink( | ||
| getUrlForApp('management', { path: '/data/index_management/indices' }) | ||
| ); | ||
| setIndexPatternManagementLink( | ||
| getUrlForApp('management', { | ||
| path: `/kibana/indexPatterns${createIndexPattern ? `/patterns/${indexPatternId}` : ''}`, | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| return () => { | ||
| unmounted = true; | ||
| }; | ||
| }, [indexPatternId, getUrlGenerator]); | ||
|
|
||
| const openInDataVisualizer = useCallback(async () => { | ||
| const path = await mlUrlGenerator.createUrl({ | ||
| page: ML_PAGES.DATA_VISUALIZER_INDEX_VIEWER, | ||
| pageState: { | ||
| index: indexPatternId, | ||
| globalState, | ||
| }, | ||
| }); | ||
| await navigateToPath(path); | ||
| }, [indexPatternId, globalState]); | ||
|
|
||
| const redirectToADCreateJobsSelectTypePage = useCallback(async () => { | ||
| const path = await mlUrlGenerator.createUrl({ | ||
| page: ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE, | ||
| pageState: { | ||
| index: indexPatternId, | ||
| globalState, | ||
| }, | ||
| }); | ||
| await navigateToPath(path); | ||
| }, [indexPatternId, globalState]); | ||
|
|
||
| useEffect(() => { | ||
| setShowCreateJobLink(checkPermission('canCreateJob') && mlNodesAvailable()); | ||
| updateTimeValues(); | ||
|
|
@@ -148,23 +169,6 @@ export const ResultsLinks: FC<Props> = ({ | |
| } | ||
| } | ||
|
|
||
| function openInDiscover(e: React.MouseEvent<HTMLButtonElement>) { | ||
| e.preventDefault(); | ||
| navigateToUrl(discoverLink); | ||
| } | ||
|
|
||
| function openIndexManagement(e: React.MouseEvent<HTMLButtonElement>) { | ||
| e.preventDefault(); | ||
| navigateToApp('management', { path: '/data/index_management/indices' }); | ||
| } | ||
|
|
||
| function openIndexPatternManagement(e: React.MouseEvent<HTMLButtonElement>) { | ||
| e.preventDefault(); | ||
| navigateToApp('management', { | ||
| path: `/kibana/indexPatterns${createIndexPattern ? `/patterns/${indexPatternId}` : ''}`, | ||
| }); | ||
| } | ||
|
|
||
| return ( | ||
| <EuiFlexGroup gutterSize="l"> | ||
| {createIndexPattern && discoverLink && ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you need to add a check for all the other links as well?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated here 0064254 |
||
|
|
@@ -178,15 +182,16 @@ export const ResultsLinks: FC<Props> = ({ | |
| /> | ||
| } | ||
| description="" | ||
| onClick={openInDiscover} | ||
| href={discoverLink} | ||
| /> | ||
| </EuiFlexItem> | ||
| )} | ||
|
|
||
| {isFullLicense() === true && | ||
| timeFieldName !== undefined && | ||
| showCreateJobLink && | ||
| createIndexPattern && ( | ||
| createIndexPattern && | ||
| createJobsSelectTypePage && ( | ||
| <EuiFlexItem> | ||
| <EuiCard | ||
| icon={<EuiIcon size="xxl" type={`machineLearningApp`} />} | ||
|
|
@@ -197,12 +202,12 @@ export const ResultsLinks: FC<Props> = ({ | |
| /> | ||
| } | ||
| description="" | ||
| onClick={redirectToADCreateJobsSelectTypePage} | ||
| href={createJobsSelectTypePage} | ||
| /> | ||
| </EuiFlexItem> | ||
| )} | ||
|
|
||
| {createIndexPattern && ( | ||
| {createIndexPattern && dataVisualizerLink && ( | ||
| <EuiFlexItem> | ||
| <EuiCard | ||
| icon={<EuiIcon size="xxl" type={`dataVisualizer`} />} | ||
|
|
@@ -213,38 +218,42 @@ export const ResultsLinks: FC<Props> = ({ | |
| /> | ||
| } | ||
| description="" | ||
| onClick={openInDataVisualizer} | ||
| href={dataVisualizerLink} | ||
| /> | ||
| </EuiFlexItem> | ||
| )} | ||
|
|
||
| <EuiFlexItem> | ||
| <EuiCard | ||
| icon={<EuiIcon size="xxl" type={`managementApp`} />} | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.indexManagementTitle" | ||
| defaultMessage="Index Management" | ||
| /> | ||
| } | ||
| description="" | ||
| onClick={openIndexManagement} | ||
| /> | ||
| </EuiFlexItem> | ||
| {indexManagementLink && ( | ||
| <EuiFlexItem> | ||
| <EuiCard | ||
| icon={<EuiIcon size="xxl" type={`managementApp`} />} | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.indexManagementTitle" | ||
| defaultMessage="Index Management" | ||
| /> | ||
| } | ||
| description="" | ||
| href={indexManagementLink} | ||
| /> | ||
| </EuiFlexItem> | ||
| )} | ||
|
|
||
| <EuiFlexItem> | ||
| <EuiCard | ||
| icon={<EuiIcon size="xxl" type={`managementApp`} />} | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.indexPatternManagementTitle" | ||
| defaultMessage="Index Pattern Management" | ||
| /> | ||
| } | ||
| description="" | ||
| onClick={openIndexPatternManagement} | ||
| /> | ||
| </EuiFlexItem> | ||
| {indexPatternManagementLink && ( | ||
| <EuiFlexItem> | ||
| <EuiCard | ||
| icon={<EuiIcon size="xxl" type={`managementApp`} />} | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.ml.fileDatavisualizer.resultsLinks.indexPatternManagementTitle" | ||
| defaultMessage="Index Pattern Management" | ||
| /> | ||
| } | ||
| description="" | ||
| href={indexPatternManagementLink} | ||
| /> | ||
| </EuiFlexItem> | ||
| )} | ||
| <EuiFlexItem> | ||
| <EuiCard | ||
| icon={<EuiIcon size="xxl" type={`filebeatApp`} />} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,9 @@ import React from 'react'; | |
| import { detectorToString } from '../../../../util/string_utils'; | ||
| import { formatValues, filterObjects } from './format_values'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { Link } from 'react-router-dom'; | ||
| import { EuiLink } from '@elastic/eui'; | ||
|
|
||
| export function extractJobDetails(job) { | ||
| export function extractJobDetails(job, basePath) { | ||
| if (Object.keys(job).length === 0) { | ||
| return {}; | ||
| } | ||
|
|
@@ -61,7 +61,9 @@ export function extractJobDetails(job) { | |
| if (job.calendars) { | ||
| calendars.items = job.calendars.map((c) => [ | ||
| '', | ||
| <Link to={`/settings/calendars_list/edit_calendar/${c}?_g=()`}>{c}</Link>, | ||
| <EuiLink href={basePath.prepend(`/app/ml/settings/calendars_list/edit_calendar/${c}?_g=()`)}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think moving forward we will have to use the url with basePath for all the href. The
Also, in this particular component the |
||
| {c} | ||
| </EuiLink>, | ||
| ]); | ||
| // remove the calendars list from the general section | ||
| // so not to show it twice. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we use
MlHrefinstead ofwindow.open?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll keep this one here for now for 7.10.0.