PanelHeaderMenu.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import React, { PureComponent } from 'react';
  2. import { DashboardModel } from 'app/features/dashboard/dashboard_model';
  3. import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem';
  4. import { store } from 'app/store/configureStore';
  5. import { updateLocation } from 'app/core/actions';
  6. import { removePanel, duplicatePanel, copyPanel, editPanelJson } from 'app/features/dashboard/utils/panel';
  7. import appEvents from 'app/core/app_events';
  8. export interface PanelHeaderMenuProps {
  9. panelId: number;
  10. dashboard: DashboardModel;
  11. }
  12. export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
  13. getPanel = () => {
  14. // Pass in panel as prop instead?
  15. const { panelId, dashboard } = this.props;
  16. const panelInfo = dashboard.getPanelInfoById(panelId);
  17. return panelInfo.panel;
  18. };
  19. onEditPanel = () => {
  20. store.dispatch(
  21. updateLocation({
  22. query: {
  23. panelId: this.props.panelId,
  24. edit: true,
  25. fullscreen: true,
  26. },
  27. })
  28. );
  29. };
  30. onViewPanel = () => {
  31. store.dispatch(
  32. updateLocation({
  33. query: {
  34. panelId: this.props.panelId,
  35. edit: false,
  36. fullscreen: true,
  37. },
  38. })
  39. );
  40. };
  41. onRemovePanel = () => {
  42. const { dashboard } = this.props;
  43. const panel = this.getPanel();
  44. removePanel(dashboard, panel, true);
  45. };
  46. onSharePanel = () => {
  47. const { dashboard } = this.props;
  48. const panel = this.getPanel();
  49. appEvents.emit('show-modal', {
  50. src: 'public/app/features/dashboard/partials/shareModal.html',
  51. model: {
  52. panel: panel,
  53. dashboard: dashboard,
  54. },
  55. });
  56. };
  57. onDuplicatePanel = () => {
  58. const { dashboard } = this.props;
  59. const panel = this.getPanel();
  60. duplicatePanel(dashboard, panel);
  61. };
  62. onCopyPanel = () => {
  63. const panel = this.getPanel();
  64. copyPanel(panel);
  65. };
  66. onEditPanelJson = () => {
  67. const { dashboard } = this.props;
  68. const panel = this.getPanel();
  69. editPanelJson(dashboard, panel);
  70. };
  71. render() {
  72. return (
  73. <div className="panel-menu-container dropdown">
  74. <ul className="dropdown-menu dropdown-menu--menu panel-menu" role="menu">
  75. <PanelHeaderMenuItem
  76. type={PanelHeaderMenuItemTypes.Link}
  77. text="View"
  78. iconClassName="fa fa-fw fa-eye"
  79. handleClick={this.onViewPanel}
  80. shortcut="v"
  81. />
  82. <PanelHeaderMenuItem
  83. type={PanelHeaderMenuItemTypes.Link}
  84. text="Edit"
  85. iconClassName="fa fa-fw fa-edit"
  86. handleClick={this.onEditPanel}
  87. shortcut="e"
  88. />
  89. <PanelHeaderMenuItem
  90. type={PanelHeaderMenuItemTypes.Link}
  91. text="Share"
  92. iconClassName="fa fa-fw fa-share"
  93. handleClick={this.onSharePanel}
  94. shortcut="p s"
  95. />
  96. <PanelHeaderMenuItem
  97. type={PanelHeaderMenuItemTypes.SubMenu}
  98. text="More ..."
  99. iconClassName="fa fa-fw fa-cube"
  100. handleClick={null}
  101. >
  102. <ul className="dropdown-menu dropdown-menu--menu panel-menu">
  103. <PanelHeaderMenuItem
  104. type={PanelHeaderMenuItemTypes.Link}
  105. text="Duplicate"
  106. iconClassName=""
  107. handleClick={this.onDuplicatePanel}
  108. shortcut="p d"
  109. />
  110. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Copy" handleClick={this.onCopyPanel} />
  111. <PanelHeaderMenuItem
  112. type={PanelHeaderMenuItemTypes.Link}
  113. text="Panel JSON"
  114. handleClick={this.onEditPanelJson}
  115. />
  116. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Export CSV" handleClick={() => {}} />
  117. <PanelHeaderMenuItem
  118. type={PanelHeaderMenuItemTypes.Link}
  119. text="Toggle legend"
  120. handleClick={() => {}}
  121. shortcut="p l"
  122. />
  123. </ul>
  124. </PanelHeaderMenuItem>
  125. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Divider} />
  126. <PanelHeaderMenuItem
  127. type={PanelHeaderMenuItemTypes.Link}
  128. text="Remove"
  129. iconClassName="fa fa-fw fa-trash"
  130. handleClick={this.onRemovePanel}
  131. shortcut="p r"
  132. />
  133. </ul>
  134. </div>
  135. );
  136. }
  137. }