Files
grafana/public/app/plugins/panel/singlestat2/module.tsx

30 lines
936 B
TypeScript
Raw Normal View History

2019-03-14 13:20:24 -07:00
import { ReactPanelPlugin } from '@grafana/ui';
2019-03-15 08:38:29 -07:00
import { SingleStatOptions, defaults, SingleStatBaseOptions } from './types';
2019-03-14 13:20:24 -07:00
import { SingleStatPanel } from './SingleStatPanel';
import cloneDeep from 'lodash/cloneDeep';
import { SingleStatEditor } from './SingleStatEditor';
export const reactPanel = new ReactPanelPlugin<SingleStatOptions>(SingleStatPanel);
const optionsToKeep = ['valueOptions', 'stat', 'maxValue', 'maxValue', 'thresholds', 'valueMappings'];
2019-03-15 08:38:29 -07:00
export const singleStatBaseOptionsCheck = (
options: Partial<SingleStatBaseOptions>,
2019-03-14 13:20:24 -07:00
prevPluginId?: string,
prevOptions?: any
) => {
if (prevOptions) {
optionsToKeep.forEach(v => {
if (prevOptions.hasOwnProperty(v)) {
options[v] = cloneDeep(prevOptions.display);
}
});
}
return options;
};
reactPanel.setEditor(SingleStatEditor);
reactPanel.setDefaults(defaults);
2019-03-15 08:38:29 -07:00
reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck);