AliasBy.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, { Component } from 'react';
  2. import { debounce } from 'lodash';
  3. export interface Props {
  4. onChange: (alignmentPeriod) => void;
  5. value: string;
  6. }
  7. export interface State {
  8. value: string;
  9. }
  10. export class AliasBy extends Component<Props, State> {
  11. constructor(props) {
  12. super(props);
  13. this.handleChange = this.handleChange.bind(this);
  14. this.onChange = debounce(this.onChange.bind(this), 500);
  15. this.state = { value: '' };
  16. }
  17. componentDidMount() {
  18. this.setState({ value: this.props.value });
  19. }
  20. handleChange(e) {
  21. this.setState({ value: e.target.value });
  22. this.onChange(e.target.value);
  23. }
  24. onChange(value) {
  25. this.props.onChange(value);
  26. }
  27. render() {
  28. return (
  29. <React.Fragment>
  30. <div className="gf-form-inline">
  31. <div className="gf-form">
  32. <label className="gf-form-label query-keyword width-9">Alias By</label>
  33. <input
  34. type="text"
  35. className="gf-form-input width-24"
  36. value={this.state.value}
  37. onChange={this.handleChange}
  38. />
  39. </div>
  40. <div className="gf-form gf-form--grow">
  41. <div className="gf-form-label gf-form-label--grow" />
  42. </div>
  43. </div>
  44. </React.Fragment>
  45. );
  46. }
  47. }