Browse Source

add default values

merge-requests/9/head
vargburz 3 years ago
parent
commit
3bab6996e7
  1. 8
      src/components/editors/UseMetricEditor.tsx
  2. 3
      src/module.ts

8
src/components/editors/UseMetricEditor.tsx

@ -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,12 +18,10 @@ const fieldNamePickerSettings = {
} as any; } as any;
export function UseMetricEditor({ onChange, value, context }: StandardEditorProps<UseMetricConfig>) { export function UseMetricEditor({ onChange, value, context }: StandardEditorProps<UseMetricConfig>) {
let config = value; let config: UseMetricConfig = value;
const onFieldChange = (field: keyof UseMetricConfig, value: any) => { const onFieldChange = (field: keyof UseMetricConfig, value: any) => {
if (_.isNil(config)) { // @ts-ignore
config = {};
}
config[field] = value; config[field] = value;
onChange(config); onChange(config);

3
src/module.ts

@ -49,12 +49,12 @@ export const plugin = new PanelPlugin<PanelOptions>(Panel).setPanelOptions((buil
category: ['Value'], category: ['Value'],
showIf: (config) => config.visualizationType === Pod.GAUGE, showIf: (config) => config.visualizationType === Pod.GAUGE,
}) })
// TODO: defaults?
.addCustomEditor({ .addCustomEditor({
id: 'min', id: 'min',
name: 'Min', name: 'Min',
path: 'gauge.min', path: 'gauge.min',
category: ['Extremum'], category: ['Extremum'],
defaultValue: { useMetric: false, value: 0 },
showIf: (config) => config.visualizationType === Pod.GAUGE, showIf: (config) => config.visualizationType === Pod.GAUGE,
editor: UseMetricEditor as any, editor: UseMetricEditor as any,
}) })
@ -63,6 +63,7 @@ export const plugin = new PanelPlugin<PanelOptions>(Panel).setPanelOptions((buil
name: 'Max', name: 'Max',
path: 'gauge.max', path: 'gauge.max',
category: ['Extremum'], category: ['Extremum'],
defaultValue: { useMetric: false },
showIf: (config) => config.visualizationType === Pod.GAUGE, showIf: (config) => config.visualizationType === Pod.GAUGE,
editor: UseMetricEditor as any, editor: UseMetricEditor as any,
}) })

Loading…
Cancel
Save