getPanelMenu.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { updateLocation } from 'app/core/actions';
  2. import { store } from 'app/store/store';
  3. import { removePanel, duplicatePanel, copyPanel, editPanelJson, sharePanel } from 'app/features/dashboard/utils/panel';
  4. import { PanelModel } from 'app/features/dashboard/panel_model';
  5. import { DashboardModel } from 'app/features/dashboard/dashboard_model';
  6. import { PanelMenuItem } from '@grafana/ui';
  7. export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
  8. const onViewPanel = () => {
  9. store.dispatch(
  10. updateLocation({
  11. query: {
  12. panelId: panel.id,
  13. edit: null,
  14. fullscreen: true,
  15. },
  16. partial: true,
  17. })
  18. );
  19. };
  20. const onEditPanel = () => {
  21. store.dispatch(
  22. updateLocation({
  23. query: {
  24. panelId: panel.id,
  25. edit: true,
  26. fullscreen: true,
  27. },
  28. partial: true,
  29. })
  30. );
  31. };
  32. const onSharePanel = () => {
  33. sharePanel(dashboard, panel);
  34. };
  35. const onDuplicatePanel = () => {
  36. duplicatePanel(dashboard, panel);
  37. };
  38. const onCopyPanel = () => {
  39. copyPanel(panel);
  40. };
  41. const onEditPanelJson = () => {
  42. editPanelJson(dashboard, panel);
  43. };
  44. const onRemovePanel = () => {
  45. removePanel(dashboard, panel, true);
  46. };
  47. const menu: PanelMenuItem[] = [];
  48. menu.push({
  49. text: 'View',
  50. iconClassName: 'fa fa-fw fa-eye',
  51. onClick: onViewPanel,
  52. shortcut: 'v',
  53. });
  54. if (dashboard.meta.canEdit) {
  55. menu.push({
  56. text: 'Edit',
  57. iconClassName: 'fa fa-fw fa-edit',
  58. onClick: onEditPanel,
  59. shortcut: 'e',
  60. });
  61. }
  62. menu.push({
  63. text: 'Share',
  64. iconClassName: 'fa fa-fw fa-share',
  65. onClick: onSharePanel,
  66. shortcut: 'p s',
  67. });
  68. const subMenu: PanelMenuItem[] = [];
  69. if (!panel.fullscreen && dashboard.meta.canEdit) {
  70. subMenu.push({
  71. text: 'Duplicate',
  72. onClick: onDuplicatePanel,
  73. shortcut: 'p d',
  74. });
  75. subMenu.push({
  76. text: 'Copy',
  77. onClick: onCopyPanel,
  78. });
  79. }
  80. subMenu.push({
  81. text: 'Panel JSON',
  82. onClick: onEditPanelJson,
  83. });
  84. menu.push({
  85. type: 'submenu',
  86. text: 'More...',
  87. iconClassName: 'fa fa-fw fa-cube',
  88. subMenu: subMenu,
  89. });
  90. if (dashboard.meta.canEdit) {
  91. menu.push({ type: 'divider' });
  92. menu.push({
  93. text: 'Remove',
  94. iconClassName: 'fa fa-fw fa-trash',
  95. onClick: onRemovePanel,
  96. shortcut: 'p r',
  97. });
  98. }
  99. return menu;
  100. };