Minor fixes in labels editor

main
Boris Sekachev 5 years ago
parent 1d6ff2e137
commit 195028f6d2

@ -50,22 +50,24 @@ export default class LabelForm extends React.Component<Props> {
const { label, onSubmit } = this.props; const { label, onSubmit } = this.props;
onSubmit({ onSubmit({
name: values.labelName, name: values.name,
id: label ? label.id : idGenerator(), id: label ? label.id : idGenerator(),
color: values.labelColor, color: values.color,
attributes: values.attributes.map((attribute: Store) => { attributes: values.attributes.map((attribute: Store) => {
let attrValues: any = attribute.values; let attrValues: string | string[] = attribute.values;
if (attribute.input_type === AttributeType.NUMBER) { if (!Array.isArray(attrValues)) {
if (attribute.type === AttributeType.NUMBER) {
attrValues = attrValues.split(';'); attrValues = attrValues.split(';');
} else { } else {
attrValues = [attrValues]; attrValues = [attrValues];
} }
}
attrValues = attrValues.map((value: string) => value.trim()); attrValues = attrValues.map((value: string) => value.trim());
return { return {
...attribute, ...attribute,
values: attrValues, values: attrValues,
input_type: attribute.type, input_type: attribute.type.toLowerCase(),
}; };
}), }),
}); });
@ -366,7 +368,7 @@ export default class LabelForm extends React.Component<Props> {
return ( return (
<Form.Item <Form.Item
hasFeedback hasFeedback
name='labelName' name='name'
initialValue={value} initialValue={value}
rules={[ rules={[
{ {
@ -462,19 +464,23 @@ export default class LabelForm extends React.Component<Props> {
const { label } = this.props; const { label } = this.props;
return ( return (
<Form.Item name='labelColor' initialValue={label && label.color ? label.color : undefined}> <Form.Item noStyle shouldUpdate>
{() => (
<Form.Item name='color' initialValue={label ? label?.color : undefined}>
<ColorPicker placement='bottom'> <ColorPicker placement='bottom'>
<Tooltip title='Change color of the label'> <Tooltip title='Change color of the label'>
<Button type='default' className='cvat-change-task-label-color-button'> <Button type='default' className='cvat-change-task-label-color-button'>
<Badge <Badge
className='cvat-change-task-label-color-badge' className='cvat-change-task-label-color-badge'
color={this.formRef.current?.getFieldValue('labelColor') || consts.NEW_LABEL_COLOR} color={this.formRef.current?.getFieldValue('color') || consts.NEW_LABEL_COLOR}
text={<Icon component={ColorizeIcon} />} text={<Icon component={ColorizeIcon} />}
/> />
</Button> </Button>
</Tooltip> </Tooltip>
</ColorPicker> </ColorPicker>
</Form.Item> </Form.Item>
)}
</Form.Item>
); );
} }
@ -486,16 +492,20 @@ export default class LabelForm extends React.Component<Props> {
public componentDidMount(): void { public componentDidMount(): void {
const { label } = this.props; const { label } = this.props;
if (this.formRef.current) { if (this.formRef.current) {
this.formRef.current.setFieldsValue({ const convertedAttributes = label ?
attributes: label ?
label.attributes.map( label.attributes.map(
(attribute: Attribute): Store => ({ (attribute: Attribute): Store => ({
...attribute, ...attribute,
type: attribute.input_type, type: attribute.input_type.toUpperCase(),
}), }),
) : ) :
[], [];
});
for (const attr of convertedAttributes) {
delete attr.input_type;
}
this.formRef.current.setFieldsValue({ attributes: convertedAttributes });
} }
} }
@ -504,10 +514,12 @@ export default class LabelForm extends React.Component<Props> {
<Form onFinish={this.handleSubmit} layout='vertical' ref={this.formRef}> <Form onFinish={this.handleSubmit} layout='vertical' ref={this.formRef}>
<Row justify='start' align='middle'> <Row justify='start' align='middle'>
<Col span={10}>{this.renderLabelNameInput()}</Col> <Col span={10}>{this.renderLabelNameInput()}</Col>
<Col span={1} /> <Col span={3} offset={1}>
<Col span={3}>{this.renderChangeColorButton()}</Col> {this.renderChangeColorButton()}
<Col span={1} /> </Col>
<Col span={6}>{this.renderNewAttributeButton()}</Col> <Col span={6} offset={1}>
{this.renderNewAttributeButton()}
</Col>
</Row> </Row>
<Row justify='start' align='middle'> <Row justify='start' align='middle'>
<Col span={24}> <Col span={24}>

Loading…
Cancel
Save