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

Move remaining uses of serviceName away from urlParams #77248

Merged
merged 7 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ const CoreVitalsThresholds = {
export function CoreVitals() {
const { urlParams, uiFilters } = useUrlParams();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this to make the distinction between path params (that we get from react-router) and query params clear?

Suggested change
const { urlParams, uiFilters } = useUrlParams();
const { queryParams, uiFilters } = useQueryParams();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with doing that but we would have to change it in a hell of a lot of places. I'd prefer doing that change in the next round of changes and leaving it for now.


const { start, end, serviceName } = urlParams;
const { start, end } = urlParams;

const { data, status } = useFetcher(
(callApmApi) => {
const { serviceName } = uiFilters;
if (start && end && serviceName) {
return callApmApi({
pathname: '/api/apm/rum-client/web-core-vitals',
Expand All @@ -34,7 +35,7 @@ export function CoreVitals() {
}
return Promise.resolve(null);
},
[start, end, serviceName, uiFilters]
[start, end, uiFilters]
);

const { lcp, lcpRanks, fid, fidRanks, cls, clsRanks } = data || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export function Buttons({
}: ButtonsProps) {
const { core } = useApmPluginContext();
const { basePath } = core.http;
// The params may contain the service name. We want to use the selected node's
// service name in the button URLs, so make a copy and set the
// `serviceName` property.
const urlParams = { ...useUrlParams().urlParams } as APMQueryParams;
urlParams.serviceName = selectedNodeServiceName;
const urlParams = useUrlParams().urlParams as APMQueryParams;

const detailsUrl = getAPMHref({
basePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import { EuiSuperDatePicker } from '@elastic/eui';
import { isEmpty, isEqual, pickBy } from 'lodash';
import React from 'react';
import { useHistory } from 'react-router-dom';
import { useHistory, useLocation } from 'react-router-dom';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing our useLocation here with the one from react-router-dom. This is also fixed in #76343 but CSM is not using our old location provider.

import { UI_SETTINGS } from '../../../../../../../src/plugins/data/common';
import { useApmPluginContext } from '../../../hooks/useApmPluginContext';
import { useLocation } from '../../../hooks/useLocation';
import { useUrlParams } from '../../../hooks/useUrlParams';
import { clearCache } from '../../../services/rest/callApi';
import { fromQuery, toQuery } from '../Links/url_helpers';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { EuiTitle } from '@elastic/eui';
import { EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui';
import theme from '@elastic/eui/dist/eui_theme_light.json';
import { i18n } from '@kbn/i18n';
import React, { useCallback } from 'react';
import { EuiPanel } from '@elastic/eui';
import { EuiSpacer } from '@elastic/eui';
import { useParams } from 'react-router-dom';
import { asPercent } from '../../../../../common/utils/formatters';
import { useChartsSync } from '../../../../hooks/useChartsSync';
import { useFetcher } from '../../../../hooks/useFetcher';
Expand All @@ -22,16 +21,11 @@ const tickFormatY = (y?: number) => {
};

export function ErroneousTransactionsRateChart() {
const { serviceName } = useParams<{ serviceName?: string }>();
const { urlParams, uiFilters } = useUrlParams();
const syncedChartsProps = useChartsSync();

const {
serviceName,
start,
end,
transactionType,
transactionName,
} = urlParams;
const { start, end, transactionType, transactionName } = urlParams;

const { data } = useFetcher(() => {
if (serviceName && start && end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { renderHook } from '@testing-library/react-hooks';
import theme from '@elastic/eui/dist/eui_theme_light.json';
import * as useFetcherModule from './useFetcher';
import { useAvgDurationByBrowser } from './useAvgDurationByBrowser';
import React, { ReactNode } from 'react';
import { MemoryRouter } from 'react-router-dom';

function Wrapper({ children }: { children?: ReactNode }) {
return <MemoryRouter>{children}</MemoryRouter>;
}

describe('useAvgDurationByBrowser', () => {
it('returns data', () => {
Expand All @@ -19,7 +25,9 @@ describe('useAvgDurationByBrowser', () => {
refetch: () => {},
status: 'success' as useFetcherModule.FETCH_STATUS,
});
const { result } = renderHook(() => useAvgDurationByBrowser());
const { result } = renderHook(() => useAvgDurationByBrowser(), {
wrapper: Wrapper,
});

expect(result.current.data).toEqual([
{
Expand Down
10 changes: 6 additions & 4 deletions x-pack/plugins/apm/public/hooks/useAvgDurationByBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/

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

function toTimeSeries(data?: AvgDurationByBrowserAPIResponse): TimeSeries[] {
if (!data) {
Expand All @@ -27,8 +28,9 @@ function toTimeSeries(data?: AvgDurationByBrowserAPIResponse): TimeSeries[] {
}

export function useAvgDurationByBrowser() {
const { serviceName } = useParams<{ serviceName?: string }>();
const {
urlParams: { serviceName, start, end, transactionName },
urlParams: { start, end, transactionName },
uiFilters,
} = useUrlParams();

Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/apm/public/hooks/useAvgDurationByCountry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { useParams } from 'react-router-dom';
import { useFetcher } from './useFetcher';
import { useUrlParams } from './useUrlParams';

export function useAvgDurationByCountry() {
const { serviceName } = useParams<{ serviceName?: string }>();
const {
urlParams: { serviceName, start, end, transactionName },
urlParams: { start, end, transactionName },
uiFilters,
} = useUrlParams();

Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/public/hooks/useTransactionBreakdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useParams } from 'react-router-dom';
import { useFetcher } from './useFetcher';
import { useUrlParams } from './useUrlParams';

export function useTransactionBreakdown() {
const { serviceName } = useParams<{ serviceName?: string }>();
const {
urlParams: { serviceName, start, end, transactionName, transactionType },
urlParams: { start, end, transactionName, transactionType },
uiFilters,
} = useUrlParams();

Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/public/hooks/useTransactionCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*/

import { useMemo } from 'react';
import { useParams } from 'react-router-dom';
import { getTransactionCharts } from '../selectors/chartSelectors';
import { useFetcher } from './useFetcher';
import { useUrlParams } from './useUrlParams';

export function useTransactionCharts() {
const { serviceName } = useParams<{ serviceName?: string }>();
const {
urlParams: { serviceName, transactionType, start, end, transactionName },
urlParams: { transactionType, start, end, transactionName },
uiFilters,
} = useUrlParams();

Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/apm/public/hooks/useTransactionDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IUrlParams } from '../context/UrlParamsContext/types';
import { useFetcher } from './useFetcher';
import { useUiFilters } from '../context/UrlParamsContext';
import { useParams } from 'react-router-dom';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { TransactionDistributionAPIResponse } from '../../server/lib/transactions/distribution';
import { useUiFilters } from '../context/UrlParamsContext';
import { IUrlParams } from '../context/UrlParamsContext/types';
import { useFetcher } from './useFetcher';

const INITIAL_DATA = {
buckets: [] as TransactionDistributionAPIResponse['buckets'],
Expand All @@ -17,8 +18,8 @@ const INITIAL_DATA = {
};

export function useTransactionDistribution(urlParams: IUrlParams) {
const { serviceName } = useParams<{ serviceName?: string }>();
const {
serviceName,
start,
end,
transactionType,
Expand Down