-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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] Move externalUrl helper out of React Context #78368
Conversation
- This uses a simple JS obj to store the enterpriseSearchUrl reference (once on plugin init) - This is vs. a class, which needs to be instantiated and passed around - the new obj can be imported flatly at any time - I also opted to not convert this into a Kea logic file - after some deliberation I decided against it because it felt really weird as one. It's not storing "state" per se that ever needs to be updated, it's simply a one-time set obj that contains helper functions. - There's also some hope that we might eventually not need this helper after the full migration, so the simpler it is to delete the better - Uses a getter & setter to ensure that we don't accidentally mutate said obj after initialization
- Mostly just consists of mocking externalUrl and importing that mock
TODO in next commit: Address kibana_header_actions
NOTE: this requires a temporary workaround of initializing externalUrl.enterpriseSearch in plugin.ts rather than in renderApp, because renderApp loads *after* the header app does. I plan on fixing this in a future PR so that setHeaderActionMenu is called AFTER renderApp has done loading (to ensure all the state in headerActions we need is available).
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 fantastic. So much cleaner! Thanks for doing this!
Hey Constance, general question. Why aren't we just storing external Url in AppLogic? |
AppLogic is product-specific (AS & WS contain their own separate AppLogic files), and the enterpriseSearchUrl / URL helpers are shared by multiple products. I mean, we certainly could store it in AppLogic if we wanted to, but at this point it's also just as easy to do an Also, for why I decided against giving it its own top-level Kea logic file:
|
Just thinking out loud. plugin.ts currently fetches all of the configuration data for Enterprise Search and passes it down via props to each one of the top level applications. WorkplaceSearch and AppSearch both receive the same initial configuration data and store it in their respective AppLogic stores. The data is then accessed from those stores by individual components. The data flows down in this case. With this new Singleton, data is no longer flowing down the tree. Since you're initializing it into a globally available store, you open up yourself to race conditions, like the one you're experiencing now. It's also creating yet another place to store configuration data. I'm just wondering out loud if it wouldn't be better to fetch the data in plugin.ts, and then pass it down to the individual applications (including headers) and have them use it as needed as we do with other configuration data. EDIT: So maybe even if the top level logic looked a little bare bones, it would at least be giving us some consistency, which might help with simplicity and understanding. |
That's not quite correct. It's not a race condition within the main app. It's a race condition within completely separate React apps. Even if we moved externalUrl to a logic file, we'd run into the exact same issue trying to obtain the That is the race condition that needs to be fixed, and which I'm working on/have a solution for locally (I just need these series of PRs to merge in first :). I'm happy to hop on a screenshare to demo it (or link to a remote branch here in a second, once I clean up my commit history). The solution that I came up with (and is the most straightforward, IMO) is moving the header app to be rendered by/after the main app. This is also a paradigm other plugins in the Kibana ecosystem use - you can see in the first result of that search that other plugins are passing the
The problem with this is it doesn't scale. What happens when we need more than just We're now essentially forced to pass down basically every single param/kibana dep into |
Great. That makes sense to me. Then the header would have access to all of our existing Logic stores, which sounds like an ideal solution. What I'm leery of is storing externalUrl in |
Maybe it will make more sense to me when you put up your next PR. |
Gotcha, that's definitely fair. I could potentially move it to (the new upcoming) KibanaLogic file, but it felt weird there for the following reasons:
For now though, this flat helper makes life a little bit nicer when generating our external URLs to the standalone UI - we just pass in route params to |
Sounds good. We'll see how things shakes out. |
Awesome, thanks a ton Jason as always for the sanity checks. I should have definitely mentioned I had the same hesitations earlier and went back and forth as well myself. In the end I'm definitely looking forward to the follow-up PR to this where we can just delete the whole folder 😁 |
) (#78497) * Add new/simpler externalUrl helper and initialize it on renderApp - This uses a simple JS obj to store the enterpriseSearchUrl reference (once on plugin init) - This is vs. a class, which needs to be instantiated and passed around - the new obj can be imported flatly at any time - I also opted to not convert this into a Kea logic file - after some deliberation I decided against it because it felt really weird as one. It's not storing "state" per se that ever needs to be updated, it's simply a one-time set obj that contains helper functions. - There's also some hope that we might eventually not need this helper after the full migration, so the simpler it is to delete the better - Uses a getter & setter to ensure that we don't accidentally mutate said obj after initialization * Update all components using get*SearchUrl helpers * Update tests for updated components - Mostly just consists of mocking externalUrl and importing that mock * Remove old ExternalUrl class/context TODO in next commit: Address kibana_header_actions * Update Workplace Search Header Actions to use new externalUrl helper NOTE: this requires a temporary workaround of initializing externalUrl.enterpriseSearch in plugin.ts rather than in renderApp, because renderApp loads *after* the header app does. I plan on fixing this in a future PR so that setHeaderActionMenu is called AFTER renderApp has done loading (to ensure all the state in headerActions we need is available). Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
Follow up to #78231 - This is the 3rd out of a set of 4 PRs focused on converting our current React Context (currently down to just KibanaContext!) into Kea/redux stores.
This PR focuses on the externalUrl helper (responsible for storing our public-facing Enterprise Search URLs, and helpers that form App Search vs Workplace Search URLs for example). However, it's a little unusual in that:
QA/Regression testing
/ws/search
)Checklist