NodeGraphEditor.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from 'react';
  2. import { Input, InlineFieldRow, InlineField, Select } from '@grafana/ui';
  3. import { NodesQuery, TestDataQuery } from '../types';
  4. export interface Props {
  5. onChange: (value: NodesQuery) => void;
  6. query: TestDataQuery;
  7. }
  8. export function NodeGraphEditor({ query, onChange }: Props) {
  9. const type = query.nodes?.type || 'random';
  10. return (
  11. <InlineFieldRow>
  12. <InlineField label="Data type" labelWidth={14}>
  13. <Select<NodesQuery['type']>
  14. options={options.map((o) => ({
  15. label: o,
  16. value: o,
  17. }))}
  18. value={options.find((item) => item === type)}
  19. onChange={(value) => onChange({ ...query.nodes, type: value.value! })}
  20. width={32}
  21. />
  22. </InlineField>
  23. {type === 'random' && (
  24. <InlineField label="Count" labelWidth={14}>
  25. <Input
  26. type="number"
  27. name="count"
  28. value={query.nodes?.count}
  29. width={32}
  30. onChange={(e) =>
  31. onChange({ ...query.nodes, count: e.currentTarget.value ? parseInt(e.currentTarget.value, 10) : 0 })
  32. }
  33. placeholder="10"
  34. />
  35. </InlineField>
  36. )}
  37. </InlineFieldRow>
  38. );
  39. }
  40. const options: Array<NodesQuery['type']> = ['random', 'response'];