Skip to content

Commit

Permalink
Added label validators (#2078)
Browse files Browse the repository at this point in the history
* Added label validators

* Updated version
  • Loading branch information
bsekachev authored Aug 25, 2020
1 parent 1c1baeb commit 1fdf100
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.8.1",
"version": "1.8.2",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions cvat-ui/src/components/labels-editor/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function validateParsedAttribute(attr: Attribute): void {
+ `Attribute values must be an array. Got type ${typeof (attr.values)}`);
}

if (!attr.values.length) {
throw new Error(`Attribute: "${attr.name}". Attribute values array mustn't be empty`);
}


for (const value of attr.values) {
if (typeof (value) !== 'string') {
throw new Error(`Attribute: "${attr.name}". `
Expand All @@ -62,6 +67,11 @@ export function validateParsedLabel(label: Label): void {
+ `Type of label id must be only a number or undefined. Got value ${label.id}`);
}

if (typeof (label.color) !== 'string') {
throw new Error(`Label "${label.name}". `
+ `Label color must be a string. Got ${typeof (label.color)}`);
}

if (!label.color.match(/^#[0-9a-f]{6}$|^$/)) {
throw new Error(`Label "${label.name}". `
+ `Type of label color must be only a valid color string. Got value ${label.color}`);
Expand Down

0 comments on commit 1fdf100

Please sign in to comment.