@@ -8,48 +8,40 @@ import { EuiButton } from '@elastic/eui';
88import { FormattedMessage } from '@kbn/i18n/react' ;
99import React from 'react' ;
1010import { encode } from 'rison-node' ;
11- import url from 'url' ;
12- import { stringify } from 'query-string' ;
13- import { useKibana } from '../../../../../../../src/plugins/kibana_react/public' ;
1411import { TimeRange } from '../../../../common/http_api/shared/time_range' ;
15- import { url as urlUtils } from '../../../../../../../src/plugins/kibana_utils/public ' ;
12+ import { useLinkProps , LinkDescriptor } from '../../../hooks/use_link_props ' ;
1613
1714export const AnalyzeInMlButton : React . FunctionComponent < {
1815 jobId : string ;
1916 partition ?: string ;
2017 timeRange : TimeRange ;
2118} > = ( { jobId, partition, timeRange } ) => {
22- const prependBasePath = useKibana ( ) . services . http ?. basePath ?. prepend ;
23- if ( ! prependBasePath ) {
24- return null ;
25- }
26- const pathname = prependBasePath ( '/app/ml' ) ;
19+ const linkProps = useLinkProps (
20+ typeof partition === 'string'
21+ ? getPartitionSpecificSingleMetricViewerLinkDescriptor ( jobId , partition , timeRange )
22+ : getOverallAnomalyExplorerLinkDescriptor ( jobId , timeRange )
23+ ) ;
2724 const buttonLabel = (
2825 < FormattedMessage
2926 id = "xpack.infra.logs.analysis.analyzeInMlButtonLabel"
3027 defaultMessage = "Analyze in ML"
3128 />
3229 ) ;
3330 return typeof partition === 'string' ? (
34- < EuiButton
35- fill = { false }
36- size = "s"
37- href = { getPartitionSpecificSingleMetricViewerLink ( pathname , jobId , partition , timeRange ) }
38- >
31+ < EuiButton fill = { false } size = "s" { ...linkProps } >
3932 { buttonLabel }
4033 </ EuiButton >
4134 ) : (
42- < EuiButton
43- fill = { true }
44- size = "s"
45- href = { getOverallAnomalyExplorerLink ( pathname , jobId , timeRange ) }
46- >
35+ < EuiButton fill = { true } size = "s" { ...linkProps } >
4736 { buttonLabel }
4837 </ EuiButton >
4938 ) ;
5039} ;
5140
52- const getOverallAnomalyExplorerLink = ( pathname : string , jobId : string , timeRange : TimeRange ) => {
41+ const getOverallAnomalyExplorerLinkDescriptor = (
42+ jobId : string ,
43+ timeRange : TimeRange
44+ ) : LinkDescriptor => {
5345 const { from, to } = convertTimeRangeToParams ( timeRange ) ;
5446
5547 const _g = encode ( {
@@ -62,20 +54,18 @@ const getOverallAnomalyExplorerLink = (pathname: string, jobId: string, timeRang
6254 } ,
6355 } ) ;
6456
65- const hash = `/explorer?${ stringify ( urlUtils . encodeQuery ( { _g } ) , { encode : false } ) } ` ;
66-
67- return url . format ( {
68- pathname,
69- hash,
70- } ) ;
57+ return {
58+ app : 'ml' ,
59+ hash : '/explorer' ,
60+ search : { _g } ,
61+ } ;
7162} ;
7263
73- const getPartitionSpecificSingleMetricViewerLink = (
74- pathname : string ,
64+ const getPartitionSpecificSingleMetricViewerLinkDescriptor = (
7565 jobId : string ,
7666 partition : string ,
7767 timeRange : TimeRange
78- ) => {
68+ ) : LinkDescriptor => {
7969 const { from, to } = convertTimeRangeToParams ( timeRange ) ;
8070
8171 const _g = encode ( {
@@ -95,15 +85,11 @@ const getPartitionSpecificSingleMetricViewerLink = (
9585 } ,
9686 } ) ;
9787
98- const hash = `/timeseriesexplorer?${ stringify ( urlUtils . encodeQuery ( { _g, _a } ) , {
99- sort : false ,
100- encode : false ,
101- } ) } `;
102-
103- return url . format ( {
104- pathname,
105- hash,
106- } ) ;
88+ return {
89+ app : 'ml' ,
90+ hash : '/timeseriesexplorer' ,
91+ search : { _g, _a } ,
92+ } ;
10793} ;
10894
10995const convertTimeRangeToParams = ( timeRange : TimeRange ) : { from : string ; to : string } => {
0 commit comments