Skip to content

Commit

Permalink
[7.x] [APM] Make client-side routes static (#52574) (#53479)
Browse files Browse the repository at this point in the history
* [APM] Make client-side routes static

Turn `getRoutes` back into `routes` so we can just import it.

Checking for the service map being enabled isn't really necessary since we don't have any links to those routes and the backend routes are already flagged.
  • Loading branch information
smith authored Dec 18, 2019
1 parent 71330e7 commit 19c5778
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import { mount } from 'enzyme';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { UpdateBreadcrumbs } from './UpdateBreadcrumbs';
import { getRoutes } from './route_config';
import { ApmPluginContextValue } from '../../../context/ApmPluginContext';
import {
MockApmPluginContextWrapper,
mockApmPluginContextValue
mockApmPluginContextValue,
MockApmPluginContextWrapper
} from '../../../utils/testHelpers';
import { ApmPluginContextValue } from '../../../context/ApmPluginContext';
import { routes } from './route_config';
import { UpdateBreadcrumbs } from './UpdateBreadcrumbs';

const routes = getRoutes({ serviceMapEnabled: true });
const setBreadcrumbs = jest.fn();

function expectBreadcrumbToMatchSnapshot(route: string, params = '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,187 +42,175 @@ const renderAsRedirectTo = (to: string) => {
);
};

