import React, { SyntheticEvent } from 'react'; import { DataSourceSettings, SelectableValue } from '@grafana/data'; import { InlineFormLabel, LegacyForms } from '@grafana/ui'; import { useUniqueId } from '../../influxdb/components/useUniqueId'; import { OpenTsdbOptions } from '../types'; const { Select, Input } = LegacyForms; const tsdbVersions = [ { label: '<=2.1', value: 1 }, { label: '==2.2', value: 2 }, { label: '==2.3', value: 3 }, ]; const tsdbResolutions = [ { label: 'second', value: 1 }, { label: 'millisecond', value: 2 }, ]; interface Props { value: DataSourceSettings; onChange: (value: DataSourceSettings) => void; } export const OpenTsdbDetails = (props: Props) => { const { onChange, value } = props; const idSuffix = useUniqueId(); return ( <>
OpenTSDB settings
Version resolution.value === value.jsonData.tsdbResolution) ?? tsdbResolutions[0] } onChange={onSelectChangeHandler('tsdbResolution', value, onChange)} />
Lookup limit
); }; const onSelectChangeHandler = (key: keyof OpenTsdbOptions, value: Props['value'], onChange: Props['onChange']) => (newValue: SelectableValue) => { onChange({ ...value, jsonData: { ...value.jsonData, [key]: newValue.value, }, }); }; const onInputChangeHandler = (key: keyof OpenTsdbOptions, value: Props['value'], onChange: Props['onChange']) => (event: SyntheticEvent) => { onChange({ ...value, jsonData: { ...value.jsonData, [key]: event.currentTarget.value, }, }); };