VisualizationTab.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { PureComponent } from 'react';
  2. import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader';
  3. import { EditorTabBody } from './EditorTabBody';
  4. import { VizTypePicker } from './VizTypePicker';
  5. import { PanelModel } from '../panel_model';
  6. import { DashboardModel } from '../dashboard_model';
  7. interface Props {
  8. panel: PanelModel;
  9. dashboard: DashboardModel;
  10. plugin: PluginModel;
  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 { PanelOptionsComponent } = plugin.exports;
  20. if (PanelOptionsComponent) {
  21. return <PanelOptionsComponent 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, onTypeChanged} = this.props;
  32. const panelSelection = {
  33. title: plugin.name,
  34. imgSrc: plugin.info.logos.small,
  35. render: () => {
  36. return <VizTypePicker current={plugin} onTypeChanged={onTypeChanged} />;
  37. },
  38. };
  39. return (
  40. <EditorTabBody toolbarItems={[panelSelection]}>
  41. {this.renderPanelOptions()}
  42. </EditorTabBody>
  43. );
  44. }
  45. }