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

[7.x] [APM] Make client-side routes static (#52574) #53479

Merged
merged 1 commit into from
Dec 18, 2019
Merged
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
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