PanelHeaderMenu.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 } 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. render() {
  67. return (
  68. <div className="panel-menu-container dropdown">
  69. <ul className="dropdown-menu dropdown-menu--menu panel-menu" role="menu">
  70. <PanelHeaderMenuItem
  71. type={PanelHeaderMenuItemTypes.Link}
  72. text="View"
  73. iconClassName="fa fa-fw fa-eye"
  74. handleClick={this.onViewPanel}
  75. shortcut="v"
  76. />
  77. <PanelHeaderMenuItem
  78. type={PanelHeaderMenuItemTypes.Link}
  79. text="Edit"
  80. iconClassName="fa fa-fw fa-edit"
  81. handleClick={this.onEditPanel}
  82. shortcut="e"
  83. />
  84. <PanelHeaderMenuItem
  85. type={PanelHeaderMenuItemTypes.Link}
  86. text="Share"
  87. iconClassName="fa fa-fw fa-share"
  88. handleClick={this.onSharePanel}
  89. shortcut="p s"
  90. />
  91. <PanelHeaderMenuItem
  92. type={PanelHeaderMenuItemTypes.SubMenu}
  93. text="More ..."
  94. iconClassName="fa fa-fw fa-cube"
  95. handleClick={null}
  96. >
  97. <ul className="dropdown-menu dropdown-menu--menu panel-menu">
  98. <PanelHeaderMenuItem
  99. type={PanelHeaderMenuItemTypes.Link}
  100. text="Duplicate"
  101. iconClassName=""
  102. handleClick={this.onDuplicatePanel}
  103. shortcut="p d"
  104. />
  105. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Copy" handleClick={this.onCopyPanel} />
  106. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Panel JSON" handleClick={() => {}} />
  107. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Export CSV" handleClick={() => {}} />
  108. <PanelHeaderMenuItem
  109. type={PanelHeaderMenuItemTypes.Link}
  110. text="Toggle legend"
  111. handleClick={() => {}}
  112. shortcut="p l"
  113. />
  114. </ul>
  115. </PanelHeaderMenuItem>
  116. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Divider} />
  117. <PanelHeaderMenuItem
  118. type={PanelHeaderMenuItemTypes.Link}
  119. text="Remove"
  120. iconClassName="fa fa-fw fa-trash"
  121. handleClick={this.onRemovePanel}
  122. shortcut="p r"
  123. />
  124. </ul>
  125. </div>
  126. );
  127. }
  128. }