import { InlineLabel, Input, InlineFormLabel, InlineSwitch, Stack } from '@grafana/ui'; import { OpenTsdbQuery } from '../types'; export interface RateSectionProps { query: OpenTsdbQuery; onChange: (query: OpenTsdbQuery) => void; onRunQuery: () => void; tsdbVersion: number; } export function RateSection({ query, onChange, onRunQuery, tsdbVersion }: RateSectionProps) { return ( Rate { const shouldComputeRate = query.shouldComputeRate ?? false; onChange({ ...query, shouldComputeRate: !shouldComputeRate }); onRunQuery(); }} /> {query.shouldComputeRate && ( <> Counter { const isCounter = query.isCounter ?? false; onChange({ ...query, isCounter: !isCounter }); onRunQuery(); }} /> )} {query.shouldComputeRate && query.isCounter && ( Counter max { const value = e.currentTarget.value; onChange({ ...query, counterMax: value }); }} onBlur={() => onRunQuery()} /> Reset value { const value = e.currentTarget.value; onChange({ ...query, counterResetValue: value }); }} onBlur={() => onRunQuery()} /> )} {tsdbVersion > 2 && ( <> Explicit tags { const explicitTags = query.explicitTags ?? false; onChange({ ...query, explicitTags: !explicitTags }); onRunQuery(); }} /> )} ); } export const testIds = { section: 'opentsdb-rate', shouldComputeRate: 'opentsdb-shouldComputeRate', isCounter: 'opentsdb-is-counter', counterMax: 'opentsdb-counter-max', counterResetValue: 'opentsdb-counter-reset-value', explicitTags: 'opentsdb-explicit-tags', };