import { FieldNamePicker } from '../../grafana/MatchersUI/FieldNamePicker'; import { isNumber } from '../../utils'; import { StandardEditorProps } from '@grafana/data'; import { HorizontalGroup, InlineField, InlineSwitch, Input } from '@grafana/ui'; import React from 'react'; import * as _ from 'lodash'; type UseMetricConfig = { useMetric: boolean; value?: number; metricName?: string; }; const fieldNamePickerSettings = { settings: { width: 24 }, } as any; export function UseMetricEditor({ onChange, value, context }: StandardEditorProps) { let config: UseMetricConfig = value; const onFieldChange = (field: keyof UseMetricConfig, value: any) => { // @ts-ignore config[field] = value; onChange(config); }; return ( onFieldChange('useMetric', evt.currentTarget.checked)} /> {config?.useMetric ? ( onFieldChange('metricName', newVal)} item={fieldNamePickerSettings} /> ) : ( onFieldChange('value', isNumber(evt.currentTarget.value) ? +evt.currentTarget.value : undefined)} /> )} ); }