Commit 512a42d2 by okhowang Committed by Torkel Ödegaard

Panel: disable edit/duplicate/delete entry for repeat panel (#21257)

parent d63ad9ac
......@@ -14,6 +14,7 @@ import { ContextSrv } from './context_srv';
import { ILocationService, IRootScopeService, ITimeoutService } from 'angular';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
import { getLocationSrv } from '@grafana/runtime';
import { DashboardModel } from '../../features/dashboard/state';
export class KeybindingSrv {
helpModal: boolean;
......@@ -174,7 +175,7 @@ export class KeybindingSrv {
this.$location.search(search);
}
setupDashboardBindings(scope: IRootScopeService & AppEventEmitter, dashboard: any) {
setupDashboardBindings(scope: IRootScopeService & AppEventEmitter, dashboard: DashboardModel) {
this.bind('mod+o', () => {
dashboard.graphTooltip = (dashboard.graphTooltip + 1) % 3;
appEvents.emit(CoreEvents.graphHoverClear);
......@@ -203,7 +204,7 @@ export class KeybindingSrv {
// edit panel
this.bind('e', () => {
if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
if (dashboard.canEditPanelById(dashboard.meta.focusPanelId)) {
appEvents.emit(PanelEvents.panelChangeView, {
fullscreen: true,
edit: true,
......@@ -248,7 +249,7 @@ export class KeybindingSrv {
// delete panel
this.bind('p r', () => {
if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
if (dashboard.canEditPanelById(dashboard.meta.focusPanelId)) {
appEvents.emit(CoreEvents.removePanel, dashboard.meta.focusPanelId);
dashboard.meta.focusPanelId = 0;
}
......@@ -256,7 +257,7 @@ export class KeybindingSrv {
// duplicate panel
this.bind('p d', () => {
if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
if (dashboard.canEditPanelById(dashboard.meta.focusPanelId)) {
const panelIndex = dashboard.getPanelInfoById(dashboard.meta.focusPanelId).index;
dashboard.duplicatePanel(dashboard.panels[panelIndex]);
}
......
......@@ -293,6 +293,14 @@ export class DashboardModel {
return null;
}
canEditPanel(panel?: PanelModel): boolean {
return this.meta.canEdit && panel && !panel.repeatPanelId;
}
canEditPanelById(id: number): boolean {
return this.canEditPanel(this.getPanelById(id));
}
addPanel(panelData: any) {
panelData.id = this.getNextPanelId();
......
......@@ -107,7 +107,7 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
shortcut: 'v',
});
if (dashboard.meta.canEdit) {
if (dashboard.canEditPanel(panel)) {
menu.push({
text: 'Edit',
iconClassName: 'gicon gicon-editor',
......@@ -152,7 +152,7 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
const subMenu: PanelMenuItem[] = [];
if (!panel.fullscreen && dashboard.meta.canEdit) {
if (!panel.fullscreen && dashboard.canEditPanel(panel)) {
subMenu.push({
text: 'Duplicate',
onClick: onDuplicatePanel,
......@@ -178,7 +178,7 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
onClick: onMore,
});
if (dashboard.meta.canEdit) {
if (dashboard.canEditPanel(panel)) {
menu.push({ type: 'divider' });
menu.push({
......
......@@ -127,7 +127,7 @@ export class PanelCtrl {
shortcut: 'v',
});
if (this.dashboard.meta.canEdit) {
if (this.dashboard.canEditPanel(this.panel)) {
menu.push({
text: 'Edit',
click: 'ctrl.editPanel();',
......@@ -164,7 +164,7 @@ export class PanelCtrl {
submenu: extendedMenu,
});
if (this.dashboard.meta.canEdit) {
if (this.dashboard.canEditPanel(this.panel)) {
menu.push({ divider: true, role: 'Editor' });
menu.push({
text: 'Remove',
......@@ -180,7 +180,7 @@ export class PanelCtrl {
getExtendedMenu() {
const menu = [];
if (!this.panel.fullscreen && this.dashboard.meta.canEdit) {
if (!this.panel.fullscreen && this.dashboard.canEditPanel(this.panel)) {
menu.push({
text: 'Duplicate',
click: 'ctrl.duplicate()',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment