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';
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<UseMetricConfig>) {
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);

3
src/module.ts

@ -49,12 +49,12 @@ export const plugin = new PanelPlugin<PanelOptions>(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<PanelOptions>(Panel).setPanelOptions((buil
name: 'Max',
path: 'gauge.max',
category: ['Extremum'],
defaultValue: { useMetric: false },
showIf: (config) => config.visualizationType === Pod.GAUGE,
editor: UseMetricEditor as any,
})

Loading…
Cancel
Save