AliasBy.tsx 1.3 KB

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