module.tsx 936 B

1234567891011121314151617181920212223242526272829
  1. import { ReactPanelPlugin } from '@grafana/ui';
  2. import { SingleStatOptions, defaults, SingleStatBaseOptions } from './types';
  3. import { SingleStatPanel } from './SingleStatPanel';
  4. import cloneDeep from 'lodash/cloneDeep';
  5. import { SingleStatEditor } from './SingleStatEditor';
  6. export const reactPanel = new ReactPanelPlugin<SingleStatOptions>(SingleStatPanel);
  7. const optionsToKeep = ['valueOptions', 'stat', 'maxValue', 'maxValue', 'thresholds', 'valueMappings'];
  8. export const singleStatBaseOptionsCheck = (
  9. options: Partial<SingleStatBaseOptions>,
  10. prevPluginId?: string,
  11. prevOptions?: any
  12. ) => {
  13. if (prevOptions) {
  14. optionsToKeep.forEach(v => {
  15. if (prevOptions.hasOwnProperty(v)) {
  16. options[v] = cloneDeep(prevOptions.display);
  17. }
  18. });
  19. }
  20. return options;
  21. };
  22. reactPanel.setEditor(SingleStatEditor);
  23. reactPanel.setDefaults(defaults);
  24. reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck);