PanelHeaderMenu.tsx 4.1 KB

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