Connect: Show resource search errors in the search bar#24520
Connect: Show resource search errors in the search bar#24520
Conversation
getClusterName used to not return the name of the cluster if there's only a single cluster present. Some places needed to get the cluster name no matter what, such as the modal with resource errors that will be added to ActionPicker.
* useSearchAttempts has been renamed to useActionAttempts * useActionAttempts returns resourceSearchAttempt in order to supply errors from ResourcesService.searchResources to ActionPicker.
We'll want to display error details in a modal. While the user interacts with the modal, we don't want to close the search bar and reset the results. So instead, we are going to force the search bar to stay open until the user closes the modal. This will use the lockOpen function from this commit.
gzdunek
left a comment
There was a problem hiding this comment.
The code looks really good, I will test it tomorrow.
avatus
left a comment
There was a problem hiding this comment.
this is really cool. its so concise, but also so informative. I REALLY like this, incredible job.
To fix this, I added a lockOpen function to the search context which takes a promise and prevents the modal from being closed for the duration of the promise.
Interesting solution, i dig it
|
Thanks Michael!
The inspiration for this comes from Ruby's |
This PR adds the foundation for error handling in the search bar. At the moment, it adds an extra item at the top of the search bar if a request for any resource fails.
This is suboptimal because it doesn't account for a bunch of different edge cases, for example requests to clusters with expired certs. This will be done in another PR since this one is quite large already.
Only 4 of the last 5 commits actually implement this. The rest are cleanup/refactoring commits which either make this feature possible or just clean up the code.
Screenshots
The most important pieces
At the heart of this PR is the change to
ResourcesService.prototype.searchResourcesin the commit "Refactor resource search to use Promise.allSettled". We used to simply return an array with all search result promises wrapped inPromise.all. This wasn't that great because if any of the requests failed, you wouldn't see the results at all.To work around this, we use
Promise.allSettledand then return a flattened array of results across different clusters. Another important piece is the customResourceSearchError. If a resource search request fails, this is the error that is returned. It contains extra fields, one which points at the relevant cluster and one which describes what kind of resource we were trying to fetch.Thanks to this, later in the UI we can extract those errors and tell the user what exactly went wrong.
Again, this is a very basic implementation which doesn't account for a plethora of edge cases, we'll deal with that in a separate PR.
Keeping the search bar open when inspecting errors
One issue I ran into is that we want the user to be able to inspect the details behind the errors in a modal. However, the search bar was written in a way where any click outside of the search bar is going to close it.
To fix this, I added a
lockOpenfunction to the search context which takes a promise and prevents the modal from being closed for the duration of the promise.