import { FieldNamePicker } from '../../grafana/MatchersUI/FieldNamePicker'; 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 = value; const onFieldChange = (field: keyof UseMetricConfig, value: any) => { if (_.isNil(config)) { config = {}; } config[field] = value; onChange(config); }; return ( onFieldChange('useMetric', (evt.target as any).checked)} /> {config?.useMetric ? ( onFieldChange('metricName', newVal)} item={fieldNamePickerSettings} /> ) : ( onFieldChange('value', (evt.target as any).value)} /> )} ); }