From b989991cf2296569900f881ad54b6821f12c76a6 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 23 Dec 2019 10:39:02 -0500 Subject: [PATCH 1/3] Adds singleton registration utilities in case we need them as an escape hatch --- .../plugins/infra/public/legacy_singletons.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 x-pack/legacy/plugins/infra/public/legacy_singletons.ts diff --git a/x-pack/legacy/plugins/infra/public/legacy_singletons.ts b/x-pack/legacy/plugins/infra/public/legacy_singletons.ts new file mode 100644 index 0000000000000..d07da7767cb73 --- /dev/null +++ b/x-pack/legacy/plugins/infra/public/legacy_singletons.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ +import { CoreSetup, CoreStart } from 'kibana/public'; + +let npSetup: CoreSetup; +let npStart: CoreStart; + +export function registerSetupSingleton(setup: CoreSetup) { + npSetup = setup; +} + +export function registerStartSingleton(start: CoreStart) { + npStart = start; +} + +export { npSetup, npStart }; From f837d600578c3d85c2dafc7e270422049112c82a Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 23 Dec 2019 10:40:43 -0500 Subject: [PATCH 2/3] Renames app to legacy_shim for clarity --- x-pack/legacy/plugins/infra/index.ts | 2 +- x-pack/legacy/plugins/infra/public/apps/start_app.tsx | 2 +- x-pack/legacy/plugins/infra/public/{app.ts => legacy_shim.ts} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename x-pack/legacy/plugins/infra/public/{app.ts => legacy_shim.ts} (100%) diff --git a/x-pack/legacy/plugins/infra/index.ts b/x-pack/legacy/plugins/infra/index.ts index 38661f430c402..18895858f52e4 100644 --- a/x-pack/legacy/plugins/infra/index.ts +++ b/x-pack/legacy/plugins/infra/index.ts @@ -35,7 +35,7 @@ export function infra(kibana: any) { defaultMessage: 'Explore your metrics', }), icon: 'plugins/infra/images/infra_mono_white.svg', - main: 'plugins/infra/app', + main: 'plugins/infra/legacy_shim', title: i18n.translate('xpack.infra.infrastructureTitle', { defaultMessage: 'Metrics', }), diff --git a/x-pack/legacy/plugins/infra/public/apps/start_app.tsx b/x-pack/legacy/plugins/infra/public/apps/start_app.tsx index 8ccb051724ede..0d12f7084c5e3 100644 --- a/x-pack/legacy/plugins/infra/public/apps/start_app.tsx +++ b/x-pack/legacy/plugins/infra/public/apps/start_app.tsx @@ -26,7 +26,7 @@ import { useUiSetting$, KibanaContextProvider, } from '../../../../../../src/plugins/kibana_react/public'; -import { ROOT_ELEMENT_ID } from '../app'; +import { ROOT_ELEMENT_ID } from '../legacy_shim'; // NP_TODO: Type plugins export async function startApp(libs: InfraFrontendLibs, core: CoreStart, plugins: any) { const history = createHashHistory(); diff --git a/x-pack/legacy/plugins/infra/public/app.ts b/x-pack/legacy/plugins/infra/public/legacy_shim.ts similarity index 100% rename from x-pack/legacy/plugins/infra/public/app.ts rename to x-pack/legacy/plugins/infra/public/legacy_shim.ts From 63d040e34f07679c9564ee29e7cfa0ae53724b8e Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 23 Dec 2019 10:41:16 -0500 Subject: [PATCH 3/3] Replaces QueryString kibana util with querystring lib --- .../log_analysis_results/analyze_in_ml_button.tsx | 6 +++--- x-pack/legacy/plugins/infra/public/utils/url_state.tsx | 9 ++++----- .../legacy/plugins/infra/public/utils/use_url_state.ts | 9 ++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/x-pack/legacy/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx b/x-pack/legacy/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx index 536dd24faa7c1..4668d30436f92 100644 --- a/x-pack/legacy/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx +++ b/x-pack/legacy/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx @@ -8,7 +8,7 @@ import { EuiButton } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import React from 'react'; import { encode } from 'rison-node'; -import { QueryString } from 'ui/utils/query_string'; +import qs from 'querystring'; import url from 'url'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { TimeRange } from '../../../../common/http_api/shared/time_range'; @@ -61,7 +61,7 @@ const getOverallAnomalyExplorerLink = (pathname: string, jobId: string, timeRang }, }); - const hash = `/explorer?${QueryString.encode({ _g })}`; + const hash = `/explorer?${qs.stringify({ _g })}`; return url.format({ pathname, @@ -94,7 +94,7 @@ const getPartitionSpecificSingleMetricViewerLink = ( }, }); - const hash = `/timeseriesexplorer?${QueryString.encode({ _g, _a })}`; + const hash = `/timeseriesexplorer?${qs.stringify({ _g, _a })}`; return url.format({ pathname, diff --git a/x-pack/legacy/plugins/infra/public/utils/url_state.tsx b/x-pack/legacy/plugins/infra/public/utils/url_state.tsx index 66bb4308d1d16..4046fbab15c16 100644 --- a/x-pack/legacy/plugins/infra/public/utils/url_state.tsx +++ b/x-pack/legacy/plugins/infra/public/utils/url_state.tsx @@ -9,8 +9,7 @@ import throttle from 'lodash/fp/throttle'; import React from 'react'; import { Route, RouteProps } from 'react-router-dom'; import { decode, encode, RisonValue } from 'rison-node'; - -import { QueryString } from 'ui/utils/query_string'; +import qs from 'querystring'; interface UrlStateContainerProps { urlState: UrlState | undefined; @@ -145,7 +144,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 = QueryString.decode(queryString)[key]; + const queryParam = qs.parse(queryString)[key]; return Array.isArray(queryParam) ? queryParam[0] : queryParam; }; @@ -153,10 +152,10 @@ export const replaceStateKeyInQueryString = ( stateKey: string, urlState: UrlState | undefined ) => (queryString: string) => { - const previousQueryValues = QueryString.decode(queryString); + const previousQueryValues = qs.parse(queryString); const encodedUrlState = typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined; - return QueryString.encode({ + return qs.stringify({ ...previousQueryValues, [stateKey]: encodedUrlState, }); diff --git a/x-pack/legacy/plugins/infra/public/utils/use_url_state.ts b/x-pack/legacy/plugins/infra/public/utils/use_url_state.ts index 79a5d552bcd78..9647163d806af 100644 --- a/x-pack/legacy/plugins/infra/public/utils/use_url_state.ts +++ b/x-pack/legacy/plugins/infra/public/utils/use_url_state.ts @@ -7,8 +7,7 @@ import { Location } from 'history'; import { useCallback, useEffect, useMemo, useState } from 'react'; import { decode, encode, RisonValue } from 'rison-node'; -import { QueryString } from 'ui/utils/query_string'; - +import qs from 'querystring'; import { useHistory } from './history_context'; export const useUrlState = ({ @@ -100,7 +99,7 @@ const encodeRisonUrlState = (state: any) => encode(state); const getQueryStringFromLocation = (location: Location) => location.search.substring(1); const getParamFromQueryString = (queryString: string, key: string): string | undefined => { - const queryParam = QueryString.decode(queryString)[key]; + const queryParam = qs.parse(queryString)[key]; return Array.isArray(queryParam) ? queryParam[0] : queryParam; }; @@ -108,10 +107,10 @@ export const replaceStateKeyInQueryString = ( stateKey: string, urlState: UrlState | undefined ) => (queryString: string) => { - const previousQueryValues = QueryString.decode(queryString); + const previousQueryValues = qs.parse(queryString); const encodedUrlState = typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined; - return QueryString.encode({ + return qs.stringify({ ...previousQueryValues, [stateKey]: encodedUrlState, });