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] Fix bug in Add Schema modal #104024

Merged

Conversation

scottybollinger
Copy link
Contributor

Summary

This PR fixes a bug where an error passed from the server was not rendering and was causing the UI to hang. The problem is that the body property was missed in the error object.

image

closes https://github.com/elastic/workplace-search-team/issues/1784

This PR fixes a bug where an error passed from the server was not rendering and was causing the UI to hang. The problem is that the `body` property was missed in the error object.
@scottybollinger scottybollinger added release_note:skip Skip the PR/issue when compiling release notes v7.14.0 auto-backport Deprecated - use backport:version if exact versions are needed labels Jun 30, 2021
@scottybollinger scottybollinger requested a review from a team June 30, 2021 22:05
@scottybollinger scottybollinger requested a review from a team July 1, 2021 13:20
@@ -31,12 +31,13 @@ interface Options {
isQueued?: boolean;
}

// TODO I know our error messages from the BE are not i18n-ized but should this be?
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently none of our error messages from the BE are localized, but if this one is in public/ it has access to i18n, so we should likely i18n it just in case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also want to add it wouldn't be my preference to export this const. I'd just check for the static 'An unexpected error occurred' string in the schema logic file. It's short, easy to read, and gives developers human-readable context over a variable that means nothing if they don't open another file to check it

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait, sorry, just saw we're using it in the actual logic file, not just the test. Hm, sec

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll i18n this

Copy link
Contributor

@yakhinvadim yakhinvadim left a comment

Choose a reason for hiding this comment

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

This looks great, thanks, Byron and Scotty! 🙌

P.S: really liked that we also verify scrollTo(0,0) behavior!

Comment on lines 352 to 358
if (isAdding) {
actions.onSchemaSetFormErrors(e?.message);
// We expect body.message to be a string[] for actions.onSchemaSetFormErrors
const message: string[] = e?.body?.message || [defaultErrorMessage];
actions.onSchemaSetFormErrors(message);
} else {
flashAPIErrors(e);
}
Copy link
Contributor

@cee-chen cee-chen Jul 1, 2021

Choose a reason for hiding this comment

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

Why not just add the e?.body?.message check into the conditional and let invalid error formats fall back to flashAPIErrors, instead having to manually fall back to defaultErrorMessage?

Suggested change
if (isAdding) {
actions.onSchemaSetFormErrors(e?.message);
// We expect body.message to be a string[] for actions.onSchemaSetFormErrors
const message: string[] = e?.body?.message || [defaultErrorMessage];
actions.onSchemaSetFormErrors(message);
} else {
flashAPIErrors(e);
}
const errorMessage: string[] = e?.body?.message;
if (isAdding && errorMessage) {
actions.onSchemaSetFormErrors(errorMessage);
} else {
flashAPIErrors(e);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be a slight functional difference, in that when the message is missing, it would appear as a Flash Message error. actions.onSchemaSetFormErrors sets addFormFieldErrors which is used inside a SchemaAddFieldModal. I think we'd still want the default error message to appear in the SchemaAddFieldModal.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion either way. I guess I'm leaning slightly towards showing the error in the modal, closer to the user action that lead to the error. But I see the point in showing it as a flash message: if the error is unexpected, it's probably not caused by user action.

I will merge the PR as-is because the code fixes the original bug and is already tested.

@scottybollinger
Copy link
Contributor Author

@elasticmachine merge upstream

@scottybollinger scottybollinger enabled auto-merge (squash) July 1, 2021 21:26
@scottybollinger scottybollinger disabled auto-merge July 1, 2021 21:26
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 2.1MB 2.1MB +2.5KB

History

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

@yakhinvadim yakhinvadim merged commit 0681120 into elastic:master Jul 2, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Jul 2, 2021
* [Enterprise Search] Fix bug in Add Schema modal

This PR fixes a bug where an error passed from the server was not rendering and was causing the UI to hang. The problem is that the `body` property was missed in the error object.

* Use default message when error response for actions.setServerField has no message

* i18n-ize default error message

* Remove TODO

Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.14

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Jul 2, 2021
* [Enterprise Search] Fix bug in Add Schema modal

This PR fixes a bug where an error passed from the server was not rendering and was causing the UI to hang. The problem is that the `body` property was missed in the error object.

* Use default message when error response for actions.setServerField has no message

* i18n-ize default error message

* Remove TODO

Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Scotty Bollinger <scotty.bollinger@elastic.co>
Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
scottybollinger added a commit to scottybollinger/kibana that referenced this pull request Jul 5, 2021
In elastic#104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.
scottybollinger added a commit that referenced this pull request Jul 7, 2021
…ing state (#104360)

* Fix an issue from previous PR

In #104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.

* Use inline error for duplicate name
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 7, 2021
…ing state (elastic#104360)

* Fix an issue from previous PR

In elastic#104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.

* Use inline error for duplicate name
darnautov pushed a commit to darnautov/kibana that referenced this pull request Jul 7, 2021
…ing state (elastic#104360)

* Fix an issue from previous PR

In elastic#104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.

* Use inline error for duplicate name
kibanamachine added a commit that referenced this pull request Jul 7, 2021
…ing state (#104360) (#104636)

* Fix an issue from previous PR

In #104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.

* Use inline error for duplicate name

Co-authored-by: Scotty Bollinger <scotty.bollinger@elastic.co>
spalger pushed a commit to spalger/kibana that referenced this pull request Jul 7, 2021
* [Enterprise Search] Fix bug in Add Schema modal

This PR fixes a bug where an error passed from the server was not rendering and was causing the UI to hang. The problem is that the `body` property was missed in the error object.

* Use default message when error response for actions.setServerField has no message

* i18n-ize default error message

* Remove TODO

Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@spalger spalger added the v7.15.0 label Jul 7, 2021
spalger pushed a commit to spalger/kibana that referenced this pull request Jul 7, 2021
…ing state (elastic#104360)

* Fix an issue from previous PR

In elastic#104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.

* Use inline error for duplicate name
spalger pushed a commit that referenced this pull request Jul 7, 2021
)

* [Enterprise Search] Fix bug in Add Schema modal (#104024)

* [Enterprise Search] Fix bug in Add Schema modal

This PR fixes a bug where an error passed from the server was not rendering and was causing the UI to hang. The problem is that the `body` property was missed in the error object.

* Use default message when error response for actions.setServerField has no message

* i18n-ize default error message

* Remove TODO

Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Workplace Search] Fix bug where error was behind modal stuck in loading state (#104360)

* Fix an issue from previous PR

In #104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.

* Use inline error for duplicate name

Co-authored-by: Scotty Bollinger <scotty.bollinger@elastic.co>
Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@scottybollinger scottybollinger deleted the scottybollinger/schema-bug branch March 15, 2022 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes v7.14.0 v7.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants