Skip to content

Commit

Permalink
updated error messages based on error number
Browse files Browse the repository at this point in the history
  • Loading branch information
adewyer committed Jan 26, 2022
1 parent 2965b70 commit c630d1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@babel/preset-react": "7.0.0",
"@babel/runtime": "^7.5.0",
"@babel/runtime-corejs2": "^7.5.0",
"@exabyte-io/made.js": "git+https://github.com/Exabyte-io/made.js.git#f033ce206a42a61cdd36df615608f2c1130eedcb",
"@exabyte-io/made.js": "git+https://github.com/Exabyte-io/made.js.git#c683928b2e7f5a07947870d646dbd4beb120d94d",
"@exabyte-io/wave.js": "3.1.5",
"bootstrap": "^3.3.7",
"classnames": "^2.2.5",
Expand Down
30 changes: 17 additions & 13 deletions src/components/source_editor/BasisText.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,23 @@ class BasisText extends React.Component {
}

isContentPassingValidation(content) {
try {
Made.parsers.xyz.validate(content);
// only show the success message first time after last failure
const error = Made.parsers.xyz.validate(content);
let messageVariable = "";
if (error !== 0) {
let message = "";
if (error === 1001) {

This comment has been minimized.

Copy link
@timurbazhirov

timurbazhirov Jan 26, 2022

Member

let's move to a separate object like below

const validationErrorStatusesConfig = {

0: "ajsdjkal",
1001: "basis.validationError"

}

displayMessage(config[error], ...)

message = "basis.validationError"
}
if (error === 2001) {
message = "basis.maxAtomError"
messageVariable = Made.Basis.nonPeriodicMaxAtomsCount;
}
this.setState({
isContentValidated: false,
message: displayMessage(message, messageVariable)
});
return false;
} else {
if (!this.state.isContentValidated) {
this.setState({
isContentValidated: true,
Expand All @@ -44,16 +58,6 @@ class BasisText extends React.Component {
// already validated before -> remove message
this.setState({message: ''});
}
} catch (err) {
let message = "basis.validationError"
if (err.message === "Non-Periodic max atom limit exceeded") {
message = "basis.maxAtomError"
}
this.setState({
isContentValidated: false,
message: displayMessage(message)
});
return false;
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/en/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
"elementsNotEqual": "Atomic elements differ",
"validationError": "Invalid basis format. Please see documentation",
"validationSuccess": "Valid basis format",
"maxAtomError": "For Non-Periodic Structures: Maximum Number of Atoms Exceeded. Limit = 1000 Atoms."
"maxAtomError": "Number of atoms (%s) exceeded for non-periodic structures."
},
"resetToLast": "Material is reset to last valid state",
"combinatorialBasesCountExceeded": "Number of combinations exceeded the limit (%s)"
Expand Down

0 comments on commit c630d1e

Please sign in to comment.