Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch of fixes #2031

Merged
merged 8 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Issue loading openvino models for semi-automatic and automatic annotation (<https://github.com/opencv/cvat/pull/1996>)
- Basic functions of CVAT works without activated nuclio dashboard
- Fixed error with creating task with labels with the same name (<https://github.com/opencv/cvat/pull/2031>)

### Security
-
Expand Down
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.7.1",
"version": "1.7.2",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import LabelForm from './label-form';
import { Label } from './common';

interface Props {
labelNames: string[];
onCreate: (label: Label | null) => void;
}

export default function ConstructorCreator(props: Props): JSX.Element {
const { onCreate } = props;
const { onCreate, labelNames } = props;
return (
<div className='cvat-label-constructor-creator'>
<LabelForm label={null} onSubmit={onCreate} />
<LabelForm label={null} onSubmit={onCreate} labelNames={labelNames} />
</div>
);
}
9 changes: 9 additions & 0 deletions cvat-ui/src/components/labels-editor/label-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum AttributeType {

type Props = FormComponentProps & {
label: Label | null;
labelNames?: string[];
onSubmit: (label: Label | null) => void;
};

Expand Down Expand Up @@ -384,6 +385,7 @@ class LabelForm extends React.PureComponent<Props, {}> {
const {
label,
form,
labelNames,
} = this.props;
const value = label ? label.name : '';
const locked = label ? label.id >= 0 : false;
Expand All @@ -399,6 +401,13 @@ class LabelForm extends React.PureComponent<Props, {}> {
}, {
pattern: patterns.validateAttributeName.pattern,
message: patterns.validateAttributeName.message,
}, {
validator:
async (_rule: any, labelName: string, callback: Function) => {
if (labelNames && labelNames.includes(labelName)) {
callback('Label name must be unique for the task');
}
},
}],
})(<Input disabled={locked} placeholder='Label name' />)}
</Form.Item>
Expand Down
2 changes: 2 additions & 0 deletions cvat-ui/src/components/labels-editor/labels-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export default class LabelsEditor
}

public render(): JSX.Element {
const { labels } = this.props;
const {
savedLabels,
unsavedLabels,
Expand Down Expand Up @@ -319,6 +320,7 @@ export default class LabelsEditor
constructorMode === ConstructorMode.CREATE
&& (
<ConstructorCreator
labelNames={labels.map((l) => l.name)}
ActiveChooN marked this conversation as resolved.
Show resolved Hide resolved
onCreate={this.handleCreate}
/>
)
Expand Down
4 changes: 4 additions & 0 deletions cvat-ui/src/components/labels-editor/raw-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class RawViewer extends React.PureComponent<Props> {
if (!Array.isArray(parsed)) {
callback('Field is expected to be a JSON array');
}
const labelNames = parsed.map((label: Label) => label.name);
if (new Set(labelNames).size !== labelNames.length) {
callback('Label names must be unique for the task');
}

for (const label of parsed) {
try {
Expand Down
7 changes: 7 additions & 0 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def to_representation(self, instance):
class LabelSerializer(serializers.ModelSerializer):
attributes = AttributeSerializer(many=True, source='attributespec_set',
default=[])

class Meta:
model = models.Label
fields = ('id', 'name', 'attributes')
Expand Down Expand Up @@ -305,6 +306,12 @@ def update(self, instance, validated_data):
instance.save()
return instance

def validate_labels(self, data):
label_names = [label['name'] for label in data]
if len(label_names) != len(set(label_names)):
ActiveChooN marked this conversation as resolved.
Show resolved Hide resolved
raise serializers.ValidationError('All label names must be unique for the task')


class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = models.Project
Expand Down