DefaultTemplateQueryComponent.tsx 952 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React, { PureComponent } from 'react';
  2. import { TemplateQueryProps } from 'app/types/plugins';
  3. export default class DefaultTemplateQueryComponent extends PureComponent<TemplateQueryProps, any> {
  4. constructor(props) {
  5. super(props);
  6. this.state = { value: props.query };
  7. this.handleChange = this.handleChange.bind(this);
  8. this.handleBlur = this.handleBlur.bind(this);
  9. }
  10. handleChange(event) {
  11. this.setState({ value: event.target.value });
  12. }
  13. handleBlur(event) {
  14. this.props.onChange(event.target.value);
  15. }
  16. render() {
  17. return (
  18. <div className="gf-form">
  19. <span className="gf-form-label width-7">Query</span>
  20. <input
  21. type="text"
  22. className="gf-form-input"
  23. value={this.state.value}
  24. onChange={this.handleChange}
  25. onBlur={this.handleBlur}
  26. placeholder="metric name or tags query"
  27. required
  28. />
  29. </div>
  30. );
  31. }
  32. }