-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
- 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?
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(() => { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this 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(() => { |
There was a problem hiding this comment.
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.
…#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
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 tonavigateToUrl
(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 passnavigateToUrl('/app/some_other_app', { shouldNotCreateHref: true })
.QA/Regression testing
shouldNotCreateHref
)/
work as expectedChecklist