QueryEditor.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { QueryEditorProps } from '@grafana/data';
  4. import InfluxDatasource from '../datasource';
  5. import { buildRawQuery } from '../queryUtils';
  6. import { InfluxOptions, InfluxQuery } from '../types';
  7. import { FluxQueryEditor } from './FluxQueryEditor';
  8. import { QueryEditorModeSwitcher } from './QueryEditorModeSwitcher';
  9. import { RawInfluxQLEditor } from './RawInfluxQLEditor';
  10. import { Editor as VisualInfluxQLEditor } from './VisualInfluxQLEditor/Editor';
  11. type Props = QueryEditorProps<InfluxDatasource, InfluxQuery, InfluxOptions>;
  12. export const QueryEditor = ({ query, onChange, onRunQuery, datasource, range, data }: Props): JSX.Element => {
  13. if (datasource.isFlux) {
  14. return (
  15. <div className="gf-form-query-content">
  16. <FluxQueryEditor query={query} onChange={onChange} onRunQuery={onRunQuery} datasource={datasource} />
  17. </div>
  18. );
  19. }
  20. return (
  21. <div className={css({ display: 'flex' })}>
  22. <div className={css({ flexGrow: 1 })}>
  23. {query.rawQuery ? (
  24. <RawInfluxQLEditor query={query} onChange={onChange} onRunQuery={onRunQuery} />
  25. ) : (
  26. <VisualInfluxQLEditor query={query} onChange={onChange} onRunQuery={onRunQuery} datasource={datasource} />
  27. )}
  28. </div>
  29. <QueryEditorModeSwitcher
  30. isRaw={query.rawQuery ?? false}
  31. onChange={(value) => {
  32. onChange({ ...query, query: buildRawQuery(query), rawQuery: value });
  33. onRunQuery();
  34. }}
  35. />
  36. </div>
  37. );
  38. };