From c793baf91073da451165aeb39d7e0e02697a80df Mon Sep 17 00:00:00 2001 From: Dmitry Kalinin Date: Mon, 1 Mar 2021 17:40:41 +0300 Subject: [PATCH] Label form validator fix (#2879) * Fixed label form validator * Added CHANGELOG and increased package npm version * Update Cypress test "Creating a label with existing label name" for PR 2879 (#2883) * Fix case 43 for PR 2879 * Try restart CI Co-authored-by: Dmitry Kruchinin <33020454+dvkruchinin@users.noreply.github.com> --- CHANGELOG.md | 1 + cvat-ui/src/components/labels-editor/label-form.tsx | 9 +++++---- .../case_43_create_label_with_existing_label_name.js | 7 +++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 609f41fe..b514f510 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated the path to python for DL models inside automatic annotation documentation () - Fixed of receiving function variable () - Shortcuts with CAPSLOCK enabled and with non-US languages activated () +- Fixed label editor name field validator () ### Security diff --git a/cvat-ui/src/components/labels-editor/label-form.tsx b/cvat-ui/src/components/labels-editor/label-form.tsx index c0f78329..23f16c96 100644 --- a/cvat-ui/src/components/labels-editor/label-form.tsx +++ b/cvat-ui/src/components/labels-editor/label-form.tsx @@ -390,10 +390,11 @@ export default class LabelForm extends React.Component { message: patterns.validateAttributeName.message, }, { - validator: async (_rule: any, labelName: string, callback: Function) => { + validator: (_rule: any, labelName: string) => { if (labelNames && labelNames.includes(labelName)) { - callback('Label name must be unique for the task'); + return Promise.reject(new Error('Label name must be unique for the task')); } + return Promise.resolve(); }, }, ]} @@ -522,7 +523,7 @@ export default class LabelForm extends React.Component { public render(): JSX.Element { return (
- + {this.renderLabelNameInput()} {this.renderChangeColorButton()} @@ -531,7 +532,7 @@ export default class LabelForm extends React.Component { {this.renderNewAttributeButton()} - + {this.renderAttributes()} diff --git a/tests/cypress/integration/actions_tasks_objects/case_43_create_label_with_existing_label_name.js b/tests/cypress/integration/actions_tasks_objects/case_43_create_label_with_existing_label_name.js index 198f7788..796e41d1 100644 --- a/tests/cypress/integration/actions_tasks_objects/case_43_create_label_with_existing_label_name.js +++ b/tests/cypress/integration/actions_tasks_objects/case_43_create_label_with_existing_label_name.js @@ -24,11 +24,10 @@ context('Creating a label with existing label name.', () => { // Try to create a label with existing label name cy.get('.cvat-constructor-viewer-new-item').click(); cy.get('[placeholder="Label name"]').type(firstLabelName); - cy.contains('[type="submit"]', 'Done').click(); + cy.contains('[role="alert"]', 'Label name must be unique for the task') // Checking alert visibility + .should('exist') + .and('be.visible'); }); - cy.get('.cvat-notification-notice-update-task-failed') - .should('exist') - .and('contain.text', 'label names must be unique'); }); }); });