GraphiteTextEditor.tsx 784 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React, { useCallback } from 'react';
  2. import { QueryField } from '@grafana/ui';
  3. import { actions } from '../state/actions';
  4. import { useDispatch } from '../state/context';
  5. type Props = {
  6. rawQuery: string;
  7. };
  8. export function GraphiteTextEditor({ rawQuery }: Props) {
  9. const dispatch = useDispatch();
  10. const updateQuery = useCallback(
  11. (query: string) => {
  12. dispatch(actions.updateQuery({ query }));
  13. },
  14. [dispatch]
  15. );
  16. const runQuery = useCallback(() => {
  17. dispatch(actions.runQuery());
  18. }, [dispatch]);
  19. return (
  20. <QueryField
  21. query={rawQuery}
  22. onChange={updateQuery}
  23. onBlur={runQuery}
  24. onRunQuery={runQuery}
  25. placeholder={'Enter a Graphite query (run with Shift+Enter)'}
  26. portalOrigin="graphite"
  27. />
  28. );
  29. }