Skip to content

Commit

Permalink
Label form validator fix (#2879)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ActiveChooN and dvkruchinin authored Mar 1, 2021
1 parent 55b20e1 commit c793baf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<https://github.com/openvinotoolkit/cvat/pull/2847>)
- Fixed of receiving function variable (<https://github.com/openvinotoolkit/cvat/pull/2860>)
- Shortcuts with CAPSLOCK enabled and with non-US languages activated (<https://github.com/openvinotoolkit/cvat/pull/2872>)
- Fixed label editor name field validator (<https://github.com/openvinotoolkit/cvat/pull/2879>)

### Security

Expand Down
9 changes: 5 additions & 4 deletions cvat-ui/src/components/labels-editor/label-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,11 @@ export default class LabelForm extends React.Component<Props> {
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();
},
},
]}
Expand Down Expand Up @@ -522,7 +523,7 @@ export default class LabelForm extends React.Component<Props> {
public render(): JSX.Element {
return (
<Form onFinish={this.handleSubmit} layout='vertical' ref={this.formRef}>
<Row justify='start' align='middle'>
<Row justify='start' align='top'>
<Col span={10}>{this.renderLabelNameInput()}</Col>
<Col span={3} offset={1}>
{this.renderChangeColorButton()}
Expand All @@ -531,7 +532,7 @@ export default class LabelForm extends React.Component<Props> {
{this.renderNewAttributeButton()}
</Col>
</Row>
<Row justify='start' align='middle'>
<Row justify='start' align='top'>
<Col span={24}>
<Form.List name='attributes'>{this.renderAttributes()}</Form.List>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit c793baf

Please sign in to comment.