mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-29 06:58:12 +08:00
category and label name validation updates (#1056)
* update label validation with new schema * add new error messages for new label errors; general cleanup
This commit is contained in:
@@ -183,7 +183,35 @@ export function createWritableAnnotationDimensions(world, crossfilter) {
|
||||
return crossfilter;
|
||||
}
|
||||
|
||||
const legalNames = /^\w+$/;
|
||||
export function isLegalAnnotationName(name) {
|
||||
return legalNames.test(name);
|
||||
const legalCharacters = /^(\w|[ .])+$/;
|
||||
export function annotationNameIsErroneous(name) {
|
||||
/*
|
||||
Validate the name - return:
|
||||
* false - a valid name
|
||||
* string - a named error, indicating why it was invalid.
|
||||
|
||||
Tests:
|
||||
0. must be string, non-null
|
||||
1. no leading or trailing spaces
|
||||
2. only accept alpha, numeric, underscore, period and space
|
||||
3. no runs of multiple spaces
|
||||
*/
|
||||
|
||||
if (name === "") {
|
||||
return "empty-string";
|
||||
}
|
||||
if (name[0] === " " || name[name.length - 1] === " ") {
|
||||
return "trim-spaces";
|
||||
}
|
||||
if (!legalCharacters.test(name)) {
|
||||
return "illegal-characters";
|
||||
}
|
||||
for (let i = 1, l = name.length; i < l; i += 1) {
|
||||
if (name[i] === " " && name[i - 1] === " ") {
|
||||
return "multi-space-run";
|
||||
}
|
||||
}
|
||||
|
||||
/* all is well! Indicte not erroneous with a false */
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user