export function getRoutes({
serviceMapEnabled
}: {
serviceMapEnabled: boolean;
}): BreadcrumbRoute[] {
const routes: BreadcrumbRoute[] = [
{
exact: true,
path: '/',
render: renderAsRedirectTo('/services'),
breadcrumb: 'APM',
name: RouteName.HOME
},
{
exact: true,
path: '/services',
component: () => <Home tab="services" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.servicesTitle', {
defaultMessage: 'Services'
}),
name: RouteName.SERVICES
},
{
exact: true,
path: '/traces',
component: () => <Home tab="traces" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.tracesTitle', {
defaultMessage: 'Traces'
}),
name: RouteName.TRACES
},
{
exact: true,
path: '/settings',
render: renderAsRedirectTo('/settings/agent-configuration'),
breadcrumb: i18n.translate('xpack.apm.breadcrumb.listSettingsTitle', {
defaultMessage: 'Settings'
}),
name: RouteName.SETTINGS
},
{
exact: true,
path: '/settings/apm-indices',
component: () => (
<Settings>
<ApmIndices />
</Settings>
),
breadcrumb: i18n.translate('xpack.apm.breadcrumb.settings.indicesTitle', {
defaultMessage: 'Indices'
}),
name: RouteName.INDICES
},
{
exact: true,
path: '/settings/agent-configuration',
component: () => (
<Settings>
<AgentConfigurations />
</Settings>
),
breadcrumb: i18n.translate(
'xpack.apm.breadcrumb.settings.agentConfigurationTitle',
{
defaultMessage: 'Agent Configuration'
}
),
name: RouteName.AGENT_CONFIGURATION
},
{
exact: true,
path: '/services/:serviceName',
breadcrumb: ({ match }) => match.params.serviceName,
render: (props: RouteComponentProps<RouteParams>) =>
renderAsRedirectTo(
`/services/${props.match.params.serviceName}/transactions`
)(props),
name: RouteName.SERVICE
},
// errors
{
exact: true,
path: '/services/:serviceName/errors/:groupId',
component: ErrorGroupDetails,
breadcrumb: ({ match }) => match.params.groupId,
name: RouteName.ERROR
},
{
exact: true,
path: '/services/:serviceName/errors',
component: () => <ServiceDetails tab="errors" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.errorsTitle', {
defaultMessage: 'Errors'
}),
name: RouteName.ERRORS
},
// transactions
{
exact: true,
path: '/services/:serviceName/transactions',
component: () => <ServiceDetails tab="transactions" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.transactionsTitle', {
defaultMessage: 'Transactions'
}),
name: RouteName.TRANSACTIONS
},
// metrics
{
exact: true,
path: '/services/:serviceName/metrics',
component: () => <ServiceDetails tab="metrics" />,
breadcrumb: metricsBreadcrumb,
name: RouteName.METRICS
},
// service nodes, only enabled for java agents for now
{
exact: true,
path: '/services/:serviceName/nodes',
component: () => <ServiceDetails tab="nodes" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.nodesTitle', {
defaultMessage: 'JVMs'
}),
name: RouteName.SERVICE_NODES
},
// node metrics
{
exact: true,
path: '/services/:serviceName/nodes/:serviceNodeName/metrics',
component: () => <ServiceNodeMetrics />,
breadcrumb: ({ location }) => {
const { serviceNodeName } = resolveUrlParams(location, {});
export const routes: BreadcrumbRoute[] = [
{
exact: true,
path: '/',
render: renderAsRedirectTo('/services'),
breadcrumb: 'APM',
name: RouteName.HOME
},
{
exact: true,
path: '/services',
component: () => <Home tab="services" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.servicesTitle', {
defaultMessage: 'Services'
}),
name: RouteName.SERVICES
},
{
exact: true,
path: '/traces',
component: () => <Home tab="traces" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.tracesTitle', {
defaultMessage: 'Traces'
}),
name: RouteName.TRACES
},
{
exact: true,
path: '/settings',
render: renderAsRedirectTo('/settings/agent-configuration'),
breadcrumb: i18n.translate('xpack.apm.breadcrumb.listSettingsTitle', {
defaultMessage: 'Settings'
}),
name: RouteName.SETTINGS
},
{
exact: true,
path: '/settings/apm-indices',
component: () => (
<Settings>
<ApmIndices />
</Settings>
),
breadcrumb: i18n.translate('xpack.apm.breadcrumb.settings.indicesTitle', {
defaultMessage: 'Indices'
}),
name: RouteName.INDICES
},
{
exact: true,
path: '/settings/agent-configuration',
component: () => (
<Settings>
<AgentConfigurations />
</Settings>
),
breadcrumb: i18n.translate(
'xpack.apm.breadcrumb.settings.agentConfigurationTitle',
{
defaultMessage: 'Agent Configuration'
}
),
name: RouteName.AGENT_CONFIGURATION
},
{
exact: true,
path: '/services/:serviceName',
breadcrumb: ({ match }) => match.params.serviceName,
render: (props: RouteComponentProps<RouteParams>) =>
renderAsRedirectTo(
`/services/${props.match.params.serviceName}/transactions`
)(props),
name: RouteName.SERVICE
},
// errors
{
exact: true,
path: '/services/:serviceName/errors/:groupId',
component: ErrorGroupDetails,
breadcrumb: ({ match }) => match.params.groupId,
name: RouteName.ERROR
},
{
exact: true,
path: '/services/:serviceName/errors',
component: () => <ServiceDetails tab="errors" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.errorsTitle', {
defaultMessage: 'Errors'
}),
name: RouteName.ERRORS
},
// transactions
{
exact: true,
path: '/services/:serviceName/transactions',
component: () => <ServiceDetails tab="transactions" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.transactionsTitle', {
defaultMessage: 'Transactions'
}),
name: RouteName.TRANSACTIONS
},
// metrics
{
exact: true,
path: '/services/:serviceName/metrics',
component: () => <ServiceDetails tab="metrics" />,
breadcrumb: metricsBreadcrumb,
name: RouteName.METRICS
},
// service nodes, only enabled for java agents for now
{
exact: true,
path: '/services/:serviceName/nodes',
component: () => <ServiceDetails tab="nodes" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.nodesTitle', {
defaultMessage: 'JVMs'
}),
name: RouteName.SERVICE_NODES
},
// node metrics
{
exact: true,
path: '/services/:serviceName/nodes/:serviceNodeName/metrics',
component: () => <ServiceNodeMetrics />,
breadcrumb: ({ location }) => {
const { serviceNodeName } = resolveUrlParams(location, {});

if (serviceNodeName === SERVICE_NODE_NAME_MISSING) {
return UNIDENTIFIED_SERVICE_NODES_LABEL;
}
if (serviceNodeName === SERVICE_NODE_NAME_MISSING) {
return UNIDENTIFIED_SERVICE_NODES_LABEL;
}

return serviceNodeName || '';
},
name: RouteName.SERVICE_NODE_METRICS
return serviceNodeName || '';
},
{
exact: true,
path: '/services/:serviceName/transactions/view',
component: TransactionDetails,
breadcrumb: ({ location }) => {
const query = toQuery(location.search);
return query.transactionName as string;
},
name: RouteName.TRANSACTION_NAME
name: RouteName.SERVICE_NODE_METRICS
},
{
exact: true,
path: '/services/:serviceName/transactions/view',
component: TransactionDetails,
breadcrumb: ({ location }) => {
const query = toQuery(location.search);
return query.transactionName as string;
},
{
exact: true,
path: '/link-to/trace/:traceId',
component: TraceLink,
breadcrumb: null,
name: RouteName.LINK_TO_TRACE
}
];
name: RouteName.TRANSACTION_NAME
},
{
exact: true,
path: '/link-to/trace/:traceId',
component: TraceLink,
breadcrumb: null,
name: RouteName.LINK_TO_TRACE
},

if (serviceMapEnabled) {
routes.push(
{
exact: true,
path: '/service-map',
component: () => <Home tab="service-map" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map'
}),
name: RouteName.SERVICE_MAP
},
{
exact: true,
path: '/services/:serviceName/service-map',
component: () => <ServiceDetails tab="service-map" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map'
}),
name: RouteName.SINGLE_SERVICE_MAP
}
);
{
exact: true,
path: '/service-map',
component: () => <Home tab="service-map" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map'
}),
name: RouteName.SERVICE_MAP
},
{
exact: true,
path: '/services/:serviceName/service-map',
component: () => <ServiceDetails tab="service-map" />,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map'
}),
name: RouteName.SINGLE_SERVICE_MAP
}

return routes;
}
];
Loading

0 comments on commit 19c5778

Please sign in to comment.