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

[Logs / Metrics UI] Switch to scopedHistory and enhance useLinkProps hook #61667

Merged
merged 14 commits into from
Apr 22, 2020

Conversation

Kerry350
Copy link
Contributor

@Kerry350 Kerry350 commented Mar 27, 2020

Summary

This ticket primarily fixes #58112 (which switches us over to using scopedHistory), but there have also been two enhancements to the useLinkProps hook. I'll explain the changes in detail below:

Use scopedHistory

We now use the scopedHistory history instance that is passed in from platform as part of the AppMountParameters.

Use navigateToApp exclusively in useLinkProps

Previously the useLinkProps hook had two logic forks, one for internal links and one for external links. Now that we're using scopedHistory, and because navigateToApp just pushes to history under the hood, we can just make use of navigateToApp for all onClick handlers.

If navigating between two new platform applications there will be no page refresh (this is all NP apps now, not just navigating between logs and metrics).

Links to legacy apps will hard refresh, as expected.

Custom <Prompt /> implementation

This is the change that requires the most explanation. Previously we were using the <Prompt /> component from react-router to warn the user if they were going to lose source configuration form changes.

However, under the hood that react-router component uses history.block. history.block is now banned with scopedHistory, it will throw an Error and instead suggest the use of the onAppLeave mount parameter.

There are a couple of issues with using onAppLeave, A) it only handles switching between apps (not tabs of an app) and B) I found the behaviour a little buggy (sometimes the handler didn't fire switching apps).

I've therefore implemented a little bit of context, and a custom <Prompt /> component, to recreate the same behaviour the react-router component gave us.

As we have a centralised location that handles the generation of our link props with useLinkProps it was easy to block navigation if needed there.

Testing

  • Do links still work as expected? (Are the href attributes correct, encoded correctly etc. Do they work as expected when clicked?)

  • If you make changes to the source configuration form, and then try to navigate away, is a warning displayed?

@Kerry350 Kerry350 marked this pull request as ready for review April 2, 2020 15:36
@Kerry350 Kerry350 requested a review from a team as a code owner April 2, 2020 15:36
@Kerry350 Kerry350 added v7.8.0 v8.0.0 Feature:Logs UI Logs UI feature Feature:Metrics UI Metrics UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services labels Apr 2, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

Copy link
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

I'm taking a look at this today.

@Kerry350
Copy link
Contributor Author

Kerry350 commented Apr 6, 2020

@elasticmachine merge upstream

@Kerry350
Copy link
Contributor Author

@jasonrhodes Were there any changes needed on this one?

Copy link
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

Tested this thoroughly and wasn't able to find anything wrong with it at all, I was pretty bummed to be honest. Merge away. Sorry again for the delay!

@jasonrhodes
Copy link
Member

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

merge conflict between base and head

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Logs UI Logs UI feature Feature:Metrics UI Metrics UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Logs / Metrics UI] [NP followup] Fix navigation within the same app via the Kibana nav bar
4 participants