Skip to content

Commit c758bea

Browse files
authored
Move remaining uses of serviceName away from urlParams (#77248) (#77428)
* Move remaining uses of serviceName away from urlParams There were a few of these that were either missed or lost in merge conflict resolution. I went through everything that's used as a path parameter and made sure it wasn't being used anywhere with `urlParams`. Previously none of the charts were working, now they all are. Looks like #67791 introduced a find/replace change that broke APM's e2e tests. This reverts that change.
1 parent e88a4cd commit c758bea

File tree

14 files changed

+44
-38
lines changed

14 files changed

+44
-38
lines changed

x-pack/plugins/apm/e2e/cypress/support/step_definitions/apm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const DEFAULT_TIMEOUT = 60 * 1000;
1212

1313
Given(`a user browses the APM UI application`, () => {
1414
// open service overview page
15-
loginAndWaitForPage(`/app/apm#/services`, {
15+
loginAndWaitForPage(`/app/apm/services`, {
1616
from: '2020-06-01T14:59:32.686Z',
1717
to: '2020-06-16T16:59:36.219Z',
1818
});

x-pack/plugins/apm/e2e/cypress/support/step_definitions/rum/rum_dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Given(`a user browses the APM UI application for RUM Data`, () => {
1515
// open service overview page
1616
const RANGE_FROM = 'now-24h';
1717
const RANGE_TO = 'now';
18-
loginAndWaitForPage(`/app/apm#/rum-preview`, {
18+
loginAndWaitForPage(`/app/apm/rum-preview`, {
1919
from: RANGE_FROM,
2020
to: RANGE_TO,
2121
});

x-pack/plugins/apm/public/components/app/RumDashboard/CoreVitals/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const CoreVitalsThresholds = {
2020
export function CoreVitals() {
2121
const { urlParams, uiFilters } = useUrlParams();
2222

23-
const { start, end, serviceName } = urlParams;
23+
const { start, end } = urlParams;
2424

2525
const { data, status } = useFetcher(
2626
(callApmApi) => {
27+
const { serviceName } = uiFilters;
2728
if (start && end && serviceName) {
2829
return callApmApi({
2930
pathname: '/api/apm/rum-client/web-core-vitals',
@@ -34,7 +35,7 @@ export function CoreVitals() {
3435
}
3536
return Promise.resolve(null);
3637
},
37-
[start, end, serviceName, uiFilters]
38+
[start, end, uiFilters]
3839
);
3940

4041
const { lcp, lcpRanks, fid, fidRanks, cls, clsRanks } = data || {};

x-pack/plugins/apm/public/components/app/ServiceMap/Popover/Buttons.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ export function Buttons({
2525
}: ButtonsProps) {
2626
const { core } = useApmPluginContext();
2727
const { basePath } = core.http;
28-
// The params may contain the service name. We want to use the selected node's
29-
// service name in the button URLs, so make a copy and set the
30-
// `serviceName` property.
31-
const urlParams = { ...useUrlParams().urlParams } as APMQueryParams;
32-
urlParams.serviceName = selectedNodeServiceName;
28+
const urlParams = useUrlParams().urlParams as APMQueryParams;
3329

3430
const detailsUrl = getAPMHref({
3531
basePath,

x-pack/plugins/apm/public/components/shared/DatePicker/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import { EuiSuperDatePicker } from '@elastic/eui';
88
import { isEmpty, isEqual, pickBy } from 'lodash';
99
import React from 'react';
10-
import { useHistory } from 'react-router-dom';
10+
import { useHistory, useLocation } from 'react-router-dom';
1111
import { UI_SETTINGS } from '../../../../../../../src/plugins/data/common';
1212
import { useApmPluginContext } from '../../../hooks/useApmPluginContext';
13-
import { useLocation } from '../../../hooks/useLocation';
1413
import { useUrlParams } from '../../../hooks/useUrlParams';
1514
import { clearCache } from '../../../services/rest/callApi';
1615
import { fromQuery, toQuery } from '../Links/url_helpers';

x-pack/plugins/apm/public/components/shared/charts/ErroneousTransactionsRateChart/index.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import { EuiTitle } from '@elastic/eui';
6+
import { EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui';
77
import theme from '@elastic/eui/dist/eui_theme_light.json';
88
import { i18n } from '@kbn/i18n';
99
import React, { useCallback } from 'react';
10-
import { EuiPanel } from '@elastic/eui';
11-
import { EuiSpacer } from '@elastic/eui';
10+
import { useParams } from 'react-router-dom';
1211
import { asPercent } from '../../../../../common/utils/formatters';
1312
import { useChartsSync } from '../../../../hooks/useChartsSync';
1413
import { useFetcher } from '../../../../hooks/useFetcher';
@@ -22,16 +21,11 @@ const tickFormatY = (y?: number) => {
2221
};
2322

2423
export function ErroneousTransactionsRateChart() {
24+
const { serviceName } = useParams<{ serviceName?: string }>();
2525
const { urlParams, uiFilters } = useUrlParams();
2626
const syncedChartsProps = useChartsSync();
2727

28-
const {
29-
serviceName,
30-
start,
31-
end,
32-
transactionType,
33-
transactionName,
34-
} = urlParams;
28+
const { start, end, transactionType, transactionName } = urlParams;
3529

3630
const { data } = useFetcher(() => {
3731
if (serviceName && start && end) {

x-pack/plugins/apm/public/hooks/useAvgDurationByBrowser.test.ts renamed to x-pack/plugins/apm/public/hooks/useAvgDurationByBrowser.test.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import { renderHook } from '@testing-library/react-hooks';
88
import theme from '@elastic/eui/dist/eui_theme_light.json';
99
import * as useFetcherModule from './useFetcher';
1010
import { useAvgDurationByBrowser } from './useAvgDurationByBrowser';
11+
import React, { ReactNode } from 'react';
12+
import { MemoryRouter } from 'react-router-dom';
13+
14+
function Wrapper({ children }: { children?: ReactNode }) {
15+
return <MemoryRouter>{children}</MemoryRouter>;
16+
}
1117

1218
describe('useAvgDurationByBrowser', () => {
1319
it('returns data', () => {
@@ -19,7 +25,9 @@ describe('useAvgDurationByBrowser', () => {
1925
refetch: () => {},
2026
status: 'success' as useFetcherModule.FETCH_STATUS,
2127
});
22-
const { result } = renderHook(() => useAvgDurationByBrowser());
28+
const { result } = renderHook(() => useAvgDurationByBrowser(), {
29+
wrapper: Wrapper,
30+
});
2331

2432
expect(result.current.data).toEqual([
2533
{

x-pack/plugins/apm/public/hooks/useAvgDurationByBrowser.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66

77
import theme from '@elastic/eui/dist/eui_theme_light.json';
8-
import { useFetcher } from './useFetcher';
9-
import { useUrlParams } from './useUrlParams';
8+
import { useParams } from 'react-router-dom';
9+
import { getVizColorForIndex } from '../../common/viz_colors';
1010
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1111
import { AvgDurationByBrowserAPIResponse } from '../../server/lib/transactions/avg_duration_by_browser';
1212
import { TimeSeries } from '../../typings/timeseries';
13-
import { getVizColorForIndex } from '../../common/viz_colors';
13+
import { useFetcher } from './useFetcher';
14+
import { useUrlParams } from './useUrlParams';
1415

1516
function toTimeSeries(data?: AvgDurationByBrowserAPIResponse): TimeSeries[] {
1617
if (!data) {
@@ -27,8 +28,9 @@ function toTimeSeries(data?: AvgDurationByBrowserAPIResponse): TimeSeries[] {
2728
}
2829

2930
export function useAvgDurationByBrowser() {
31+
const { serviceName } = useParams<{ serviceName?: string }>();
3032
const {
31-
urlParams: { serviceName, start, end, transactionName },
33+
urlParams: { start, end, transactionName },
3234
uiFilters,
3335
} = useUrlParams();
3436

x-pack/plugins/apm/public/hooks/useAvgDurationByCountry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
6+
import { useParams } from 'react-router-dom';
77
import { useFetcher } from './useFetcher';
88
import { useUrlParams } from './useUrlParams';
99

1010
export function useAvgDurationByCountry() {
11+
const { serviceName } = useParams<{ serviceName?: string }>();
1112
const {
12-
urlParams: { serviceName, start, end, transactionName },
13+
urlParams: { start, end, transactionName },
1314
uiFilters,
1415
} = useUrlParams();
1516

x-pack/plugins/apm/public/hooks/useTransactionBreakdown.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { useParams } from 'react-router-dom';
78
import { useFetcher } from './useFetcher';
89
import { useUrlParams } from './useUrlParams';
910

1011
export function useTransactionBreakdown() {
12+
const { serviceName } = useParams<{ serviceName?: string }>();
1113
const {
12-
urlParams: { serviceName, start, end, transactionName, transactionType },
14+
urlParams: { start, end, transactionName, transactionType },
1315
uiFilters,
1416
} = useUrlParams();
1517

0 commit comments

Comments
 (0)