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

[Enterprise Search] DRY out createHref helper for navigateToUrl calls #78717

Merged
merged 5 commits into from
Sep 29, 2020

Conversation

cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Sep 29, 2020

Summary

Scotty pointed out that the navigateToUrl method added in #78513 felt weird dev-usage-wise, because it required a full /app/enterprise_search/workplace_search/something URL vs. just /something that we often use (thanks to our helpers).

I opted to solve this by DRYing out the createHref helper/logic we're using elsewhere in the codebase (see e329ed4) and adding it to navigateToUrl (see 9bee2e9). The subsequent PRs then update code & tests accordingly - I recommend following along by commit.

You should now be able to use navigateToUrl('/whatever') from within any Workplace Search file and it will automatically prepend the correct app route basename. If you want to turn this off for any reason (e.g., directing users outside of the Workplace Search plugin), you can pass navigateToUrl('/app/some_other_app', { shouldNotCreateHref: true }).

QA/Regression testing

  • Breadcrumbs still work as expected
  • Enterprise Search Overview links to products work as expected (these are using shouldNotCreateHref)
  • 404 pages linking back to / work as expected

Checklist

- that navigateToUrl will shortly also use

+ fix mockHistory type complaint
+ add param.history value, since we're technically supposed to be using Kibana's passed history over anything from useHistory
- navigateToUrl is now double-dipping createHref, so we update it to not do so
- remove useHistory in favor of grabbing history from KibanaLogic
- since we're now storing it there, we might as well grab it as well instead of passing in props?
@cee-chen cee-chen added Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Sep 29, 2020
@cee-chen cee-chen requested review from scottybollinger and a team September 29, 2020 03:50
afterMount: () => {
// On React Router navigation, clear previous flash messages and load any queued messages
const unlisten = props.history.listen(() => {
const unlisten = KibanaLogic.values.history.listen(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not super invested in this change (e5f8e15) and would love to get a confidence check from others if they like DRYing out props: param.history or nah. Happy to revert if nah!

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach, personally.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id value diff baseline
enterpriseSearch 250 +1 249

async chunks size

id value diff baseline
enterpriseSearch 477.1KB +4.6KB 472.5KB

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

Copy link
Contributor

@scottybollinger scottybollinger left a comment

Choose a reason for hiding this comment

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

This is great. Thanks for the clean history and helpful comments in the code.

afterMount: () => {
// On React Router navigation, clear previous flash messages and load any queued messages
const unlisten = props.history.listen(() => {
const unlisten = KibanaLogic.values.history.listen(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach, personally.

@cee-chen cee-chen merged commit e873848 into elastic:master Sep 29, 2020
@cee-chen cee-chen deleted the create-href branch September 29, 2020 15:20
cee-chen pushed a commit that referenced this pull request Sep 29, 2020
…#78717) (#78800)

* DRY out createHref helper
- that navigateToUrl will shortly also use

+ fix mockHistory type complaint

* KibanaLogic: Update navigateToUrl to use createHref helper

+ add param.history value, since we're technically supposed to be using Kibana's passed history over anything from useHistory

* Update breadcrumbs & eui link helpers w/ new KibanaLogic changes

- navigateToUrl is now double-dipping createHref, so we update it to not do so
- remove useHistory in favor of grabbing history from KibanaLogic

* [Optional?] Update FlashMessages to grab history from KibanaLogic

- since we're now storing it there, we might as well grab it as well instead of passing in props?

* [Misc] Fix failing tests due to react router mock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants