* Fixes bug with rison decode vs encode * Adds and updates tests for kibana link component
This commit is contained in:
parent
f55b39d195
commit
51b1f4febf
|
@ -10,13 +10,34 @@ exports[`RelativeLinkComponent should render correct markup 1`] = `
|
||||||
</a>
|
</a>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`UnconnectedKibanaLink should render correct markup 1`] = `
|
exports[`UnconnectedKibanaLink should include existing _g values in link href 1`] = `
|
||||||
<a
|
<EuiLink
|
||||||
className="euiLink euiLink--primary"
|
color="primary"
|
||||||
href="myBasePath/app/kibana#/discover?_a=(interval:auto,query:(language:lucene,query:'context.service.name:\\"myServiceName\\" AND error.grouping_key:\\"myGroupId\\"'),sort:('@timestamp':desc))&_g=(time:(from:now-24h,mode:quick,to:now))"
|
href="myBasePath/app/kibana#/discover?_a=(interval:auto,query:(language:lucene,query:'context.service.name:\\"myServiceName\\" AND error.grouping_key:\\"myGroupId\\"'),sort:('@timestamp':desc))&_g=(refreshInterval:(pause:!t,value:0),time:(from:now-7d,mode:relative,to:now-1d))"
|
||||||
|
type="button"
|
||||||
>
|
>
|
||||||
Go to Discover
|
Go to Discover
|
||||||
</a>
|
</EuiLink>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`UnconnectedKibanaLink should include existing _g values in link href 2`] = `
|
||||||
|
<EuiLink
|
||||||
|
color="primary"
|
||||||
|
href="myBasePath/app/kibana#/discover?_a=(interval:auto,query:(language:lucene,query:'context.service.name:\\"myServiceName\\" AND error.grouping_key:\\"myGroupId\\"'),sort:('@timestamp':desc))&_g=H@whatever"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Go to Discover
|
||||||
|
</EuiLink>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`UnconnectedKibanaLink should render correct markup 1`] = `
|
||||||
|
<EuiLink
|
||||||
|
color="primary"
|
||||||
|
href="myBasePath/app/kibana#/discover?_a=(interval:auto,query:(language:lucene,query:'context.service.name:\\"myServiceName\\" AND error.grouping_key:\\"myGroupId\\"'),sort:('@timestamp':desc))&_g=(time:(from:now-24h,mode:quick,to:now))"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Go to Discover
|
||||||
|
</EuiLink>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`ViewMLJob should render component 1`] = `
|
exports[`ViewMLJob should render component 1`] = `
|
||||||
|
|
|
@ -197,7 +197,7 @@ describe('UnconnectedKibanaLink', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
wrapper = mount(
|
wrapper = shallow(
|
||||||
<UnconnectedKibanaLink
|
<UnconnectedKibanaLink
|
||||||
location={{ search: '' }}
|
location={{ search: '' }}
|
||||||
pathname={'/app/kibana'}
|
pathname={'/app/kibana'}
|
||||||
|
@ -210,13 +210,26 @@ describe('UnconnectedKibanaLink', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have correct url', () => {
|
it('should have correct url', () => {
|
||||||
expect(wrapper.find('a').prop('href')).toBe(
|
expect(wrapper.find('EuiLink').prop('href')).toBe(
|
||||||
'myBasePath/app/kibana#/discover?_a=(interval:auto,query:(language:lucene,query:\'context.service.name:"myServiceName" AND error.grouping_key:"myGroupId"\'),sort:(\'@timestamp\':desc))&_g=(time:(from:now-24h,mode:quick,to:now))'
|
'myBasePath/app/kibana#/discover?_a=(interval:auto,query:(language:lucene,query:\'context.service.name:"myServiceName" AND error.grouping_key:"myGroupId"\'),sort:(\'@timestamp\':desc))&_g=(time:(from:now-24h,mode:quick,to:now))'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render correct markup', () => {
|
it('should render correct markup', () => {
|
||||||
expect(toJson(wrapper)).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should include existing _g values in link href', () => {
|
||||||
|
wrapper.setProps({
|
||||||
|
location: {
|
||||||
|
search:
|
||||||
|
'?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-7d,mode:relative,to:now-1d))'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
|
||||||
|
wrapper.setProps({ location: { search: '?_g=H@whatever' } });
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
|
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
|
||||||
import createHistory from 'history/createHashHistory';
|
import createHistory from 'history/createHashHistory';
|
||||||
import { get, isEmpty, isPlainObject, mapValues } from 'lodash';
|
import { get, isPlainObject, mapValues } from 'lodash';
|
||||||
import qs from 'querystring';
|
import qs from 'querystring';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
@ -16,6 +16,10 @@ import chrome from 'ui/chrome';
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import { StringMap } from '../../typings/common';
|
import { StringMap } from '../../typings/common';
|
||||||
|
|
||||||
|
// Kibana default set in: https://github.com/elastic/kibana/blob/e13e47fc4eb6112f2a5401408e9f765eae90f55d/x-pack/plugins/apm/public/utils/timepicker/index.js#L31-L35
|
||||||
|
// TODO: store this in config or a shared constant?
|
||||||
|
const DEFAULT_KIBANA_TIME_RANGE = '(time:(from:now-24h,mode:quick,to:now))';
|
||||||
|
|
||||||
interface ViewMlJobArgs {
|
interface ViewMlJobArgs {
|
||||||
serviceName: string;
|
serviceName: string;
|
||||||
transactionType: string;
|
transactionType: string;
|
||||||
|
@ -152,17 +156,6 @@ export function RelativeLinkComponent({
|
||||||
// The two components have different APIs: `path` vs `pathname` and one uses EuiLink the other react-router's Link (which behaves differently)
|
// The two components have different APIs: `path` vs `pathname` and one uses EuiLink the other react-router's Link (which behaves differently)
|
||||||
// Suggestion: Deprecate RelativeLink, and clean up KibanaLink
|
// Suggestion: Deprecate RelativeLink, and clean up KibanaLink
|
||||||
|
|
||||||
// _g is always retrieved from the url - it can not be changed via query prop
|
|
||||||
function getGArg(g: string) {
|
|
||||||
// use "g" if it's set in the url
|
|
||||||
if (g && !isEmpty(rison.decode(g))) {
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
// use default 24h (default set in: https://github.com/elastic/kibana/blob/e13e47fc4eb6112f2a5401408e9f765eae90f55d/x-pack/plugins/apm/public/utils/timepicker/index.js#L31-L35)
|
|
||||||
return '(time:(from:now-24h,mode:quick,to:now))';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface KibanaLinkArgs {
|
export interface KibanaLinkArgs {
|
||||||
location: {
|
location: {
|
||||||
search?: string;
|
search?: string;
|
||||||
|
@ -194,7 +187,8 @@ export const UnconnectedKibanaLink: React.SFC<KibanaLinkArgs> = ({
|
||||||
const currentQuery = toQuery(location.search);
|
const currentQuery = toQuery(location.search);
|
||||||
const nextQuery = {
|
const nextQuery = {
|
||||||
...query,
|
...query,
|
||||||
_g: getGArg(currentQuery._g),
|
// use "_g" if it's set in the url, otherwise use default
|
||||||
|
_g: currentQuery._g || DEFAULT_KIBANA_TIME_RANGE,
|
||||||
_a: query._a ? rison.encode(query._a) : ''
|
_a: query._a ? rison.encode(query._a) : ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue