diff --git a/src/components/editors/UseMetricEditor.tsx b/src/components/editors/UseMetricEditor.tsx index 4018e26..d91d1cc 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,10 +18,12 @@ const fieldNamePickerSettings = { } as any; export function UseMetricEditor({ onChange, value, context }: StandardEditorProps) { - const config = value; + let config = value; const onFieldChange = (field: keyof UseMetricConfig, value: any) => { - // @ts-ignore + if(_.isNil(config)) { + config = {}; + } config[field] = value; onChange(config); @@ -31,22 +33,22 @@ export function UseMetricEditor({ onChange, value, context }: StandardEditorProp onFieldChange('useMetric', (evt.target as any).checked)} /> - {config.useMetric ? ( + {config?.useMetric ? ( onFieldChange('metricName', newVal)} item={fieldNamePickerSettings} /> ) : ( onFieldChange('value', (evt.target as any).value)} /> diff --git a/src/models/options.ts b/src/models/options.ts index f150d29..f63a74b 100644 --- a/src/models/options.ts +++ b/src/models/options.ts @@ -21,7 +21,10 @@ export class Options { } private _setMin(): void { - if (!this.grafanaOptions.gauge.min.useMetric) { + if (!this.grafanaOptions.gauge.min) { + throw new Error(`Min Config is not selected: [See options: Extremum -> Min]`); + } + if (!this.grafanaOptions.gauge.min?.useMetric) { this.minValue = this.grafanaOptions.gauge.min.value; return; } @@ -30,7 +33,10 @@ export class Options { } private _setMax(): void { - if (!this.grafanaOptions.gauge.max.useMetric) { + if (!this.grafanaOptions.gauge.max) { + throw new Error(`Max Config is not selected: [See options: Extremum -> Max]`); + } + if (!this.grafanaOptions.gauge.max?.useMetric) { this.maxValue = this.grafanaOptions.gauge.max.value; return; } diff --git a/src/models/series.ts b/src/models/series.ts index 3155a82..30a22cb 100644 --- a/src/models/series.ts +++ b/src/models/series.ts @@ -10,7 +10,7 @@ export class Series { private _selectedSerieName; constructor(grafanaSeriesList: any, private gaugeValueOptions: ValueOptions) { - if (_.isEmpty(this.gaugeValueOptions.metricName)) { + if (_.isEmpty(this.gaugeValueOptions?.metricName)) { throw new Error(`Value: metric is not selected. [See options: Value -> Metric]`); } this._selectedSerieName = this.gaugeValueOptions.metricName;