|
|
@ -8,7 +8,7 @@ import React from 'react'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
type UseMetricConfig = { |
|
|
|
type UseMetricConfig = { |
|
|
|
useMetric: boolean; |
|
|
|
useMetric?: boolean; |
|
|
|
value?: number; |
|
|
|
value?: number; |
|
|
|
metricName?: string; |
|
|
|
metricName?: string; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -18,10 +18,12 @@ const fieldNamePickerSettings = { |
|
|
|
} as any; |
|
|
|
} as any; |
|
|
|
|
|
|
|
|
|
|
|
export function UseMetricEditor({ onChange, value, context }: StandardEditorProps<UseMetricConfig>) { |
|
|
|
export function UseMetricEditor({ onChange, value, context }: StandardEditorProps<UseMetricConfig>) { |
|
|
|
const config = value; |
|
|
|
let config = value; |
|
|
|
|
|
|
|
|
|
|
|
const onFieldChange = (field: keyof UseMetricConfig, value: any) => { |
|
|
|
const onFieldChange = (field: keyof UseMetricConfig, value: any) => { |
|
|
|
// @ts-ignore
|
|
|
|
if(_.isNil(config)) { |
|
|
|
|
|
|
|
config = {}; |
|
|
|
|
|
|
|
} |
|
|
|
config[field] = value; |
|
|
|
config[field] = value; |
|
|
|
|
|
|
|
|
|
|
|
onChange(config); |
|
|
|
onChange(config); |
|
|
@ -31,22 +33,22 @@ export function UseMetricEditor({ onChange, value, context }: StandardEditorProp |
|
|
|
<HorizontalGroup> |
|
|
|
<HorizontalGroup> |
|
|
|
<InlineField label="Use metric"> |
|
|
|
<InlineField label="Use metric"> |
|
|
|
<InlineSwitch |
|
|
|
<InlineSwitch |
|
|
|
value={config.useMetric} |
|
|
|
value={config?.useMetric} |
|
|
|
onChange={(evt) => onFieldChange('useMetric', (evt.target as any).checked)} |
|
|
|
onChange={(evt) => onFieldChange('useMetric', (evt.target as any).checked)} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</InlineField> |
|
|
|
</InlineField> |
|
|
|
<InlineField> |
|
|
|
<InlineField> |
|
|
|
{config.useMetric ? ( |
|
|
|
{config?.useMetric ? ( |
|
|
|
<FieldNamePicker |
|
|
|
<FieldNamePicker |
|
|
|
context={context} |
|
|
|
context={context} |
|
|
|
value={config.metricName as string} |
|
|
|
value={config?.metricName as string} |
|
|
|
onChange={(newVal: any) => onFieldChange('metricName', newVal)} |
|
|
|
onChange={(newVal: any) => onFieldChange('metricName', newVal)} |
|
|
|
item={fieldNamePickerSettings} |
|
|
|
item={fieldNamePickerSettings} |
|
|
|
/> |
|
|
|
/> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|
<Input |
|
|
|
<Input |
|
|
|
placeholder="value" |
|
|
|
placeholder="value" |
|
|
|
value={config.value} |
|
|
|
value={config?.value} |
|
|
|
width={24} |
|
|
|
width={24} |
|
|
|
onChange={(evt) => onFieldChange('value', (evt.target as any).value)} |
|
|
|
onChange={(evt) => onFieldChange('value', (evt.target as any).value)} |
|
|
|
/> |
|
|
|
/> |
|
|
|