rozetko
3 years ago
2 changed files with 79 additions and 36 deletions
@ -0,0 +1,62 @@
|
||||
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<UseMetricConfig>) { |
||||
const config = value; |
||||
|
||||
const onFieldChange = (field: keyof UseMetricConfig, value: any) => { |
||||
// @ts-ignore
|
||||
config[field] = value; |
||||
|
||||
onChange(config); |
||||
} |
||||
|
||||
return ( |
||||
<HorizontalGroup> |
||||
<InlineField label="Use metric"> |
||||
<InlineSwitch |
||||
value={config.useMetric} |
||||
onChange={(evt) => onFieldChange('useMetric', (evt.target as any).checked)} |
||||
/> |
||||
</InlineField> |
||||
<InlineField> |
||||
{config.useMetric ? ( |
||||
<FieldNamePicker |
||||
context={context} |
||||
value={config.metricName as string} |
||||
onChange={(newVal: any) => onFieldChange('metricName', newVal)} |
||||
item={fieldNamePickerSettings} |
||||
/> |
||||
) : ( |
||||
<Input |
||||
placeholder="value" |
||||
value={config.value} |
||||
onChange={(evt) => onFieldChange('value', (evt.target as any).value)} |
||||
/> |
||||
)} |
||||
</InlineField> |
||||
</HorizontalGroup> |
||||
) |
||||
} |
Loading…
Reference in new issue