VisualizationTab.tsx 1.5 KB

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