* bump query-string version to remove manual type definitions * remove manual type declaration * fix cypress tests * add ) # Conflicts: # x-pack/plugins/security_solution/cypress/integration/ml_conditional_links.spec.ts
This commit is contained in:
parent
a3ede09d54
commit
c5c112f2e9
|
@ -190,7 +190,7 @@
|
|||
"p-map": "^4.0.0",
|
||||
"pegjs": "0.10.0",
|
||||
"proxy-from-env": "1.0.0",
|
||||
"query-string": "5.1.1",
|
||||
"query-string": "^6.13.2",
|
||||
"re2": "^1.15.4",
|
||||
"react": "^16.12.0",
|
||||
"react-color": "^2.13.8",
|
||||
|
|
|
@ -24,6 +24,6 @@ export { mapToObject } from './map_to_object';
|
|||
export { merge } from './merge';
|
||||
export { pick } from './pick';
|
||||
export { withTimeout } from './promise';
|
||||
export { isRelativeUrl, modifyUrl, URLMeaningfulParts, ParsedQuery } from './url';
|
||||
export { isRelativeUrl, modifyUrl, URLMeaningfulParts } from './url';
|
||||
export { unset } from './unset';
|
||||
export { getFlattenedObject } from './get_flattened_object';
|
||||
|
|
|
@ -18,11 +18,7 @@
|
|||
*/
|
||||
|
||||
import { format as formatUrl, parse as parseUrl, UrlObject } from 'url';
|
||||
|
||||
// duplicate type from 'query-string' to avoid adding the d.ts file to all packages depending on kbn-std
|
||||
export interface ParsedQuery<T = string> {
|
||||
[key: string]: T | T[] | null | undefined;
|
||||
}
|
||||
import type { ParsedQuery } from 'query-string';
|
||||
|
||||
/**
|
||||
* We define our own typings because the current version of @types/node
|
||||
|
|
|
@ -17,34 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
declare module 'query-string' {
|
||||
type ArrayFormat = 'bracket' | 'index' | 'none';
|
||||
|
||||
export interface ParseOptions {
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export interface ParsedQuery<T = string> {
|
||||
[key: string]: T | T[] | null | undefined;
|
||||
}
|
||||
|
||||
export function parse(str: string, options?: ParseOptions): ParsedQuery;
|
||||
|
||||
export function parseUrl(str: string, options?: ParseOptions): { url: string; query: any };
|
||||
|
||||
export interface StringifyOptions {
|
||||
strict?: boolean;
|
||||
encode?: boolean;
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export function stringify(obj: object, options?: StringifyOptions): string;
|
||||
|
||||
export function extract(str: string): string;
|
||||
}
|
||||
|
||||
type DeeplyMockedKeys<T> = {
|
||||
[P in keyof T]: T[P] extends (...args: any[]) => any
|
||||
? jest.MockInstance<ReturnType<T[P]>, Parameters<T[P]>>
|
||||
|
|
|
@ -24,16 +24,17 @@ describe('', () => {
|
|||
const id = '123eb456cd';
|
||||
const url =
|
||||
"/pep/app/dashboards#/create?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
|
||||
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toEqual(
|
||||
`/pep/app/dashboards#/create?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
|
||||
|
||||
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toBe(
|
||||
'/pep/app/dashboards?addEmbeddableId=123eb456cd&addEmbeddableType=visualization#%2Fcreate%3F_g%3D%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29%26_a%3D%28description%3A%27%27%2Cfilters%3A%21%28%29%29'
|
||||
);
|
||||
});
|
||||
it('addEmbeddableToDashboardUrl when dashboard is saved', () => {
|
||||
const id = '123eb456cd';
|
||||
const url =
|
||||
"/pep/app/dashboards#/view/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
|
||||
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toEqual(
|
||||
`/pep/app/dashboards#/view/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
|
||||
expect(addEmbeddableToDashboardUrl(url, id, 'visualization')).toBe(
|
||||
'/pep/app/dashboards?addEmbeddableId=123eb456cd&addEmbeddableType=visualization#%2Fview%2F9b780cd0-3dd3-11e8-b2b9-5d5dc1715159%3F_g%3D%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29%26_a%3D%28description%3A%27%27%2Cfilters%3A%21%28%29%29'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { parseUrl, stringify } from 'query-string';
|
||||
import { parseUrl, stringifyUrl } from 'query-string';
|
||||
import { DashboardConstants } from '../index';
|
||||
|
||||
/** *
|
||||
|
@ -34,12 +34,14 @@ export function addEmbeddableToDashboardUrl(
|
|||
embeddableId: string,
|
||||
embeddableType: string
|
||||
) {
|
||||
const { url, query } = parseUrl(dashboardUrl);
|
||||
const { url, query, fragmentIdentifier } = parseUrl(dashboardUrl, {
|
||||
parseFragmentIdentifier: true,
|
||||
});
|
||||
|
||||
if (embeddableId) {
|
||||
query[DashboardConstants.ADD_EMBEDDABLE_TYPE] = embeddableType;
|
||||
query[DashboardConstants.ADD_EMBEDDABLE_ID] = embeddableId;
|
||||
}
|
||||
|
||||
return `${url}?${stringify(query)}`;
|
||||
return stringifyUrl({ url, query, fragmentIdentifier });
|
||||
}
|
||||
|
|
46
test/typings/query_string.d.ts
vendored
46
test/typings/query_string.d.ts
vendored
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
declare module 'query-string' {
|
||||
type ArrayFormat = 'bracket' | 'index' | 'none';
|
||||
|
||||
export interface ParseOptions {
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export interface ParsedQuery<T = string> {
|
||||
[key: string]: T | T[] | null | undefined;
|
||||
}
|
||||
|
||||
export function parse(str: string, options?: ParseOptions): ParsedQuery;
|
||||
|
||||
export function parseUrl(str: string, options?: ParseOptions): { url: string; query: any };
|
||||
|
||||
export interface StringifyOptions {
|
||||
strict?: boolean;
|
||||
encode?: boolean;
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export function stringify(obj: object, options?: StringifyOptions): string;
|
||||
|
||||
export function extract(str: string): string;
|
||||
}
|
46
typings/query_string.d.ts
vendored
46
typings/query_string.d.ts
vendored
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
declare module 'query-string' {
|
||||
type ArrayFormat = 'bracket' | 'index' | 'none';
|
||||
|
||||
export interface ParseOptions {
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export interface ParsedQuery<T = string> {
|
||||
[key: string]: T | T[] | null | undefined;
|
||||
}
|
||||
|
||||
export function parse(str: string, options?: ParseOptions): ParsedQuery;
|
||||
|
||||
export function parseUrl(str: string, options?: ParseOptions): { url: string; query: any };
|
||||
|
||||
export interface StringifyOptions {
|
||||
strict?: boolean;
|
||||
encode?: boolean;
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export function stringify(obj: object, options?: StringifyOptions): string;
|
||||
|
||||
export function extract(str: string): string;
|
||||
}
|
|
@ -362,7 +362,7 @@
|
|||
"proper-lockfile": "^3.2.0",
|
||||
"puid": "1.0.7",
|
||||
"puppeteer-core": "^1.19.0",
|
||||
"query-string": "5.1.1",
|
||||
"query-string": "^6.13.2",
|
||||
"raw-loader": "3.1.0",
|
||||
"react": "^16.12.0",
|
||||
"react-datetime": "^2.14.0",
|
||||
|
|
|
@ -19,7 +19,7 @@ describe('RedirectToLogs component', () => {
|
|||
|
||||
expect(component).toMatchInlineSnapshot(`
|
||||
<Redirect
|
||||
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'',kind:kuery)"
|
||||
to="/stream?sourceId=default&logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&logFilter=(expression:'',kind:kuery)"
|
||||
/>
|
||||
`);
|
||||
});
|
||||
|
@ -33,7 +33,7 @@ describe('RedirectToLogs component', () => {
|
|||
|
||||
expect(component).toMatchInlineSnapshot(`
|
||||
<Redirect
|
||||
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
|
||||
to="/stream?sourceId=default&logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
|
||||
/>
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -156,16 +156,14 @@ export const replaceStateKeyInQueryString = <UrlState extends any>(
|
|||
urlState: UrlState | undefined
|
||||
) => (queryString: string) => {
|
||||
const previousQueryValues = parse(queryString, { sort: false });
|
||||
const encodedUrlState =
|
||||
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;
|
||||
|
||||
return stringify(
|
||||
url.encodeQuery({
|
||||
...previousQueryValues,
|
||||
[stateKey]: encodedUrlState,
|
||||
}),
|
||||
{ sort: false, encode: false }
|
||||
);
|
||||
const newValue =
|
||||
typeof urlState === 'undefined'
|
||||
? previousQueryValues
|
||||
: {
|
||||
...previousQueryValues,
|
||||
[stateKey]: encodeRisonUrlState(urlState),
|
||||
};
|
||||
return stringify(url.encodeQuery(newValue), { sort: false, encode: false });
|
||||
};
|
||||
|
||||
const replaceQueryStringInLocation = (location: Location, queryString: string): Location => {
|
||||
|
|
|
@ -111,16 +111,15 @@ export const replaceStateKeyInQueryString = <UrlState extends any>(
|
|||
urlState: UrlState | undefined
|
||||
) => (queryString: string) => {
|
||||
const previousQueryValues = parse(queryString, { sort: false });
|
||||
const encodedUrlState =
|
||||
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;
|
||||
const newValue =
|
||||
typeof urlState === 'undefined'
|
||||
? previousQueryValues
|
||||
: {
|
||||
...previousQueryValues,
|
||||
[stateKey]: encodeRisonUrlState(urlState),
|
||||
};
|
||||
|
||||
return stringify(
|
||||
url.encodeQuery({
|
||||
...previousQueryValues,
|
||||
[stateKey]: encodedUrlState,
|
||||
}),
|
||||
{ sort: false, encode: false }
|
||||
);
|
||||
return stringify(url.encodeQuery(newValue), { sort: false, encode: false });
|
||||
};
|
||||
|
||||
const replaceQueryStringInLocation = (location: Location, queryString: string): Location => {
|
||||
|
|
|
@ -58,16 +58,14 @@ export const replaceStateKeyInQueryString = <T>(stateKey: string, urlState: T) =
|
|||
|
||||
// ಠ_ಠ Code was copied from x-pack/legacy/plugins/infra/public/utils/url_state.tsx ಠ_ಠ
|
||||
// Remove this if these utilities are promoted to kibana core
|
||||
const encodedUrlState =
|
||||
typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined;
|
||||
|
||||
return stringify(
|
||||
url.encodeQuery({
|
||||
...previousQueryValues,
|
||||
[stateKey]: encodedUrlState,
|
||||
}),
|
||||
{ sort: false, encode: false }
|
||||
);
|
||||
const newValue =
|
||||
typeof urlState === 'undefined'
|
||||
? previousQueryValues
|
||||
: {
|
||||
...previousQueryValues,
|
||||
[stateKey]: encodeRisonUrlState(urlState),
|
||||
};
|
||||
return stringify(url.encodeQuery(newValue), { sort: false, encode: false });
|
||||
};
|
||||
|
||||
export const replaceQueryStringInLocation = (
|
||||
|
|
|
@ -121,7 +121,7 @@ describe('useUrlParams', () => {
|
|||
|
||||
expect(history.push).toHaveBeenCalledWith({
|
||||
pathname: '/',
|
||||
search: 'dateRangeEnd=now&dateRangeStart=now-12&g=%22%22',
|
||||
search: 'g=%22%22&dateRangeStart=now-12&dateRangeEnd=now',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
33
x-pack/typings/query_string.d.ts
vendored
33
x-pack/typings/query_string.d.ts
vendored
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
declare module 'query-string' {
|
||||
type ArrayFormat = 'bracket' | 'index' | 'none';
|
||||
|
||||
export interface ParseOptions {
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort?: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export interface ParsedQuery<T = string> {
|
||||
[key: string]: T | T[] | null | undefined;
|
||||
}
|
||||
|
||||
export function parse(str: string, options?: ParseOptions): ParsedQuery;
|
||||
|
||||
export function parseUrl(str: string, options?: ParseOptions): { url: string; query: any };
|
||||
|
||||
export interface StringifyOptions {
|
||||
strict?: boolean;
|
||||
encode?: boolean;
|
||||
arrayFormat?: ArrayFormat;
|
||||
sort?: ((itemLeft: string, itemRight: string) => number) | false;
|
||||
}
|
||||
|
||||
export function stringify(obj: object, options?: StringifyOptions): string;
|
||||
|
||||
export function extract(str: string): string;
|
||||
}
|
33
yarn.lock
33
yarn.lock
|
@ -23123,7 +23123,15 @@ qs@^6.6.0:
|
|||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.8.0.tgz#87b763f0d37ca54200334cd57bb2ef8f68a1d081"
|
||||
integrity sha512-tPSkj8y92PfZVbinY1n84i1Qdx75lZjMQYx9WZhnkofyxzw2r7Ho39G3/aEvSUdebxpnnM4LZJCtvE/Aq3+s9w==
|
||||
|
||||
query-string@5.1.1, query-string@^5.0.1:
|
||||
query-string@^4.1.0, query-string@^4.2.2:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
|
||||
integrity sha1-u7aTucqRXCMlFbIosaArYJBD2+s=
|
||||
dependencies:
|
||||
object-assign "^4.1.0"
|
||||
strict-uri-encode "^1.0.0"
|
||||
|
||||
query-string@^5.0.1:
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-5.1.1.tgz#a78c012b71c17e05f2e3fa2319dd330682efb3cb"
|
||||
integrity sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==
|
||||
|
@ -23132,13 +23140,14 @@ query-string@5.1.1, query-string@^5.0.1:
|
|||
object-assign "^4.1.0"
|
||||
strict-uri-encode "^1.0.0"
|
||||
|
||||
query-string@^4.1.0, query-string@^4.2.2:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
|
||||
integrity sha1-u7aTucqRXCMlFbIosaArYJBD2+s=
|
||||
query-string@^6.13.2:
|
||||
version "6.13.2"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.13.2.tgz#3585aa9412c957cbd358fd5eaca7466f05586dda"
|
||||
integrity sha512-BMmDaUiLDFU1hlM38jTFcRt7HYiGP/zt1sRzrIWm5zpeEuO1rkbPS0ELI3uehoLuuhHDCS8u8lhFN3fEN4JzPQ==
|
||||
dependencies:
|
||||
object-assign "^4.1.0"
|
||||
strict-uri-encode "^1.0.0"
|
||||
decode-uri-component "^0.2.0"
|
||||
split-on-first "^1.0.0"
|
||||
strict-uri-encode "^2.0.0"
|
||||
|
||||
querystring-es3@^0.2.0:
|
||||
version "0.2.1"
|
||||
|
@ -26456,6 +26465,11 @@ spdy@^4.0.2:
|
|||
select-hose "^2.0.0"
|
||||
spdy-transport "^3.0.0"
|
||||
|
||||
split-on-first@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
|
||||
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
|
||||
|
||||
split-string@^3.0.1, split-string@^3.0.2:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
|
||||
|
@ -26725,6 +26739,11 @@ strict-uri-encode@^1.0.0:
|
|||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
|
||||
integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=
|
||||
|
||||
strict-uri-encode@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
|
||||
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
|
||||
|
||||
string-length@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/string-length/-/string-length-1.0.1.tgz#56970fb1c38558e9e70b728bf3de269ac45adfac"
|
||||
|
|
Loading…
Reference in a new issue