Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few client np migration updates #2

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/infra/public/apps/start_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -94,7 +94,7 @@ const getPartitionSpecificSingleMetricViewerLink = (
},
});

const hash = `/timeseriesexplorer?${QueryString.encode({ _g, _a })}`;
const hash = `/timeseriesexplorer?${qs.stringify({ _g, _a })}`;

return url.format({
pathname,
Expand Down
19 changes: 19 additions & 0 deletions x-pack/legacy/plugins/infra/public/legacy_singletons.ts
Original file line number Diff line number Diff line change
@@ -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 };
9 changes: 4 additions & 5 deletions x-pack/legacy/plugins/infra/public/utils/url_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: UrlState | undefined;
Expand Down Expand Up @@ -145,18 +144,18 @@ 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;
};

export const replaceStateKeyInQueryString = <UrlState extends any>(
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,
});
Expand Down
9 changes: 4 additions & 5 deletions x-pack/legacy/plugins/infra/public/utils/use_url_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <State>({
Expand Down Expand Up @@ -100,18 +99,18 @@ 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;
};

export const replaceStateKeyInQueryString = <UrlState extends any>(
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,
});
Expand Down