You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
3 years ago
|
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>
|
||
|
)
|
||
|
}
|