Skip to content

Commit

Permalink
Removes APM custom breadcrumbs, leaves only chrome.breadcrumbs.set
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Jan 24, 2019
1 parent 9d33143 commit 02cf59f
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 103 deletions.
80 changes: 0 additions & 80 deletions x-pack/plugins/apm/public/components/app/Main/Breadcrumbs.js

This file was deleted.

58 changes: 58 additions & 0 deletions x-pack/plugins/apm/public/components/app/Main/UpdateBreadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 { Location } from 'history';
import { flatten } from 'lodash';
import React from 'react';
// @ts-ignore
import { withBreadcrumbs } from 'react-router-breadcrumbs-hoc';
import chrome from 'ui/chrome';
import { toQuery } from '../../shared/Links/url_helpers';
import { isSwitchSet, routes } from './routeConfig';

interface Props {
location: Location;
breadcrumbs: Array<{
breadcrumb: any;
match: {
url: string;
};
}>;
}

class UpdateBreadcrumbsComponent extends React.Component<Props> {
public updateHeaderBreadcrumbs() {
const { _g = '', kuery = '' } = toQuery(this.props.location.search);
const breadcrumbs = this.props.breadcrumbs.map(({ breadcrumb, match }) => ({
text: breadcrumb,
href: `#${match.url}?_g=${_g}&kuery=${kuery}`
}));

chrome.breadcrumbs.set(breadcrumbs);
}

public componentDidMount() {
this.updateHeaderBreadcrumbs();
}

public componentDidUpdate() {
this.updateHeaderBreadcrumbs();
}

public render() {
return null;
}
}

const flatRoutes = flatten(
routes.map(route => (isSwitchSet(route) ? route.routes : route))
);

const UpdateBreadcrumbs = withBreadcrumbs(flatRoutes)(
UpdateBreadcrumbsComponent
);

export { UpdateBreadcrumbs };
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/public/components/app/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { routes } from './routeConfig';
import ScrollToTopOnPathChange from './ScrollToTopOnPathChange';
import { px, units, unit, topNavHeight } from '../../../style/variables';
import ConnectRouterToRedux from '../../shared/ConnectRouterToRedux';
import { UpdateBreadcrumbs } from './UpdateBreadcrumbs';

const MainContainer = styled.div`
min-width: ${px(unit * 50)};
Expand All @@ -21,6 +22,7 @@ const MainContainer = styled.div`
export default function Main() {
return (
<MainContainer>
<UpdateBreadcrumbs />
<Route component={ConnectRouterToRedux} />
<Route component={ScrollToTopOnPathChange} />
{routes.map((route, i) => {
Expand Down
23 changes: 21 additions & 2 deletions x-pack/plugins/apm/public/components/app/Main/routeConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import React from 'react';
import { Redirect, RouteComponentProps } from 'react-router-dom';
import { Redirect, RouteComponentProps, RouteProps } from 'react-router-dom';
import { legacyDecodeURIComponent } from 'x-pack/plugins/apm/public/components/shared/Links/url_helpers';
import { StringMap } from '../../../../typings/common';
// @ts-ignore
Expand All @@ -25,6 +25,25 @@ interface RouteParams {
serviceName: string;
}

type BreadcrumbFunction = (args: BreadcrumbArgs) => string | null;

interface Route extends RouteProps {
switch?: never;
breadcrumb: string | BreadcrumbFunction | null;
}

interface SwitchSet {
switch: true;
routes: Route[];
}

type RoutesConfig = Array<Route | SwitchSet>;

// this function is used to tell TS what type the route is based on route.switch
export function isSwitchSet(route: Route | SwitchSet): route is SwitchSet {
return Boolean(route.switch);
}

const renderAsRedirectTo = (to: string) => {
return ({ location }: RouteComponentProps<RouteParams>) => (
<Redirect
Expand All @@ -36,7 +55,7 @@ const renderAsRedirectTo = (to: string) => {
);
};

export const routes = [
export const routes: RoutesConfig = [
{
exact: true,
path: '/',
Expand Down
12 changes: 0 additions & 12 deletions x-pack/plugins/apm/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import './style/global_overrides.css';

import template from './templates/index.html';
import Main from './components/app/Main';
import Breadcrumbs from './components/app/Main/Breadcrumbs';

import { initTimepicker } from './utils/timepicker';
import configureStore from './store/config/configureStore';
Expand All @@ -33,17 +32,6 @@ chrome.setRootTemplate(template);
const store = configureStore();

initTimepicker(history, store.dispatch).then(() => {
const showPluginBreadcrumbs = !chrome
.getUiSettingsClient()
.get('k7design', false);

ReactDOM.render(
<Router history={history}>
<Breadcrumbs showPluginBreadcrumbs={showPluginBreadcrumbs} />
</Router>,
document.getElementById('react-apm-breadcrumbs')
);

ReactDOM.render(
<I18nProvider>
<Provider store={store}>
Expand Down
10 changes: 2 additions & 8 deletions x-pack/plugins/apm/public/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<div ng-controller="TimePickerController">
<kbn-top-nav name="apm" config="topNavMenu">
<div data-transclude-slots>
<div data-transclude-slot="topLeftCorner">
<div id="react-apm-breadcrumbs"></div>
</div>
</div>
</kbn-top-nav>
<div ng-controller="TimePickerController" id="kibana-angular-template">
<kbn-top-nav name="apm" config="topNavMenu"></kbn-top-nav>
</div>

<div id="react-apm-root" style="overflow-x: auto;"></div>
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/public/utils/timepicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let currentInterval;
// hack to wait for angular template to be ready
const waitForAngularReady = new Promise(resolve => {
const checkInterval = setInterval(() => {
const hasElm = !!document.querySelector('#react-apm-breadcrumbs');
const hasElm = !!document.querySelector('#kibana-angular-template');
if (hasElm) {
clearInterval(checkInterval);
resolve();
Expand Down

0 comments on commit 02cf59f

Please sign in to comment.