RandomWalkEditor.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from 'react';
  2. import { selectors } from '@grafana/e2e-selectors';
  3. import { InlineField, InlineFieldRow, Input } from '@grafana/ui';
  4. import { EditorProps } from '../QueryEditor';
  5. import { TestDataQuery } from '../types';
  6. const randomWalkFields = [
  7. { label: 'Series count', id: 'seriesCount', placeholder: '1', min: 1, step: 1 },
  8. { label: 'Start value', id: 'startValue', placeholder: 'auto', step: 1 },
  9. { label: 'Min', id: 'min', placeholder: 'none', step: 0.1 },
  10. { label: 'Max', id: 'max', placeholder: 'none', step: 0.1 },
  11. { label: 'Spread', id: 'spread', placeholder: '1', min: 0.5, step: 0.1 },
  12. { label: 'Noise', id: 'noise', placeholder: '0', min: 0, step: 0.1 },
  13. {
  14. label: 'Drop (%)',
  15. id: 'drop',
  16. placeholder: '0',
  17. min: 0,
  18. max: 100,
  19. step: 1,
  20. tooltip: 'Exclude some percent (chance) points',
  21. },
  22. ];
  23. const testSelectors = selectors.components.DataSource.TestData.QueryTab;
  24. type Selector = 'max' | 'min' | 'noise' | 'seriesCount' | 'spread' | 'startValue' | 'drop';
  25. export const RandomWalkEditor = ({ onChange, query }: EditorProps) => {
  26. return (
  27. <InlineFieldRow>
  28. {randomWalkFields.map(({ label, id, min, step, placeholder, tooltip }) => {
  29. const selector = testSelectors?.[id as Selector];
  30. return (
  31. <InlineField label={label} labelWidth={14} key={id} aria-label={selector} tooltip={tooltip}>
  32. <Input
  33. width={32}
  34. name={id}
  35. type="number"
  36. id={`randomWalk-${id}-${query.refId}`}
  37. min={min}
  38. step={step}
  39. value={(query as any)[id as keyof TestDataQuery] || placeholder}
  40. placeholder={placeholder}
  41. onChange={onChange}
  42. />
  43. </InlineField>
  44. );
  45. })}
  46. </InlineFieldRow>
  47. );
  48. };