Better input validation (#580)

This commit is contained in:
Colin Megill
2019-02-05 10:44:59 -05:00
committed by GitHub
parent ad9be3cdd7
commit 08ea7d5137
+22 -17
View File
@@ -108,21 +108,29 @@ class GeneExpression extends React.Component {
const { world, dispatch, userDefinedGenes } = this.props; const { world, dispatch, userDefinedGenes } = this.props;
const { bulkAdd } = this.state; const { bulkAdd } = this.state;
const genes = _.uniq(bulkAdd.split(", ").map(g => g.trim())); /*
test:
Apod,,, Cd74,, ,,, Foo, Bar-2,,
*/
if (bulkAdd !== "") {
const genes = _.pull(_.uniq(bulkAdd.split(/[ ,]+/)), "");
genes.forEach(gene => { genes.forEach(gene => {
if (userDefinedGenes.indexOf(gene) !== -1) { if (userDefinedGenes.indexOf(gene) !== -1) {
keepAroundErrorToast("That gene already exists"); keepAroundErrorToast("That gene already exists");
} else if (!_.find(world.varAnnotations, { name: gene })) { } else if (!_.find(world.varAnnotations, { name: gene })) {
keepAroundErrorToast(`${gene} doesn't appear to be a valid gene name.`); keepAroundErrorToast(
} else { `${gene} doesn't appear to be a valid gene name.`
dispatch(actions.requestUserDefinedGene(gene)); );
dispatch({ } else {
type: "user defined gene", dispatch(actions.requestUserDefinedGene(gene));
data: gene dispatch({
}); type: "user defined gene",
} data: gene
}); });
}
});
}
this.setState({ bulkAdd: "" }); this.setState({ bulkAdd: "" });
} }
@@ -230,9 +238,6 @@ class GeneExpression extends React.Component {
<FormGroup <FormGroup
helperText="Add a list of genes (comma delimited)" helperText="Add a list of genes (comma delimited)"
labelFor="text-input-bulk-add" labelFor="text-input-bulk-add"
onSubmit={() => {
console.log("heyo");
}}
> >
<ControlGroup> <ControlGroup>
<InputGroup <InputGroup