AliasBy.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.updateQuery = debounce(this.updateQuery.bind(this), 500);
  14. this.state = { value: '' };
  15. }
  16. componentDidMount() {
  17. this.setState({ value: this.props.value });
  18. }
  19. componentWillReceiveProps(nextProps: Props) {
  20. if (nextProps.value !== this.props.value) {
  21. this.setState({ value: nextProps.value });
  22. }
  23. }
  24. onChange(e) {
  25. this.setState({ value: e.target.value });
  26. this.updateQuery(e.target.value);
  27. }
  28. updateQuery(value) {
  29. this.props.onChange(value);
  30. }
  31. render() {
  32. return (
  33. <React.Fragment>
  34. <div className="gf-form-inline">
  35. <div className="gf-form">
  36. <label className="gf-form-label query-keyword width-9">Alias By</label>
  37. <input
  38. type="text"
  39. className="gf-form-input width-24"
  40. value={this.state.value}
  41. onChange={e => this.onChange(e)}
  42. />
  43. </div>
  44. <div className="gf-form gf-form--grow">
  45. <div className="gf-form-label gf-form-label--grow" />
  46. </div>
  47. </div>
  48. </React.Fragment>
  49. );
  50. }
  51. }