VisualizationTab.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. renderPanelOptions() {
  18. const { plugin, panel } = this.props;
  19. const { PanelOptions } = plugin.exports;
  20. if (PanelOptions) {
  21. return <PanelOptions options={panel.getOptions()} onChange={this.onPanelOptionsChanged} />;
  22. } else {
  23. return <p>Visualization has no options</p>;
  24. }
  25. }
  26. onPanelOptionsChanged = (options: any) => {
  27. this.props.panel.updateOptions(options);
  28. this.forceUpdate();
  29. };
  30. render() {
  31. const { plugin } = this.props;
  32. const panelSelection = {
  33. title: plugin.name,
  34. imgSrc: plugin.info.logos.small,
  35. render: () => {
  36. // the needs to be scoped inside this closure
  37. const { plugin, onTypeChanged } = this.props;
  38. return <VizTypePicker current={plugin} onTypeChanged={onTypeChanged} />;
  39. },
  40. };
  41. return (
  42. <EditorTabBody main={panelSelection} toolbarItems={[]}>
  43. {this.renderPanelOptions()}
  44. </EditorTabBody>
  45. );
  46. }
  47. }