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)) {
attrValues = attrValues.split(';'); if (attribute.type === AttributeType.NUMBER) {
} else { attrValues = attrValues.split(';');
attrValues = [attrValues]; } else {
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,18 +464,22 @@ 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>
<ColorPicker placement='bottom'> {() => (
<Tooltip title='Change color of the label'> <Form.Item name='color' initialValue={label ? label?.color : undefined}>
<Button type='default' className='cvat-change-task-label-color-button'> <ColorPicker placement='bottom'>
<Badge <Tooltip title='Change color of the label'>
className='cvat-change-task-label-color-badge' <Button type='default' className='cvat-change-task-label-color-button'>
color={this.formRef.current?.getFieldValue('labelColor') || consts.NEW_LABEL_COLOR} <Badge
text={<Icon component={ColorizeIcon} />} className='cvat-change-task-label-color-badge'
/> color={this.formRef.current?.getFieldValue('color') || consts.NEW_LABEL_COLOR}
</Button> text={<Icon component={ColorizeIcon} />}
</Tooltip> />
</ColorPicker> </Button>
</Tooltip>
</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.toUpperCase(),
type: attribute.input_type, }),
}), ) :
) : [];
[],
}); 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