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

Conversation

jasonrhodes
Copy link
Member

@jasonrhodes jasonrhodes commented Jan 24, 2019

Closes #25906

Summary

After much discussion in the comments of #25906, we decided to leave the APM breadcrumbs working the way they are for now until we can consider how to update navigation elements after K7 lands. In this PR I've done the following:

  • Removed the check for showPluginBreadcrumbs (this checked if K7 theme was on, which will always be on in 7.0+)
  • Renamed the <Breadcrumbs> component to <UpdateBreadcrumbs> as it is only now responsible for calling chrome.breadcrumbs.set() when the breadcrumb changes.
  • Converted breadcrumb component to TS
  • Added more robust types to the routeConfig file
  • Updated the HTML template to remove the elements that were only there for our custom breadcrumbs

screen shot 2019-01-24 at 1 57 52 pm

@jasonrhodes jasonrhodes requested a review from a team as a code owner January 24, 2019 18:58
type BreadcrumbFunction = (args: BreadcrumbArgs) => string | null;

interface Route extends RouteProps {
switch?: never;
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not sure this is the intention of the never type. should it be boolean instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

This key should "never" be present on this type. This is the end result of a ton of messing around with discriminated union stuff, we can chat...

Copy link
Member

@sorenlouv sorenlouv Jan 25, 2019

Choose a reason for hiding this comment

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

You can simplify this if you combine the switch and routes properties into just a switchRoutes prop (renamed for clarity). Then you can type it like:

interface Route extends RouteProps {
  switchRoutes?: Route[];
  breadcrumb?: string | BreadcrumbFunction | null;
}

type RoutesConfig = Route[];

If you want the union you can do this instead:

interface NormalRoute extends RouteProps {
  breadcrumb: string | BreadcrumbFunction | null;
}

interface SwitchRoute extends RouteProps {
  switchRoutes: Route[];
}

type Route = SwitchRoute | NormalRoute;
type RoutesConfig = Route[];

But I think the extra type narrowing is not really warranted.

Copy link
Member Author

Choose a reason for hiding this comment

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

The first one works, but I have to then be careful to update where we build out the routes to use the new key, and I was really hoping TS would allow me to keep it working the way it was already working. The second example here doesn't seem to work without the other stuff I added to tell TS about which type a route is.

If we're ok with changing the key to switchRoutes and just checking for its existence, I'm good with that.

Copy link
Member

@sorenlouv sorenlouv Jan 25, 2019

Choose a reason for hiding this comment

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

If you prefer the second solution, we can try working towards that. What do you mean "it doesn't work"?

If we're ok with changing the key to switchRoutes and just checking for its existence, I'm good with that.

Yes, I think this is the better solution, Typescript or not. Just didn't think about it back when I initially wrote it

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really care that much. :) I made the change to switchRoutes 👍

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.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@jasonrhodes
Copy link
Member Author

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@jasonrhodes jasonrhodes merged commit 06a5ce7 into elastic:master Jan 25, 2019
@jasonrhodes jasonrhodes deleted the remove-apm-breadcrumb branch January 25, 2019 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants