VisualizationTab.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { PureComponent } from 'react';
  2. import { EditorTabBody } from './EditorTabBody';
  3. import { VizTypePicker } from './VizTypePicker';
  4. import { PanelModel } from '../panel_model';
  5. import { DashboardModel } from '../dashboard_model';
  6. import { PanelPlugin } from 'app/types/plugins';
  7. interface Props {
  8. panel: PanelModel;
  9. dashboard: DashboardModel;
  10. plugin: PanelPlugin;
  11. onTypeChanged: (newType: PanelPlugin) => void;
  12. }
  13. export class VisualizationTab extends PureComponent<Props> {
  14. constructor(props) {
  15. super(props);
  16. }
  17. getPanelDefaultOptions() {
  18. const { panel, plugin } = this.props;
  19. if (plugin.exports.PanelDefaults) {
  20. return panel.getOptions(plugin.exports.PanelDefaults.options);
  21. }
  22. return panel.getOptions(plugin.exports.PanelDefaults);
  23. }
  24. renderPanelOptions() {
  25. const { plugin } = this.props;
  26. const { PanelOptions } = plugin.exports;
  27. if (PanelOptions) {
  28. return <PanelOptions options={this.getPanelDefaultOptions()} onChange={this.onPanelOptionsChanged} />;
  29. } else {
  30. return <p>Visualization has no options</p>;
  31. }
  32. }
  33. onPanelOptionsChanged = (options: any) => {
  34. this.props.panel.updateOptions(options);
  35. this.forceUpdate();
  36. };
  37. render() {
  38. const { plugin } = this.props;
  39. const panelSelection = {
  40. title: plugin.name,
  41. imgSrc: plugin.info.logos.small,
  42. render: () => {
  43. // the needs to be scoped inside this closure
  44. const { plugin, onTypeChanged } = this.props;
  45. return <VizTypePicker current={plugin} onTypeChanged={onTypeChanged} />;
  46. },
  47. };
  48. return (
  49. <EditorTabBody main={panelSelection} toolbarItems={[]}>
  50. {this.renderPanelOptions()}
  51. </EditorTabBody>
  52. );
  53. }
  54. }