Skip to content

Commit

Permalink
Handle both commas and semicolons in scenario editor
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanliefland committed Jul 4, 2022
1 parent 10252e9 commit 4fa00d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions public/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
"Valid": "Valid",
"Validating": "Validating",
"Value": "Value",
"Values must be separated either by commas or semicolon": "Values must be separated either by commas or semicolon",
"Vector": "Vector",
"View all": "View all",
"Viewer": "Viewer",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"Valid": "",
"Validating": "",
"Value": "",
"Values must be separated either by commas or semicolon": "",
"Vector": "",
"View all": "",
"Viewer": "",
Expand Down
19 changes: 17 additions & 2 deletions src/features/dataset/ScenarioEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,27 @@ const ScenarioEditor = (props: ScenarioEditorProps) => {
if (typeof reader.result !== "string") {
return abort(t("Expected string, got ArrayBuffer"));
}
let rows = reader.result.split("\n").map((row) => row.split(";"));
const rawRows = reader.result
.split("\n")
.filter((row) => row.replace(" ", "") !== "");

// Make sure that the file is not empty and has two columns
if (rows.length === 0) {
if (rawRows.length === 0) {
return abort(t("File is empty"));
}

// Split by comma or semicolon
let rows;
if (rawRows[0].indexOf(";") !== -1) {
rows = rawRows.map((row) => row.split(";"));
} else if (rawRows[0].indexOf(",") !== -1) {
rows = rawRows.map((row) => row.split(","));
} else {
return abort(
t("Values must be separated either by commas or semicolon")
);
}

if (rows.find((row) => row.length !== 2)) {
return abort(t("The file must have two columns"));
}
Expand Down

0 comments on commit 4fa00d0

Please sign in to comment.