PanelHeaderMenu.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import React, { PureComponent } from 'react';
  2. // import { store } from 'app/store/configureStore';
  3. import { DashboardModel } from 'app/features/dashboard/dashboard_model';
  4. import { PanelModel } from 'app/features/dashboard/panel_model';
  5. import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem';
  6. import appEvents from 'app/core/app_events';
  7. import { store } from 'app/store/configureStore';
  8. import { updateLocation } from 'app/core/actions';
  9. export interface PanelHeaderMenuProps {
  10. panelId: number;
  11. dashboard: DashboardModel;
  12. }
  13. export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
  14. onEditPanel = () => {
  15. store.dispatch(
  16. updateLocation({
  17. query: {
  18. panelId: this.props.panelId,
  19. edit: true,
  20. fullscreen: true,
  21. },
  22. })
  23. );
  24. };
  25. onViewPanel = () => {
  26. store.dispatch(
  27. updateLocation({
  28. query: {
  29. panelId: this.props.panelId,
  30. edit: false,
  31. fullscreen: true,
  32. },
  33. })
  34. );
  35. };
  36. onRemovePanel = () => {
  37. const { panelId, dashboard } = this.props;
  38. const panelInfo = dashboard.getPanelInfoById(panelId);
  39. this.removePanel(panelInfo.panel, true);
  40. };
  41. removePanel = (panel: PanelModel, ask: boolean) => {
  42. const { dashboard } = this.props;
  43. // confirm deletion
  44. if (ask !== false) {
  45. const text2 = panel.alert ? 'Panel includes an alert rule, removing panel will also remove alert rule' : null;
  46. const confirmText = panel.alert ? 'YES' : null;
  47. appEvents.emit('confirm-modal', {
  48. title: 'Remove Panel',
  49. text: 'Are you sure you want to remove this panel?',
  50. text2: text2,
  51. icon: 'fa-trash',
  52. confirmText: confirmText,
  53. yesText: 'Remove',
  54. onConfirm: () => this.removePanel(panel, false),
  55. });
  56. return;
  57. }
  58. dashboard.removePanel(panel);
  59. };
  60. render() {
  61. return (
  62. <div className="panel-menu-container dropdown">
  63. <ul className="dropdown-menu dropdown-menu--menu panel-menu" role="menu">
  64. <PanelHeaderMenuItem
  65. type={PanelHeaderMenuItemTypes.Link}
  66. text="View"
  67. iconClassName="fa fa-fw fa-eye"
  68. handleClick={this.onViewPanel}
  69. shortcut="v"
  70. />
  71. <PanelHeaderMenuItem
  72. type={PanelHeaderMenuItemTypes.Link}
  73. text="Edit"
  74. iconClassName="fa fa-fw fa-edit"
  75. handleClick={this.onEditPanel}
  76. shortcut="e"
  77. />
  78. <PanelHeaderMenuItem
  79. type={PanelHeaderMenuItemTypes.Link}
  80. text="Share"
  81. iconClassName="fa fa-fw fa-share"
  82. handleClick={() => {}}
  83. shortcut="p s"
  84. />
  85. <PanelHeaderMenuItem
  86. type={PanelHeaderMenuItemTypes.SubMenu}
  87. text="More ..."
  88. iconClassName="fa fa-fw fa-cube"
  89. handleClick={() => {}}
  90. >
  91. <ul className="dropdown-menu dropdown-menu--menu panel-menu">
  92. <PanelHeaderMenuItem
  93. type={PanelHeaderMenuItemTypes.Link}
  94. text="Duplicate"
  95. iconClassName=""
  96. handleClick={() => {}}
  97. shortcut="p d"
  98. />
  99. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Copy" handleClick={() => {}} />
  100. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Panel JSON" handleClick={() => {}} />
  101. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Export CSV" handleClick={() => {}} />
  102. <PanelHeaderMenuItem
  103. type={PanelHeaderMenuItemTypes.Link}
  104. text="Toggle legend"
  105. handleClick={() => {}}
  106. shortcut="p l"
  107. />
  108. </ul>
  109. </PanelHeaderMenuItem>
  110. <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Divider} />
  111. <PanelHeaderMenuItem
  112. type={PanelHeaderMenuItemTypes.Link}
  113. text="Remove"
  114. iconClassName="fa fa-fw fa-trash"
  115. handleClick={this.onRemovePanel}
  116. shortcut="p r"
  117. />
  118. </ul>
  119. </div>
  120. );
  121. }
  122. }