{
const basePath = ({
prepend: (url: string) => {
return `some-basepath${url}`;
},
- } as unknown) as AppMountContextBasePath;
+ } as unknown) as IBasePath;
const date = '2020-02-06T11:00:00.000Z';
const timestamp = { us: new Date(date).getTime() };
diff --git a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/sections.ts b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/sections.ts
index 5ca0285eb4ee..4433865b4499 100644
--- a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/sections.ts
+++ b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/sections.ts
@@ -5,7 +5,8 @@
*/
import { i18n } from '@kbn/i18n';
import { Location } from 'history';
-import { pickBy, isEmpty } from 'lodash';
+import { IBasePath } from 'kibana/public';
+import { isEmpty, pickBy } from 'lodash';
import moment from 'moment';
import url from 'url';
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
@@ -14,7 +15,6 @@ import { getDiscoverHref } from '../Links/DiscoverLinks/DiscoverLink';
import { getDiscoverQuery } from '../Links/DiscoverLinks/DiscoverTransactionLink';
import { getInfraHref } from '../Links/InfraLink';
import { fromQuery } from '../Links/url_helpers';
-import { AppMountContextBasePath } from '../../../context/ApmPluginContext';
function getInfraMetricsQuery(transaction: Transaction) {
const timestamp = new Date(transaction['@timestamp']).getTime();
@@ -49,7 +49,7 @@ export const getSections = ({
urlParams,
}: {
transaction: Transaction;
- basePath: AppMountContextBasePath;
+ basePath: IBasePath;
location: Location;
urlParams: IUrlParams;
}) => {
diff --git a/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js
index d2e237b086bb..9d127c06e0c1 100644
--- a/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js
+++ b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js
@@ -6,7 +6,11 @@
import moment from 'moment';
import React from 'react';
-import { toJson, mountWithTheme } from '../../../../../utils/testHelpers';
+import {
+ disableConsoleWarning,
+ toJson,
+ mountWithTheme,
+} from '../../../../../utils/testHelpers';
import { InnerCustomPlot } from '../index';
import responseWithData from './responseWithData.json';
import VoronoiPlot from '../VoronoiPlot';
@@ -19,11 +23,20 @@ function getXValueByIndex(index) {
}
describe('when response has data', () => {
+ let consoleMock;
let wrapper;
let onHover;
let onMouseLeave;
let onSelectionEnd;
+ beforeAll(() => {
+ consoleMock = disableConsoleWarning('Warning: componentWillReceiveProps');
+ });
+
+ afterAll(() => {
+ consoleMock.mockRestore();
+ });
+
beforeEach(() => {
const series = getResponseTimeSeries({ apmTimeseries: responseWithData });
onHover = jest.fn();
diff --git a/x-pack/plugins/apm/public/components/shared/charts/Histogram/__test__/Histogram.test.js b/x-pack/plugins/apm/public/components/shared/charts/Histogram/__test__/Histogram.test.js
index 41f835fbd5b1..ebb10f6676c5 100644
--- a/x-pack/plugins/apm/public/components/shared/charts/Histogram/__test__/Histogram.test.js
+++ b/x-pack/plugins/apm/public/components/shared/charts/Histogram/__test__/Histogram.test.js
@@ -13,13 +13,27 @@ import {
getDurationFormatter,
asInteger,
} from '../../../../../utils/formatters';
-import { toJson, mountWithTheme } from '../../../../../utils/testHelpers';
+import {
+ disableConsoleWarning,
+ toJson,
+ mountWithTheme,
+} from '../../../../../utils/testHelpers';
import { getFormattedBuckets } from '../../../../app/TransactionDetails/Distribution/index';
describe('Histogram', () => {
+ let mockConsole;
let wrapper;
+
const onClick = jest.fn();
+ beforeAll(() => {
+ mockConsole = disableConsoleWarning('Warning: componentWillReceiveProps');
+ });
+
+ afterAll(() => {
+ mockConsole.mockRestore();
+ });
+
beforeEach(() => {
const buckets = getFormattedBuckets(response.buckets, response.bucketSize);
const xMax = d3.max(buckets, (d) => d.x);
diff --git a/x-pack/plugins/apm/public/components/shared/charts/Timeline/Marker/ErrorMarker.test.tsx b/x-pack/plugins/apm/public/components/shared/charts/Timeline/Marker/ErrorMarker.test.tsx
index 7a5d0dd5ce87..6a5ab344d2ba 100644
--- a/x-pack/plugins/apm/public/components/shared/charts/Timeline/Marker/ErrorMarker.test.tsx
+++ b/x-pack/plugins/apm/public/components/shared/charts/Timeline/Marker/ErrorMarker.test.tsx
@@ -4,15 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import React from 'react';
-import { ErrorMarker } from './ErrorMarker';
-import { ErrorMark } from '../../../../app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Marks/get_error_marks';
import { fireEvent } from '@testing-library/react';
import { act } from '@testing-library/react-hooks';
+import React, { ReactNode } from 'react';
+import { MockApmPluginContextWrapper } from '../../../../../context/ApmPluginContext/MockApmPluginContext';
import {
expectTextsInDocument,
renderWithTheme,
} from '../../../../../utils/testHelpers';
+import { ErrorMark } from '../../../../app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Marks/get_error_marks';
+import { ErrorMarker } from './ErrorMarker';
+
+function Wrapper({ children }: { children?: ReactNode }) {
+ return
{children};
+}
describe('ErrorMarker', () => {
const mark = ({
@@ -36,7 +41,9 @@ describe('ErrorMarker', () => {
} as unknown) as ErrorMark;
function openPopover(errorMark: ErrorMark) {
- const component = renderWithTheme(
);
+ const component = renderWithTheme(
, {
+ wrapper: Wrapper,
+ });
act(() => {
fireEvent.click(component.getByTestId('popover'));
});
@@ -51,7 +58,8 @@ describe('ErrorMarker', () => {
it('renders link with trace and transaction', () => {
const component = openPopover(mark);
const errorLink = component.getByTestId('errorLink') as HTMLAnchorElement;
- expect(getKueryDecoded(errorLink.hash)).toEqual(
+
+ expect(getKueryDecoded(errorLink.search)).toEqual(
'kuery=trace.id : "123" and transaction.id : "456"'
);
});
@@ -63,7 +71,7 @@ describe('ErrorMarker', () => {
} as ErrorMark;
const component = openPopover(newMark);
const errorLink = component.getByTestId('errorLink') as HTMLAnchorElement;
- expect(getKueryDecoded(errorLink.hash)).toEqual('kuery=trace.id : "123"');
+ expect(getKueryDecoded(errorLink.search)).toEqual('kuery=trace.id : "123"');
});
it('renders link with transaction', () => {
const { trace, ...withoutTrace } = mark.error;
@@ -73,7 +81,7 @@ describe('ErrorMarker', () => {
} as ErrorMark;
const component = openPopover(newMark);
const errorLink = component.getByTestId('errorLink') as HTMLAnchorElement;
- expect(getKueryDecoded(errorLink.hash)).toEqual(
+ expect(getKueryDecoded(errorLink.search)).toEqual(
'kuery=transaction.id : "456"'
);
});
@@ -85,7 +93,7 @@ describe('ErrorMarker', () => {
} as ErrorMark;
const component = openPopover(newMark);
const errorLink = component.getByTestId('errorLink') as HTMLAnchorElement;
- expect(getKueryDecoded(errorLink.hash)).toEqual('kuery=');
+ expect(getKueryDecoded(errorLink.search)).toEqual('kuery=');
});
it('truncates the error message text', () => {
const { trace, transaction, ...withoutTraceAndTransaction } = mark.error;
diff --git a/x-pack/plugins/apm/public/components/shared/charts/Timeline/Timeline.test.tsx b/x-pack/plugins/apm/public/components/shared/charts/Timeline/Timeline.test.tsx
index 03ddc3f65682..ec9f887916f5 100644
--- a/x-pack/plugins/apm/public/components/shared/charts/Timeline/Timeline.test.tsx
+++ b/x-pack/plugins/apm/public/components/shared/charts/Timeline/Timeline.test.tsx
@@ -7,6 +7,7 @@
import React from 'react';
import { StickyContainer } from 'react-sticky';
import {
+ disableConsoleWarning,
mountWithTheme,
mockMoment,
toJson,
@@ -14,8 +15,15 @@ import {
import { Timeline } from '.';
describe('Timeline', () => {
+ let consoleMock: jest.SpyInstance;
+
beforeAll(() => {
mockMoment();
+ consoleMock = disableConsoleWarning('Warning: componentWill');
+ });
+
+ afterAll(() => {
+ consoleMock.mockRestore();
});
it('should render with data', () => {
diff --git a/x-pack/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx b/x-pack/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx
index 8c38cdcda958..8334efffbd51 100644
--- a/x-pack/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx
+++ b/x-pack/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx
@@ -3,11 +3,12 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React from 'react';
+import React, { ReactNode } from 'react';
+import { Observable, of } from 'rxjs';
import { ApmPluginContext, ApmPluginContextValue } from '.';
-import { createCallApmApi } from '../../services/rest/createCallApmApi';
import { ConfigSchema } from '../..';
import { UI_SETTINGS } from '../../../../../../src/plugins/data/common';
+import { createCallApmApi } from '../../services/rest/createCallApmApi';
const uiSettings: Record
= {
[UI_SETTINGS.TIMEPICKER_QUICK_RANGES]: [
@@ -33,8 +34,17 @@ const uiSettings: Record = {
};
const mockCore = {
+ application: {
+ capabilities: {
+ apm: {},
+ },
+ currentAppId$: new Observable(),
+ },
chrome: {
+ docTitle: { change: () => {} },
setBreadcrumbs: () => {},
+ setHelpExtension: () => {},
+ setBadge: () => {},
},
docLinks: {
DOC_LINK_VERSION: '0',
@@ -45,6 +55,9 @@ const mockCore = {
prepend: (path: string) => `/basepath${path}`,
},
},
+ i18n: {
+ Context: ({ children }: { children: ReactNode }) => children,
+ },
notifications: {
toasts: {
addWarning: () => {},
@@ -53,6 +66,7 @@ const mockCore = {
},
uiSettings: {
get: (key: string) => uiSettings[key],
+ get$: (key: string) => of(mockCore.uiSettings.get(key)),
},
};
diff --git a/x-pack/plugins/apm/public/context/ApmPluginContext/index.tsx b/x-pack/plugins/apm/public/context/ApmPluginContext/index.tsx
index 37304d292540..39d961f6a816 100644
--- a/x-pack/plugins/apm/public/context/ApmPluginContext/index.tsx
+++ b/x-pack/plugins/apm/public/context/ApmPluginContext/index.tsx
@@ -4,16 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { CoreStart } from 'kibana/public';
import { createContext } from 'react';
-import { AppMountContext } from 'kibana/public';
-import { ConfigSchema } from '../..';
+import { ConfigSchema } from '../../';
import { ApmPluginSetupDeps } from '../../plugin';
-export type AppMountContextBasePath = AppMountContext['core']['http']['basePath'];
-
export interface ApmPluginContextValue {
config: ConfigSchema;
- core: AppMountContext['core'];
+ core: CoreStart;
plugins: ApmPluginSetupDeps;
}
diff --git a/x-pack/plugins/apm/public/context/ChartsSyncContext.tsx b/x-pack/plugins/apm/public/context/ChartsSyncContext.tsx
index f93b69a87705..801c1d7e53f2 100644
--- a/x-pack/plugins/apm/public/context/ChartsSyncContext.tsx
+++ b/x-pack/plugins/apm/public/context/ChartsSyncContext.tsx
@@ -5,10 +5,10 @@
*/
import React, { ReactNode, useMemo, useState } from 'react';
-import { toQuery, fromQuery } from '../components/shared/Links/url_helpers';
-import { history } from '../utils/history';
-import { useUrlParams } from '../hooks/useUrlParams';
+import { useHistory } from 'react-router-dom';
+import { fromQuery, toQuery } from '../components/shared/Links/url_helpers';
import { useFetcher } from '../hooks/useFetcher';
+import { useUrlParams } from '../hooks/useUrlParams';
const ChartsSyncContext = React.createContext<{
hoverX: number | null;
@@ -18,6 +18,7 @@ const ChartsSyncContext = React.createContext<{
} | null>(null);
function ChartsSyncContextProvider({ children }: { children: ReactNode }) {
+ const history = useHistory();
const [time, setTime] = useState(null);
const { urlParams, uiFilters } = useUrlParams();
@@ -75,7 +76,7 @@ function ChartsSyncContextProvider({ children }: { children: ReactNode }) {
};
return { ...hoverXHandlers };
- }, [time, data.annotations]);
+ }, [history, time, data.annotations]);
return ;
}
diff --git a/x-pack/plugins/apm/public/hooks/useLocalUIFilters.ts b/x-pack/plugins/apm/public/hooks/useLocalUIFilters.ts
index 45ede7e7f260..0ed26fe08948 100644
--- a/x-pack/plugins/apm/public/hooks/useLocalUIFilters.ts
+++ b/x-pack/plugins/apm/public/hooks/useLocalUIFilters.ts
@@ -5,21 +5,21 @@
*/
import { omit } from 'lodash';
-import { useFetcher } from './useFetcher';
+import { useHistory } from 'react-router-dom';
+import { Projection } from '../../common/projections';
+import { pickKeys } from '../../common/utils/pick_keys';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LocalUIFiltersAPIResponse } from '../../server/lib/ui_filters/local_ui_filters';
-import { useUrlParams } from './useUrlParams';
import {
LocalUIFilterName,
localUIFilters,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../server/lib/ui_filters/local_ui_filters/config';
-import { history } from '../utils/history';
-import { toQuery, fromQuery } from '../components/shared/Links/url_helpers';
+import { fromQuery, toQuery } from '../components/shared/Links/url_helpers';
import { removeUndefinedProps } from '../context/UrlParamsContext/helpers';
-import { Projection } from '../../common/projections';
-import { pickKeys } from '../../common/utils/pick_keys';
import { useCallApi } from './useCallApi';
+import { useFetcher } from './useFetcher';
+import { useUrlParams } from './useUrlParams';
const getInitialData = (
filterNames: LocalUIFilterName[]
@@ -39,6 +39,7 @@ export function useLocalUIFilters({
filterNames: LocalUIFilterName[];
params?: Record;
}) {
+ const history = useHistory();
const { uiFilters, urlParams } = useUrlParams();
const callApi = useCallApi();
diff --git a/x-pack/plugins/apm/public/utils/history.ts b/x-pack/plugins/apm/public/utils/history.ts
deleted file mode 100644
index bd2203fe9206..000000000000
--- a/x-pack/plugins/apm/public/utils/history.ts
+++ /dev/null
@@ -1,17 +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.
- */
-
-import { createHashHistory } from 'history';
-
-// Make history singleton available across APM project
-// TODO: Explore using React context or hook instead?
-let history = createHashHistory();
-
-export const resetHistory = () => {
- history = createHashHistory();
-};
-
-export { history };
diff --git a/x-pack/plugins/apm/public/utils/testHelpers.tsx b/x-pack/plugins/apm/public/utils/testHelpers.tsx
index a750a9ea7af6..037da01c7446 100644
--- a/x-pack/plugins/apm/public/utils/testHelpers.tsx
+++ b/x-pack/plugins/apm/public/utils/testHelpers.tsx
@@ -26,6 +26,20 @@ import {
} from '../../typings/elasticsearch';
import { MockApmPluginContextWrapper } from '../context/ApmPluginContext/MockApmPluginContext';
+const originalConsoleWarn = console.warn; // eslint-disable-line no-console
+/**
+ * A dependency we're using is using deprecated react methods. Override the
+ * console to hide the warnings. These should go away when we switch to
+ * Elastic Charts
+ */
+export function disableConsoleWarning(messageToDisable: string) {
+ return jest.spyOn(console, 'warn').mockImplementation((message) => {
+ if (!message.startsWith(messageToDisable)) {
+ originalConsoleWarn(message);
+ }
+ });
+}
+
export function toJson(wrapper: ReactWrapper) {
return enzymeToJson(wrapper, {
noKey: true,
diff --git a/x-pack/plugins/observability/public/application/application.test.tsx b/x-pack/plugins/observability/public/application/application.test.tsx
index db7fca140be8..19995ed233e8 100644
--- a/x-pack/plugins/observability/public/application/application.test.tsx
+++ b/x-pack/plugins/observability/public/application/application.test.tsx
@@ -4,10 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { createMemoryHistory } from 'history';
import React from 'react';
-import { renderApp } from './';
import { Observable } from 'rxjs';
-import { CoreStart, AppMountParameters } from 'src/core/public';
+import { AppMountParameters, CoreStart } from 'src/core/public';
+import { renderApp } from './';
describe('renderApp', () => {
it('renders', () => {
@@ -19,6 +20,7 @@ describe('renderApp', () => {
} as unknown) as CoreStart;
const params = ({
element: window.document.createElement('div'),
+ history: createMemoryHistory(),
} as unknown) as AppMountParameters;
expect(() => {
diff --git a/x-pack/plugins/observability/public/application/index.tsx b/x-pack/plugins/observability/public/application/index.tsx
index 4c0147dc3cd5..fa691a7f41dd 100644
--- a/x-pack/plugins/observability/public/application/index.tsx
+++ b/x-pack/plugins/observability/public/application/index.tsx
@@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
-import { createHashHistory } from 'history';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
import { Route, Router, Switch } from 'react-router-dom';
@@ -52,10 +51,10 @@ function App() {
);
}
-export const renderApp = (core: CoreStart, { element }: AppMountParameters) => {
+export const renderApp = (core: CoreStart, { element, history }: AppMountParameters) => {
const i18nCore = core.i18n;
const isDarkMode = core.uiSettings.get('theme:darkMode');
- const history = createHashHistory();
+
ReactDOM.render(