VariableQueryEditor.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { PureComponent } from 'react';
  2. import { InlineFormLabel, TextArea } from '@grafana/ui';
  3. import InfluxDatasource from '../datasource';
  4. import { FluxQueryEditor } from './FluxQueryEditor';
  5. interface Props {
  6. query: string; // before flux, it was always a string
  7. onChange: (query?: string) => void;
  8. datasource: InfluxDatasource;
  9. }
  10. export default class VariableQueryEditor extends PureComponent<Props> {
  11. onRefresh = () => {
  12. // noop
  13. };
  14. render() {
  15. let { query, datasource, onChange } = this.props;
  16. if (datasource.isFlux) {
  17. return (
  18. <FluxQueryEditor
  19. datasource={datasource}
  20. query={{
  21. refId: 'A',
  22. query,
  23. }}
  24. onRunQuery={this.onRefresh}
  25. onChange={(v) => onChange(v.query)}
  26. />
  27. );
  28. }
  29. return (
  30. <div className="gf-form-inline">
  31. <InlineFormLabel width={10}>Query</InlineFormLabel>
  32. <div className="gf-form-inline gf-form--grow">
  33. <TextArea
  34. defaultValue={query || ''}
  35. placeholder="metric name or tags query"
  36. rows={1}
  37. className="gf-form-input"
  38. onBlur={(e) => onChange(e.currentTarget.value)}
  39. />
  40. </div>
  41. </div>
  42. );
  43. }
  44. }