AliasBy.tsx 1.3 KB

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