GeneralTab.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Libraries
  2. import React, { PureComponent } from 'react';
  3. // Components
  4. import { getAngularLoader, AngularComponent } from '@grafana/runtime';
  5. import { EditorTabBody } from './EditorTabBody';
  6. import './../../panel/GeneralTabCtrl';
  7. // Types
  8. import { PanelModel } from '../state/PanelModel';
  9. import { DataLink } from '@grafana/data';
  10. import { PanelOptionsGroup, DataLinksEditor } from '@grafana/ui';
  11. import { getPanelLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv';
  12. interface Props {
  13. panel: PanelModel;
  14. }
  15. export class GeneralTab extends PureComponent<Props> {
  16. element: any;
  17. component: AngularComponent;
  18. constructor(props: Props) {
  19. super(props);
  20. }
  21. componentDidMount() {
  22. if (!this.element) {
  23. return;
  24. }
  25. const { panel } = this.props;
  26. const loader = getAngularLoader();
  27. const template = '<panel-general-tab />';
  28. const scopeProps = {
  29. ctrl: {
  30. panel: panel,
  31. },
  32. };
  33. this.component = loader.load(this.element, scopeProps, template);
  34. }
  35. componentWillUnmount() {
  36. if (this.component) {
  37. this.component.destroy();
  38. }
  39. }
  40. onDataLinksChanged = (links: DataLink[]) => {
  41. this.props.panel.links = links;
  42. this.props.panel.render();
  43. this.forceUpdate();
  44. };
  45. render() {
  46. const { panel } = this.props;
  47. const suggestions = getPanelLinksVariableSuggestions();
  48. return (
  49. <EditorTabBody heading="General" toolbarItems={[]}>
  50. <>
  51. <div ref={element => (this.element = element)} />
  52. <PanelOptionsGroup title="Panel links">
  53. <DataLinksEditor
  54. value={panel.links}
  55. onChange={this.onDataLinksChanged}
  56. suggestions={suggestions}
  57. maxLinks={10}
  58. />
  59. </PanelOptionsGroup>
  60. </>
  61. </EditorTabBody>
  62. );
  63. }
  64. }