mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Backports the following commits to 6.x: - [Infra UI] Use alternative query string serialization function (#29361)
This commit is contained in:
parent
97e5be671a
commit
3b04216444
2 changed files with 7 additions and 4 deletions
2
src/ui/public/utils/query_string.d.ts
vendored
2
src/ui/public/utils/query_string.d.ts
vendored
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
|
||||
declare class QueryStringClass {
|
||||
public decode(queryString: string): any;
|
||||
public encode(obj: any): string;
|
||||
public param(key: string, value: string): string;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue