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

Update error in AppView to use ErrorAlert. #4199

Merged
merged 2 commits into from
Feb 2, 2022

Conversation

absoludity
Copy link
Contributor

@absoludity absoludity commented Feb 1, 2022

Signed-off-by: Michael Nelson minelson@vmware.com

Description of the change

Initially was just to update the error displayed in the AppView to use the ErrorAlert component, but the ErrorAlert component didn't currently support child elements like the old one did, which the AppView uses. So after chatting with Rafa, I've updated that component to take the error as a prop allowing the children to be normal react nodes.

Benefits

Before:
appview-error-before

After:
appview-error-after

Clicking on the "Try again" does what it always did, re-issuing the request and rendering the view when it succeeds.

Possible drawbacks

Applicable issues

Additional information

Signed-off-by: Michael Nelson <minelson@vmware.com>
dispatch(errorApp(new FetchError(e.message)));
dispatch(
errorApp(
e instanceof Error
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've just followed the pattern which you'd done elsewhere Rafa, but wondering when e would not be an instance of Error? Guessing you saw something else, but it still had an e.message, so confused?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't really remember, probably due to the any in } catch (e: any) {. But given that it is a catch, I'm with you, can't think of a situation where e would not be an Error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, I'll update both this one and the one you'd added before landing.

Comment on lines -10 to -13
it("should render string messages", () => {
const wrapper = mount(<ErrorAlert>foo</ErrorAlert>);
expect(wrapper.text()).toContain("foo");
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment below on the interface for more info why I thought to remove this.

@@ -8,7 +8,8 @@ import { CustomError } from "shared/types";
import "./ErrorAlert.css";

export interface IErrorAlert {
children: CustomError | Error | string;
error: CustomError | Error;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When changing to an error prop, given that this is an ErrorAlert component (ie. something that should be used when you have an error), it no longer seemed to make sense to support a plain string here since (a) why use an ErrorAlert in that case, and (b) even if you wanted to, you could put the string as the child.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There could be use cases where we need to show a plain text message as an error on UI (red, etc.), but agree with you that it can be done with (b).

@castelblanque
Copy link
Collaborator

Awesome, thanks!

Comment on lines 131 to 133
e instanceof Error
? new FetchError("Unable to get installed package", [e])
: new FetchError(`Unable to get installed package: ${e.message}`),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
e instanceof Error
? new FetchError("Unable to get installed package", [e])
: new FetchError(`Unable to get installed package: ${e.message}`),
new FetchError("Unable to get installed package", [e])

Signed-off-by: Michael Nelson <minelson@vmware.com>
@absoludity absoludity merged commit 8f2f6ca into main Feb 2, 2022
@absoludity absoludity deleted the 3695-check-installed-pkg-details-2 branch February 2, 2022 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update ErrorAlert component to accept other children for rendering (in Appview)
2 participants