Skip to content

Commit

Permalink
Resolved issue #2968
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Sekachev committed Mar 17, 2021
1 parent c58074e commit 1251cc4
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions cvat-ui/src/components/labels-editor/label-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,20 @@ export default class LabelForm extends React.Component<Props> {
const locked = attr ? attr.id >= 0 : false;
const existedValues = attr ? attr.values : [];

const validator = (_: any, values: string[], callback: any): void => {
const validator = (_: any, values: string[]): Promise<void> => {
if (locked && existedValues) {
if (!equalArrayHead(existedValues, values)) {
callback('You can only append new values');
return Promise.reject(new Error('You can only append new values'));
}
}

for (const value of values) {
if (!patterns.validateAttributeValue.pattern.test(value)) {
callback(`Invalid attribute value: "${value}"`);
return Promise.reject(new Error(`Invalid attribute value: "${value}"`));
}
}

callback();
return Promise.resolve();
};

return (
Expand Down Expand Up @@ -223,35 +223,35 @@ export default class LabelForm extends React.Component<Props> {
private renderNumberRangeInput(fieldInstance: any, attr: Attribute | null): JSX.Element {
const { key } = fieldInstance;
const locked = attr ? attr.id >= 0 : false;
const value = attr ? attr.values.join(';') : '';
const value = attr ? attr.values : '';

const validator = (_: any, strNumbers: string, callback: any): void => {
const validator = (_: any, strNumbers: string): Promise<void> => {
const numbers = strNumbers.split(';').map((number): number => Number.parseFloat(number));
if (numbers.length !== 3) {
callback('Three numbers are expected');
return Promise.reject(new Error('Three numbers are expected'));
}

for (const number of numbers) {
if (Number.isNaN(number)) {
callback(`"${number}" is not a number`);
return Promise.reject(new Error(`"${number}" is not a number`));
}
}

const [min, max, step] = numbers;

if (min >= max) {
callback('Minimum must be less than maximum');
return Promise.reject(new Error('Minimum must be less than maximum'));
}

if (max - min < step) {
callback('Step must be less than minmax difference');
return Promise.reject(new Error('Step must be less than minmax difference'));
}

if (step <= 0) {
callback('Step must be a positive number');
return Promise.reject(new Error('Step must be a positive number'));
}

callback();
return Promise.resolve();
};

return (
Expand Down Expand Up @@ -507,6 +507,10 @@ export default class LabelForm extends React.Component<Props> {
label.attributes.map(
(attribute: Attribute): Store => ({
...attribute,
values:
attribute.input_type.toUpperCase() === 'NUMBER' ?
attribute.values.join(';') :
attribute.values,
type: attribute.input_type.toUpperCase(),
}),
) :
Expand Down

0 comments on commit 1251cc4

Please sign in to comment.