QueriesTab.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React, { PureComponent } from 'react';
  2. import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader';
  3. import { EditorTabBody } from './EditorTabBody';
  4. import { DataSourcePicker } from './DataSourcePicker';
  5. import { PanelModel } from '../panel_model';
  6. import { DashboardModel } from '../dashboard_model';
  7. interface Props {
  8. panel: PanelModel;
  9. dashboard: DashboardModel;
  10. }
  11. export class QueriesTab extends PureComponent<Props> {
  12. element: any;
  13. component: AngularComponent;
  14. constructor(props) {
  15. super(props);
  16. }
  17. componentDidMount() {
  18. if (!this.element) {
  19. return;
  20. }
  21. const { panel, dashboard } = this.props;
  22. const loader = getAngularLoader();
  23. const template = '<metrics-tab />';
  24. const scopeProps = {
  25. ctrl: {
  26. panel: panel,
  27. dashboard: dashboard,
  28. refresh: () => panel.refresh(),
  29. },
  30. };
  31. this.component = loader.load(this.element, scopeProps, template);
  32. }
  33. componentWillUnmount() {
  34. if (this.component) {
  35. this.component.destroy();
  36. }
  37. }
  38. render() {
  39. const currentDataSource = {
  40. title: 'ProductionDB',
  41. imgSrc: 'public/app/plugins/datasource/prometheus/img/prometheus_logo.svg',
  42. render: () => <DataSourcePicker />,
  43. };
  44. const queryInspector = {
  45. title: 'Query Inspector',
  46. render: () => <h2>hello</h2>,
  47. };
  48. const dsHelp = {
  49. title: '',
  50. icon: 'fa fa-question',
  51. render: () => <h2>hello</h2>,
  52. };
  53. return (
  54. <EditorTabBody main={currentDataSource} toolbarItems={[queryInspector, dsHelp]}>
  55. <div ref={element => (this.element = element)} style={{ width: '100%' }} />
  56. </EditorTabBody>
  57. );
  58. }
  59. }