[6.x] [Infra UI] Use alternative query string serialization function (#29361) (#29480)

Backports the following commits to 6.x:
 - [Infra UI] Use alternative query string serialization function  (#29361)
This commit is contained in:
Felix Stürmer 2019-01-29 11:50:33 +01:00 committed by GitHub
parent 97e5be671a
commit 3b04216444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -18,6 +18,8 @@
*/
declare class QueryStringClass {
public decode(queryString: string): any;
public encode(obj: any): string;
public param(key: string, value: string): string;
}

View file

@ -6,11 +6,12 @@
import { History, Location } from 'history';
import throttle from 'lodash/fp/throttle';
import { parse as parseQueryString, stringify as stringifyQueryString } from 'querystring';
import React from 'react';
import { Route, RouteProps } from 'react-router';
import { decode, encode, RisonValue } from 'rison-node';
import { QueryString } from 'ui/utils/query_string';
interface UrlStateContainerProps<UrlState> {
urlState: UrlState | undefined;
urlStateKey: string;
@ -135,7 +136,7 @@ const encodeRisonUrlState = (state: any) => encode(state);
export const getQueryStringFromLocation = (location: Location) => location.search.substring(1);
export const getParamFromQueryString = (queryString: string, key: string): string | undefined => {
const queryParam = parseQueryString(queryString)[key];
const queryParam = QueryString.decode(queryString)[key];
return Array.isArray(queryParam) ? queryParam[0] : queryParam;
};
@ -143,10 +144,10 @@ export const replaceStateKeyInQueryString = <UrlState extends any>(
stateKey: string,
urlState: UrlState | undefined
) => (queryString: string) => {
const previousQueryValues = parseQueryString(queryString);
const previousQueryValues = QueryString.decode(queryString);
const encodedUrlState =
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;
return stringifyQueryString({
return QueryString.encode({
...previousQueryValues,
[stateKey]: encodedUrlState,
});