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] Link handling / stop page reloads #58478

Merged
merged 36 commits into from
Mar 10, 2020

Conversation

Kerry350
Copy link
Contributor

@Kerry350 Kerry350 commented Feb 25, 2020

Summary

This PR fixes #58007. No internal links (metrics <-> metrics, logs <-> logs) will cause a page reload now. Some stray broken links (from the NP migration) have also been fixed. A longstanding bug with the getUptimeLink function has also been fixed (serialized arrays (e.g. host.ip) weren't being handled correctly).

Going into more detail: A useLinkProps hook has been introduced. My hope is that this can become the primary (hopefully only) way we handle links. This hook takes care of using either interal routing via the react-router history instance, or external routing. It will return a href attribute, plus onClick where relevant. This return value can be spread (...) wherever it's needed (generally with EUI components). It is app and basePath aware and will handle all of those niggles.

To acquire the correct href and onClick atrributes we just need to supply a LinkDescriptor. We had a lot of locations handling links, and in a lot of cases they were all doing something slightly different. By consolidating things we should be able to have a lot more trust in our linking (as they're hanled in the same way), and changes will be easier to make when necessary.

The only thing the hook doesn't handle is complex data types and complex encoding for search, e.g. using Rison encoding. This is because some apps use it, and some don't, so I've left this as something for the consumer to handle. It could very well be an option to the hook though, with a default. Ultimately, the hook expects search values to already be strings, or arrays of strings, and in a state that is ready to be handed off to urlUtils.encodeQuery.

Example of an internal link:

// Linking from within the metrics app, to the metrics app
useLinkProps({
  app: 'metrics',
  pathname: '/inventory'
});

This would return a space / basepath aware href, plus an onClick handler that will deal with react-router and pushing to the history instance.

Example of an external link:

// Logs making an ML link (here some Rison encoding is used)

const _a = encode({
  mlTimeSeriesExplorer: {
    entities: { 'event.dataset': partition },
  },
});

useLinkProps({
  app: 'ml',
  hash: '/timeseriesexplorer',
  search: { _a },
});

These changes affect links in:

  • Main navigation (inventory, settings etc)
  • Node context menu (the menu displayed with a node on the metrics snapshot page)
  • Log item actions menu in the log item flyout
  • Chart context menu on the metrics explorer page
  • Log rate / log categorisation Analyze in ML buttons
  • No indices / No data prompt buttons (e.g. "View source configuration")

@Kerry350
Copy link
Contributor Author

Kerry350 commented Mar 2, 2020

@elasticmachine merge upstream

@Kerry350 Kerry350 requested a review from a team March 2, 2020 13:17
@Kerry350 Kerry350 assigned Kerry350 and unassigned Kerry350 Mar 2, 2020
@Kerry350 Kerry350 added v7.7.0 v8.0.0 Feature:Logs UI Logs UI feature Feature:Metrics UI Metrics UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services labels Mar 2, 2020
@elasticmachine
Copy link
Contributor

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

@Kerry350 Kerry350 added the release_note:skip Skip the PR/issue when compiling release notes label Mar 2, 2020
@Kerry350
Copy link
Contributor Author

Kerry350 commented Mar 4, 2020

Note: #58943 will affect this PR ever so slightly (the one line that handles encoding, and potentially minor test changes). I'm going to try and preemptively make those changes on this branch, without that needing merged first.

Copy link
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

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

I really like the useLinkProps hook. It makes all the link generation a lot more readable and I expect it will prevent quite a number of mistakes in the future - great work 👏

One interesting behavior I noticed was that switching between the logs and metrics apps via the sidebar causes no reload, but clicking the "Host logs" entry in the waffle map node context menu does. 🤔 Any idea why that might be?

@Kerry350
Copy link
Contributor Author

Kerry350 commented Mar 5, 2020

@weltenwort Thanks for the review.

One interesting behavior I noticed was that switching between the logs and metrics apps via the sidebar causes no reload, but clicking the "Host logs" entry in the waffle map node context menu does. 🤔 Any idea why that might be?

The links in the sidebar receive special treatment in new platform allowing the nice no-refresh behaviour when switching between apps. However, with metrics and logs now technically being two separate apps, with independent App IDs, mount functions, and routers, the link rendered in the node context menu for logs is just a plain old <a /> and doesn't receive the same treatment.

If it's okay with you I'd like to look into fixing this when dealing with #58112?

Will start addressing the other feedback now 👍

@weltenwort
Copy link
Member

If it's okay with you I'd like to look into fixing this when dealing with #58112?

Certainly, I just wasn't aware of that separate issue 👍

@Kerry350
Copy link
Contributor Author

Kerry350 commented Mar 9, 2020

@weltenwort I've responded to all of the feedback now, this should be ready for another look. The app prop is now enforced, and the mechanism for differentiating between external links vs internal links has changed to treating links as external, and then enhancing as internal if they're the same (thanks for the suggestion, this worked well).

@Kerry350
Copy link
Contributor Author

Kerry350 commented Mar 9, 2020

(For #58943 I'm not going to try and preemptively make those changes here due to package / webpack alias changes etc. Instead, as there's only really a one line change (and whatever merge conflicts), I'll help with making them over there once this is merged).

Copy link
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

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

Thank you for including the explanatory comments. Together with the external/internal comparison it's quite straightforward to understand now. 👍 Nicely done 👏

x-pack/plugins/infra/public/hooks/use_link_props.tsx Outdated Show resolved Hide resolved
x-pack/plugins/infra/public/hooks/use_link_props.tsx Outdated Show resolved Hide resolved
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@Kerry350 Kerry350 merged commit 565dd25 into elastic:master Mar 10, 2020
Kerry350 added a commit to Kerry350/kibana that referenced this pull request Mar 10, 2020
* Add a hook for seamlessly handling onClick and href props of links, buttons etc

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Felix Stürmer <[email protected]>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 10, 2020
* master:
  [Logs / Metrics UI] Link handling / stop page reloads (elastic#58478)
  Add SavedObject management section registration in core  (elastic#59291)
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 10, 2020
* master:
  Add a retry to dashboard test for a sometimes slow async operation (elastic#59600)
  [Endpoint] Sample data generator for endpoint app (elastic#58936)
  [Vis Editor] Refactoring metrics axes (elastic#59135)
  [DOCS] Changed Discover app to Discover (elastic#59769)
  [Metrics Alerts] Add support for search query and groupBy on alerts (elastic#59388)
  Enhancement - EUICodeEditor for Visualize JSON  (elastic#58679)
  [ML] Transforms: Data grid fixes. (elastic#59538)
  [SIEM] Fix and consolidate handling of error responses in the client (elastic#59438)
  [Maps] convert tooltip classes to typescript (elastic#59589)
  [ML] Functional tests - re-activate date_nanos test (elastic#59649)
  Move canvas to use NP Expressions service (elastic#58387)
  Update misc dependencies (elastic#59542)
  [Unit Testing] Configure react-testing-library queries to use Kibana's data-test-subj instead of default data-testid (elastic#59445)
  [Console] Remove unused code (elastic#59554)
  [Logs / Metrics UI] Link handling / stop page reloads (elastic#58478)
  Add SavedObject management section registration in core  (elastic#59291)
Kerry350 added a commit that referenced this pull request Mar 10, 2020
* Add a hook for seamlessly handling onClick and href props of links, buttons etc

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Felix Stürmer <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Felix Stürmer <[email protected]>
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.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Logs / Metrics UI] [NP followup] Make sure application links don't cause a page reload
4 participants