LegacyVariableQueryEditor.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { css } from '@emotion/css';
  2. import React, { FC, useCallback, useState } from 'react';
  3. import { GrafanaTheme } from '@grafana/data';
  4. import { selectors } from '@grafana/e2e-selectors';
  5. import { useStyles } from '@grafana/ui';
  6. import { VariableQueryEditorProps } from '../types';
  7. import { VariableTextAreaField } from './VariableTextAreaField';
  8. export const LEGACY_VARIABLE_QUERY_EDITOR_NAME = 'Grafana-LegacyVariableQueryEditor';
  9. export const LegacyVariableQueryEditor: FC<VariableQueryEditorProps> = ({ onChange, query }) => {
  10. const styles = useStyles(getStyles);
  11. const [value, setValue] = useState(query);
  12. const onValueChange = (event: React.FormEvent<HTMLTextAreaElement>) => {
  13. setValue(event.currentTarget.value);
  14. };
  15. const onBlur = useCallback(
  16. (event: React.FormEvent<HTMLTextAreaElement>) => {
  17. onChange(event.currentTarget.value, event.currentTarget.value);
  18. },
  19. [onChange]
  20. );
  21. return (
  22. <div className={styles.container}>
  23. <VariableTextAreaField
  24. name="Query"
  25. value={value}
  26. placeholder="metric name or tags query"
  27. width={100}
  28. onChange={onValueChange}
  29. onBlur={onBlur}
  30. required
  31. labelWidth={20}
  32. ariaLabel={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsQueryInput}
  33. />
  34. </div>
  35. );
  36. };
  37. function getStyles(theme: GrafanaTheme) {
  38. return {
  39. container: css`
  40. margin-bottom: ${theme.spacing.xs};
  41. `,
  42. };
  43. }
  44. LegacyVariableQueryEditor.displayName = LEGACY_VARIABLE_QUERY_EDITOR_NAME;