ConstantVariableEditor.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React, { FormEvent, PureComponent } from 'react';
  2. import { selectors } from '@grafana/e2e-selectors';
  3. import { VerticalGroup } from '@grafana/ui';
  4. import { VariableSectionHeader } from '../editor/VariableSectionHeader';
  5. import { VariableTextField } from '../editor/VariableTextField';
  6. import { VariableEditorProps } from '../editor/types';
  7. import { ConstantVariableModel } from '../types';
  8. export interface Props extends VariableEditorProps<ConstantVariableModel> {}
  9. export class ConstantVariableEditor extends PureComponent<Props> {
  10. onChange = (event: FormEvent<HTMLInputElement>) => {
  11. this.props.onPropChange({
  12. propName: 'query',
  13. propValue: event.currentTarget.value,
  14. });
  15. };
  16. onBlur = (event: FormEvent<HTMLInputElement>) => {
  17. this.props.onPropChange({
  18. propName: 'query',
  19. propValue: event.currentTarget.value,
  20. updateOptions: true,
  21. });
  22. };
  23. render() {
  24. return (
  25. <VerticalGroup spacing="xs">
  26. <VariableSectionHeader name="Constant options" />
  27. <VariableTextField
  28. value={this.props.variable.query}
  29. name="Value"
  30. placeholder="your metric prefix"
  31. onChange={this.onChange}
  32. onBlur={this.onBlur}
  33. labelWidth={20}
  34. testId={selectors.pages.Dashboard.Settings.Variables.Edit.ConstantVariable.constantOptionsQueryInputV2}
  35. grow
  36. />
  37. </VerticalGroup>
  38. );
  39. }
  40. }