PanelHeaderMenu.tsx 4.3 KB

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