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

[APM] Get service name from context for alert flyout #104103

Merged
merged 3 commits into from
Jul 9, 2021

Conversation

dgieselaar
Copy link
Member

Closes #101837.

Instead of using useParams to get the service name, introduce a useServiceName hook that is used by useApmServiceContext, in which matchPath and apmRouteConfig are used. This removes the necessity of the component calling useApmServiceContext to be a child of a service view route.

@dgieselaar dgieselaar added release_note:fix v8.0.0 v7.14.0 auto-backport Deprecated - use backport:version if exact versions are needed v7.15.0 labels Jul 1, 2021
@dgieselaar dgieselaar requested a review from a team as a code owner July 1, 2021 14:00
@botelastic botelastic bot added the Team:APM All issues that need APM UI Team support label Jul 1, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:apm)

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

lgtm!
It seems we have at least 4 ways to access serviceName (and probably other path params):

Can we make this more consistent? I'm hoping that going forward we can at least get rid of useUrlParams when we tackle #51963

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

lgtm!
It seems we have at least 4 ways to access serviceName (and probably other path params):

Can we make this more consistent going forward? I'm hoping that we can at least get rid of useUrlParams when we tackle #51963

export function useServiceName(): string | undefined {
const history = useHistory();
for (const config of apmRouteConfig) {
const match = matchPath<{ serviceName?: string }>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to use useRouteMatch? I don't think we would need to iterate through the routes if we did that. It's independent of any route component and just uses the current path.

Copy link
Member Author

Choose a reason for hiding this comment

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

useRouteMatch() returns an empty match object:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you have to give it a path like useRouteMatch('/app/apm/services/:serviceName/*')? I thought that's how it worked.

Copy link
Member

Choose a reason for hiding this comment

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

I think in this case we only know the actual pathname (history.location.pathname), not the route since it's a generic hook that can be called anywhere in the application.

Copy link
Member

Choose a reason for hiding this comment

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

... but seeing your example, if it allows wildcards it might be different.

Copy link
Member

Choose a reason for hiding this comment

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

nvm. It seems like useRouteMatch simply uses https://github.com/pillarjs/path-to-regexp under the hood. What @smith is suggesting makes sense

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've changed it to useRouteMatch('/services/:serviceName'), which seems to work fine.

@dgieselaar
Copy link
Member Author

Can we make this more consistent going forward? I'm hoping that we can at least get rid of useUrlParams when we tackle #51963

Yeah, I'd prefer to do it there and do the minimal changes now, as we're past FF.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
apm 1565 1566 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 4.3MB 4.3MB +691.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.14
7.x

The backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Jul 9, 2021
Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>
kibanamachine added a commit that referenced this pull request Jul 9, 2021
Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:fix Team:APM All issues that need APM UI Team support v7.14.0 v7.15.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] useParams not working in alert flyout components (service is always "All")
5 participants