import React, { Component } from 'react';
import { Form, Label } from 'semantic-ui-react';


class MetricTarget extends Component {
  constructor(props) {
    super(props);
    this.state = { edited_target: this.props.target || 0 }
  }
  onChange(event) {
    this.setState({ edited_target: event.target.value});
  }
  onKeyDown(event) {
    if (event.key === "Escape") {
      this.setState({ edited_target: this.props.target })
    }
  }
  onSubmit(event) {
    event.preventDefault();
    if (this.state.edited_target !== this.props.target) {
      this.props.set_value(this.state.edited_target || 0);
    }
  }
  render() {
    return (
      <Form onSubmit={(e) => this.onSubmit(e)}>
        <Form.Group style={{marginBottom: '0px'}}>
          <Form.Input
            focus
            label={this.props.label}
            labelPosition='right'
            min="0"
            type="number"
            onBlur={(e) => this.onSubmit(e)}
            onChange={(e) => this.onChange(e)}
            onKeyDown={(e) => this.onKeyDown(e)}
            readOnly={this.props.readOnly}
            value={this.state.edited_target}
            width={16}
          >
            <Label basic>{this.props.direction}</Label>
            <input />
            <Label basic>{this.props.unit}</Label>
          </Form.Input>
        </Form.Group>
      </Form >
    )
  }
}

export { MetricTarget };

@@ -225,24 +225,176 @@
  %7C%7C 0 %7D%0A  %7D%0A
+  componentDidUpdate(prevProps) %7B%0A    if (prevProps.target !== this.props.target) %7B%0A      this.setState(%7B edited_target: this.props.target %7D)%0A    %7D%0A  %7D%0A
   onChange(e

Update the metric target field when changing the metric type. (#179)