OpenTsdbDetails.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React, { SyntheticEvent } from 'react';
  2. import { DataSourceSettings, SelectableValue } from '@grafana/data';
  3. import { InlineFormLabel, LegacyForms } from '@grafana/ui';
  4. import { useUniqueId } from '../../influxdb/components/useUniqueId';
  5. import { OpenTsdbOptions } from '../types';
  6. const { Select, Input } = LegacyForms;
  7. const tsdbVersions = [
  8. { label: '<=2.1', value: 1 },
  9. { label: '==2.2', value: 2 },
  10. { label: '==2.3', value: 3 },
  11. ];
  12. const tsdbResolutions = [
  13. { label: 'second', value: 1 },
  14. { label: 'millisecond', value: 2 },
  15. ];
  16. interface Props {
  17. value: DataSourceSettings<OpenTsdbOptions>;
  18. onChange: (value: DataSourceSettings<OpenTsdbOptions>) => void;
  19. }
  20. export const OpenTsdbDetails = (props: Props) => {
  21. const { onChange, value } = props;
  22. const idSuffix = useUniqueId();
  23. return (
  24. <>
  25. <h5>OpenTSDB settings</h5>
  26. <div className="gf-form">
  27. <InlineFormLabel width={7} htmlFor={`select-version-${idSuffix}`}>
  28. Version
  29. </InlineFormLabel>
  30. <Select
  31. inputId={`select-version-${idSuffix}`}
  32. options={tsdbVersions}
  33. value={tsdbVersions.find((version) => version.value === value.jsonData.tsdbVersion) ?? tsdbVersions[0]}
  34. onChange={onSelectChangeHandler('tsdbVersion', value, onChange)}
  35. />
  36. </div>
  37. <div className="gf-form">
  38. <InlineFormLabel width={7} htmlFor={`select-resolution-${idSuffix}`}>
  39. Resolution
  40. </InlineFormLabel>
  41. <Select
  42. inputId={`select-resolution-${idSuffix}`}
  43. options={tsdbResolutions}
  44. value={
  45. tsdbResolutions.find((resolution) => resolution.value === value.jsonData.tsdbResolution) ??
  46. tsdbResolutions[0]
  47. }
  48. onChange={onSelectChangeHandler('tsdbResolution', value, onChange)}
  49. />
  50. </div>
  51. <div className="gf-form">
  52. <InlineFormLabel width={7} htmlFor={`lookup-input-${idSuffix}`}>
  53. Lookup limit
  54. </InlineFormLabel>
  55. <Input
  56. id={`lookup-input-${idSuffix}`}
  57. type="number"
  58. value={value.jsonData.lookupLimit ?? 1000}
  59. onChange={onInputChangeHandler('lookupLimit', value, onChange)}
  60. />
  61. </div>
  62. </>
  63. );
  64. };
  65. const onSelectChangeHandler =
  66. (key: keyof OpenTsdbOptions, value: Props['value'], onChange: Props['onChange']) => (newValue: SelectableValue) => {
  67. onChange({
  68. ...value,
  69. jsonData: {
  70. ...value.jsonData,
  71. [key]: newValue.value,
  72. },
  73. });
  74. };
  75. const onInputChangeHandler =
  76. (key: keyof OpenTsdbOptions, value: Props['value'], onChange: Props['onChange']) =>
  77. (event: SyntheticEvent<HTMLInputElement>) => {
  78. onChange({
  79. ...value,
  80. jsonData: {
  81. ...value.jsonData,
  82. [key]: event.currentTarget.value,
  83. },
  84. });
  85. };