PredictablePulseEditor.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React, { ChangeEvent } from 'react';
  2. import { InlineField, InlineFieldRow, Input } from '@grafana/ui';
  3. import { EditorProps } from '../QueryEditor';
  4. import { PulseWaveQuery } from '../types';
  5. const fields = [
  6. { label: 'Step', id: 'timeStep', placeholder: '60', tooltip: 'The number of seconds between datapoints.' },
  7. {
  8. label: 'On Count',
  9. id: 'onCount',
  10. placeholder: '3',
  11. tooltip: 'The number of values within a cycle, at the start of the cycle, that should have the onValue.',
  12. },
  13. { label: 'Off Count', id: 'offCount', placeholder: '6', tooltip: 'The number of offValues within the cycle.' },
  14. {
  15. label: 'On Value',
  16. id: 'onValue',
  17. placeholder: '1',
  18. tooltip: 'The value for "on values", may be an int, float, or null.',
  19. },
  20. {
  21. label: 'Off Value',
  22. id: 'offValue',
  23. placeholder: '1',
  24. tooltip: 'The value for "off values", may be a int, float, or null.',
  25. },
  26. ];
  27. export const PredictablePulseEditor = ({ onChange, query }: EditorProps) => {
  28. // Convert values to numbers before saving
  29. const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {
  30. const { name, value } = e.target;
  31. onChange({ target: { name, value: Number(value) } });
  32. };
  33. return (
  34. <InlineFieldRow>
  35. {fields.map(({ label, id, placeholder, tooltip }) => {
  36. return (
  37. <InlineField label={label} labelWidth={14} key={id} tooltip={tooltip}>
  38. <Input
  39. width={32}
  40. type="number"
  41. name={id}
  42. id={`pulseWave.${id}-${query.refId}`}
  43. value={query.pulseWave?.[id as keyof PulseWaveQuery]}
  44. placeholder={placeholder}
  45. onChange={onInputChange}
  46. />
  47. </InlineField>
  48. );
  49. })}
  50. </InlineFieldRow>
  51. );
  52. };