From 3bab6996e7df5f36791314b2c0b4c8b3617c203d Mon Sep 17 00:00:00 2001 From: vargburz Date: Thu, 9 Jun 2022 14:32:12 +0300 Subject: [PATCH] add default values --- src/components/editors/UseMetricEditor.tsx | 8 +++----- src/module.ts | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) 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, })