Skip to content
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

Fixes bug with rison decode on Kibana links #25214

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions x-pack/plugins/apm/public/utils/url.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import chrome from 'ui/chrome';
import url from 'url';
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
const DEFAULT_KIBANA_TIME_RANGE = '(time:(from:now-24h,mode:quick,to:now))';

interface ViewMlJobArgs {
serviceName: string;
transactionType: string;
Expand Down Expand Up @@ -152,17 +155,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)
// 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 {
location: {
search?: string;
Expand Down Expand Up @@ -194,7 +186,8 @@ export const UnconnectedKibanaLink: React.SFC<KibanaLinkArgs> = ({
const currentQuery = toQuery(location.search);
const nextQuery = {
...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) : ''
};

Expand Down