Skip to content

Commit

Permalink
Merge pull request #262 from oarepo/display-validation-errors-when-se…
Browse files Browse the repository at this point in the history
…rver-returns-400

showing validation errors when server returns 400
  • Loading branch information
mirekys authored Dec 2, 2024
2 parents 7880e08 + db66ac1 commit 26cc4f2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 44 deletions.
22 changes: 19 additions & 3 deletions oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export const useDepositApiClient = ({
errorMessage:
errorMessage ||
i18next.t(
"Draft saved with validation errors. Fields listed below that failed validation were not saved to the server"
"Draft saved with validation errors. Please correct the following issues and try again:"
),
errorPaths,
};
Expand All @@ -258,8 +258,24 @@ export const useDepositApiClient = ({
} catch (error) {
// handle 400 errors. Normally, axios would put messages in error.response. But for example
// offline Error message does not produce a response, so in this way we can display
// network error message
errorsObj["httpErrors"] = error?.response?.data?.message ?? error.message;
// network error message. Additionally, if request returns 400 and contains validation errors
// we can display them in the same manner as for the case when 200 is returned.
if (error?.response?.data?.errors?.length > 0) {
for (const err of error.response.data.errors) {
errorsObj = setIn(errorsObj, err.field, err.messages.join(" "));
}
errorsObj["BEvalidationErrors"] = {
errors: error.response.data.errors,
errorMessage:
errorMessage ||
i18next.t(
"Draft saved with validation errors. Please correct the following issues and try again:"
),
};
} else {
errorsObj["httpErrors"] =
error?.response?.data?.message ?? error.message;
}
return false;
} finally {
// put state changing calls together, in order to avoid multiple rerenders during form submit
Expand Down

Large diffs are not rendered by default.

Binary file modified oarepo_ui/translations/cs/LC_MESSAGES/messages.mo
Binary file not shown.
7 changes: 7 additions & 0 deletions oarepo_ui/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,10 @@ msgstr "Smazat koncept"

msgid "Draft deleted successfully. Redirecting to your dashboard ..."
msgstr "Koncept byl úspěšně smazán. Přesměrování na vaši nástěnku ..."

msgid ""
"Draft saved with validation errors. Please correct the following issues and "
"try again:"
msgstr ""
"Koncept byl uložen s validačními chybami. Opravte prosím následující "
"problémy a zkuste to znovu:"
5 changes: 5 additions & 0 deletions oarepo_ui/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,8 @@ msgstr ""

msgid "Draft deleted successfully. Redirecting to your dashboard ..."
msgstr ""

msgid ""
"Draft saved with validation errors. Please correct the following issues and "
"try again:"
msgstr ""
Binary file modified oarepo_ui/translations/messages.mo
Binary file not shown.
55 changes: 16 additions & 39 deletions oarepo_ui/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-31 13:07+0100\n"
"POT-Creation-Date: 2024-12-02 15:03+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -49,7 +49,7 @@ msgstr ""
msgid "api.versions"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/resources/config.py:140
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/resources/config.py:149
msgid "JSON"
msgstr ""

Expand Down Expand Up @@ -77,34 +77,6 @@ msgstr ""
msgid "Edit item"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:9
msgid "ORCID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:14
msgid "Scopus ID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:19
msgid "ROR profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:24
msgid "WOS Researcher ID"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:29
msgid "ISNI profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:34
msgid "DOI profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:39
msgid "GND profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifiersAndLinks.jinja:4
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifiersAndLinks.jinja:5
msgid "Identifiers and links"
Expand Down Expand Up @@ -161,7 +133,7 @@ msgid "Size"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/datafields/files/FilesViewer.jinja:13
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:53
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:54
msgid "Actions"
msgstr ""

Expand Down Expand Up @@ -239,18 +211,18 @@ msgstr ""
msgid "Sign up"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:36
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:37
msgid "Quick create"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:72
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:113
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:73
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:114
msgid "My account"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:107
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:136
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:143
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:108
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:137
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/oarepo_ui/header_login.html:144
msgid "Log out"
msgstr ""

Expand Down Expand Up @@ -385,8 +357,8 @@ msgid "Save"
msgstr ""

msgid ""
"Draft saved with validation errors. Fields listed below that failed "
"validation were not saved to the server"
"Draft saved with validation errors. Please correct the following issues and "
"try again:"
msgstr ""

msgid "Draft saved successfully."
Expand All @@ -406,6 +378,11 @@ msgstr ""
msgid "Your draft was saved. Redirecting to the preview page..."
msgstr ""

msgid ""
"Draft saved with validation errors. Fields listed below that failed "
"validation were not saved to the server"
msgstr ""

msgid "Clear all filters"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-ui
version = 5.2.30
version = 5.2.31
description = UI module for invenio 3.5+
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit 26cc4f2

Please sign in to comment.