Skip to content

Commit

Permalink
Fix more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Mar 4, 2020
1 parent 945990e commit f26a1ca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { parse } from 'querystring';
import { parse, stringify } from 'querystring';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LocalUIFilterName } from '../../../../../../../plugins/apm/server/lib/ui_filters/local_ui_filters/config';
import { url } from '../../../../../../../../src/plugins/kibana_utils/public';
Expand All @@ -18,7 +18,9 @@ export function fromQuery(query: Record<string, any>) {
encodeURIComponent(value).replace(/%3A/g, ':')
);

return url.makeUrlFromQuery(encodedQuery);
return stringify(encodedQuery, undefined, undefined, {
encodeURIComponent: (c: unknown) => c
});
}

export type APMQueryParams = {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/legacy/plugins/ml/public/application/util/url_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { parse, stringify } from 'querystring';
import { parse } from 'querystring';
import { useCallback } from 'react';
import { isEqual } from 'lodash';
import { decode, encode } from 'rison-node';
Expand Down Expand Up @@ -33,7 +33,7 @@ function isRisonSerializationRequired(queryParam: string): boolean {

export function getUrlState(search: string): Dictionary<any> {
const urlState: Dictionary<any> = {};
const parsedQueryString = parse(search);
const parsedQueryString = parse(search.substring(1));

try {
Object.keys(parsedQueryString).forEach(a => {
Expand Down Expand Up @@ -64,7 +64,7 @@ export const useUrlState = (accessor: string): UrlState => {
const setUrlState = useCallback(
(attribute: string | Dictionary<any>, value?: any) => {
const urlState = getUrlState(search);
const parsedQueryString = parse(search);
const parsedQueryString = parse(search.substring(1));

if (!Object.prototype.hasOwnProperty.call(urlState, accessor)) {
urlState[accessor] = {};
Expand Down Expand Up @@ -97,7 +97,7 @@ export const useUrlState = (accessor: string): UrlState => {

if (oldLocationSearch !== newLocationSearch) {
history.push({
search: stringify(parsedQueryString),
search: url.makeUrlFromQuery(parsedQueryString),
});
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('RedirectToLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/stream?sourceId=default&logPosition=(position%3A(tiebreaker%3A0%2Ctime%3A1550671089404)%2CstreamLive%3A!f)&logFilter=(expression%3A''%2Ckind%3Akuery)"
to="/stream?sourceId=default&logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&logFilter=(expression:'',kind:kuery)"
/>
`);
});
Expand All @@ -33,7 +33,7 @@ describe('RedirectToLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/stream?sourceId=default&logPosition=(position%3A(tiebreaker%3A0%2Ctime%3A1550671089404)%2CstreamLive%3A!f)&logFilter=(expression%3A'FILTER_FIELD%3AFILTER_VALUE'%2Ckind%3Akuery)"
to="/stream?sourceId=default&logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
/>
`);
});
Expand All @@ -45,7 +45,7 @@ describe('RedirectToLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/stream?sourceId=SOME-OTHER-SOURCE&logFilter=(expression%3A''%2Ckind%3Akuery)"
to="/stream?sourceId=SOME-OTHER-SOURCE&logFilter=(expression:'',kind:kuery)"
/>
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?sourceId=default&logFilter=(expression%3A'HOST_FIELD%3A%2520HOST_NAME'%2Ckind%3Akuery)"
to="/?sourceId=default&logFilter=(expression:'HOST_FIELD:+HOST_NAME',kind:kuery)"
/>
`);
});
Expand All @@ -47,7 +47,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?sourceId=default&logFilter=(expression%3A'CONTAINER_FIELD%3A%2520CONTAINER_ID'%2Ckind%3Akuery)"
to="/?sourceId=default&logFilter=(expression:'CONTAINER_FIELD:+CONTAINER_ID',kind:kuery)"
/>
`);
});
Expand All @@ -59,7 +59,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?sourceId=default&logFilter=(expression%3A'POD_FIELD%3A%2520POD_ID'%2Ckind%3Akuery)"
to="/?sourceId=default&logFilter=(expression:'POD_FIELD:+POD_ID',kind:kuery)"
/>
`);
});
Expand All @@ -73,7 +73,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?sourceId=default&logPosition=(position%3A(tiebreaker%3A0%2Ctime%3A1550671089404)%2CstreamLive%3A!f)&logFilter=(expression%3A'HOST_FIELD%3A%2520HOST_NAME'%2Ckind%3Akuery)"
to="/?sourceId=default&logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&logFilter=(expression:'HOST_FIELD:+HOST_NAME',kind:kuery)"
/>
`);
});
Expand All @@ -89,7 +89,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?sourceId=default&logPosition=(position%3A(tiebreaker%3A0%2Ctime%3A1550671089404)%2CstreamLive%3A!f)&logFilter=(expression%3A'(HOST_FIELD%3A%2520HOST_NAME)%2520and%2520(FILTER_FIELD%3AFILTER_VALUE)'%2Ckind%3Akuery)"
to="/?sourceId=default&logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&logFilter=(expression:'(HOST_FIELD:+HOST_NAME)+and+(FILTER_FIELD:FILTER_VALUE)',kind:kuery)"
/>
`);
});
Expand All @@ -103,7 +103,7 @@ describe('RedirectToNodeLogs component', () => {

expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?sourceId=SOME-OTHER-SOURCE&logFilter=(expression%3A'HOST_FIELD%3A%2520HOST_NAME'%2Ckind%3Akuery)"
to="/?sourceId=SOME-OTHER-SOURCE&logFilter=(expression:'HOST_FIELD:+HOST_NAME',kind:kuery)"
/>
`);
});
Expand Down

0 comments on commit f26a1ca

Please sign in to comment.