Resample.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { ChangeEvent, FC } from 'react';
  2. import { SelectableValue } from '@grafana/data';
  3. import { InlineField, InlineFieldRow, Input, Select } from '@grafana/ui';
  4. import { downsamplingTypes, ExpressionQuery, upsamplingTypes } from '../types';
  5. interface Props {
  6. refIds: Array<SelectableValue<string>>;
  7. query: ExpressionQuery;
  8. labelWidth: number;
  9. onChange: (query: ExpressionQuery) => void;
  10. }
  11. export const Resample: FC<Props> = ({ labelWidth, onChange, refIds, query }) => {
  12. const downsampler = downsamplingTypes.find((o) => o.value === query.downsampler);
  13. const upsampler = upsamplingTypes.find((o) => o.value === query.upsampler);
  14. const onWindowChange = (event: ChangeEvent<HTMLInputElement>) => {
  15. onChange({ ...query, window: event.target.value });
  16. };
  17. const onRefIdChange = (value: SelectableValue<string>) => {
  18. onChange({ ...query, expression: value.value });
  19. };
  20. const onSelectDownsampler = (value: SelectableValue<string>) => {
  21. onChange({ ...query, downsampler: value.value });
  22. };
  23. const onSelectUpsampler = (value: SelectableValue<string>) => {
  24. onChange({ ...query, upsampler: value.value });
  25. };
  26. return (
  27. <>
  28. <InlineFieldRow>
  29. <InlineField label="Input" labelWidth={labelWidth}>
  30. <Select onChange={onRefIdChange} options={refIds} value={query.expression} width={20} />
  31. </InlineField>
  32. </InlineFieldRow>
  33. <InlineFieldRow>
  34. <InlineField label="Resample to" labelWidth={labelWidth} tooltip="10s, 1m, 30m, 1h">
  35. <Input onChange={onWindowChange} value={query.window} width={15} />
  36. </InlineField>
  37. <InlineField label="Downsample">
  38. <Select options={downsamplingTypes} value={downsampler} onChange={onSelectDownsampler} width={25} />
  39. </InlineField>
  40. <InlineField label="Upsample">
  41. <Select options={upsamplingTypes} value={upsampler} onChange={onSelectUpsampler} width={25} />
  42. </InlineField>
  43. </InlineFieldRow>
  44. </>
  45. );
  46. };