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

Removes APM custom breadcrumbs, leaves only chrome.breadcrumbs.set #29286

Merged
merged 3 commits into from
Jan 25, 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
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 { 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 => (route.switchRoutes ? route.switchRoutes : route))
);

const UpdateBreadcrumbs = withBreadcrumbs(flatRoutes)(
UpdateBreadcrumbsComponent
);

export { UpdateBreadcrumbs };
Copy link
Contributor

Choose a reason for hiding this comment

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

It's strange that this component's only purpose is its side effects. i feel like this is a case where store.subscribe is useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed that it's not the best. I thought about looking into changing it but I see we already do this with Main/LicenseChecker, so I left it alone.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with how you did it here - but if there is a better approach I think we should take that, and update LicenseChecker accordingly in another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I'm not sure if there is a way that's significantly better, sometimes at the top-level you just have some side-effect components (we definitely had these at my last job), and personally I'm fine with that if they're contained up there. If folks have a specific better idea and want to log something, go for it.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import React from 'react';
import { mount } from 'enzyme';
import { MemoryRouter } from 'react-router-dom';

import Breadcrumbs from '../Breadcrumbs';
import { toJson } from '../../../../utils/testHelpers';
import { UpdateBreadcrumbs } from '../UpdateBreadcrumbs';
import chrome from 'ui/chrome';

jest.mock(
'ui/chrome',
() => ({
breadcrumbs: {
set: () => {}
set: jest.fn()
},
getBasePath: () => `/some/base/path`,
getUiSettingsClient: () => {
Expand All @@ -37,17 +36,20 @@ jest.mock(
);

function expectBreadcrumbToMatchSnapshot(route) {
const wrapper = mount(
mount(
<MemoryRouter initialEntries={[`${route}?_g=myG&kuery=myKuery`]}>
<Breadcrumbs showPluginBreadcrumbs={true} />
<UpdateBreadcrumbs />
</MemoryRouter>
);
expect(
toJson(wrapper.find('.kuiLocalBreadcrumb').children())
).toMatchSnapshot();
expect(chrome.breadcrumbs.set).toHaveBeenCalledTimes(1);
expect(chrome.breadcrumbs.set.mock.calls[0][0]).toMatchSnapshot();
}

describe('Breadcrumbs', () => {
beforeEach(() => {
chrome.breadcrumbs.set.mockReset();
});

it('Homepage', () => {
expectBreadcrumbToMatchSnapshot('/');
});
Expand Down Expand Up @@ -77,13 +79,4 @@ describe('Breadcrumbs', () => {
'/:serviceName/transactions/request/my-transaction-name'
);
});

it('does not render breadcrumbs when showPluginBreadcrumbs = false', () => {
const wrapper = mount(
<MemoryRouter initialEntries={[`/?_g=myG&kuery=myKuery`]}>
<Breadcrumbs showPluginBreadcrumbs={false} />
</MemoryRouter>
);
expect(wrapper.find('.kuiLocalBreadcrumbs').exists()).toEqual(false);
});
});

This file was deleted.

Loading