diff --git a/src/components/editors/UseMetricEditor.tsx b/src/components/editors/UseMetricEditor.tsx index 183b635..d35b375 100644 --- a/src/components/editors/UseMetricEditor.tsx +++ b/src/components/editors/UseMetricEditor.tsx @@ -8,7 +8,7 @@ import React from 'react'; import * as _ from 'lodash'; type UseMetricConfig = { - useMetric?: boolean; + useMetric: boolean; value?: number; metricName?: string; }; @@ -18,12 +18,10 @@ const fieldNamePickerSettings = { } as any; export function UseMetricEditor({ onChange, value, context }: StandardEditorProps) { - let config = value; + let config: UseMetricConfig = value; const onFieldChange = (field: keyof UseMetricConfig, value: any) => { - if (_.isNil(config)) { - config = {}; - } + // @ts-ignore config[field] = value; onChange(config); diff --git a/src/module.ts b/src/module.ts index a67da81..de92132 100644 --- a/src/module.ts +++ b/src/module.ts @@ -49,12 +49,12 @@ export const plugin = new PanelPlugin(Panel).setPanelOptions((buil category: ['Value'], showIf: (config) => config.visualizationType === Pod.GAUGE, }) - // TODO: defaults? .addCustomEditor({ id: 'min', name: 'Min', path: 'gauge.min', category: ['Extremum'], + defaultValue: { useMetric: false, value: 0 }, showIf: (config) => config.visualizationType === Pod.GAUGE, editor: UseMetricEditor as any, }) @@ -63,6 +63,7 @@ export const plugin = new PanelPlugin(Panel).setPanelOptions((buil name: 'Max', path: 'gauge.max', category: ['Extremum'], + defaultValue: { useMetric: false }, showIf: (config) => config.visualizationType === Pod.GAUGE, editor: UseMetricEditor as any, })