mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Panel: disable edit/duplicate/delete entry for repeat panel (#21257)
This commit is contained in:
parent
d63ad9ac93
commit
512a42d2c6
@ -14,6 +14,7 @@ import { ContextSrv } from './context_srv';
|
|||||||
import { ILocationService, IRootScopeService, ITimeoutService } from 'angular';
|
import { ILocationService, IRootScopeService, ITimeoutService } from 'angular';
|
||||||
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
||||||
import { getLocationSrv } from '@grafana/runtime';
|
import { getLocationSrv } from '@grafana/runtime';
|
||||||
|
import { DashboardModel } from '../../features/dashboard/state';
|
||||||
|
|
||||||
export class KeybindingSrv {
|
export class KeybindingSrv {
|
||||||
helpModal: boolean;
|
helpModal: boolean;
|
||||||
@ -174,7 +175,7 @@ export class KeybindingSrv {
|
|||||||
this.$location.search(search);
|
this.$location.search(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
setupDashboardBindings(scope: IRootScopeService & AppEventEmitter, dashboard: any) {
|
setupDashboardBindings(scope: IRootScopeService & AppEventEmitter, dashboard: DashboardModel) {
|
||||||
this.bind('mod+o', () => {
|
this.bind('mod+o', () => {
|
||||||
dashboard.graphTooltip = (dashboard.graphTooltip + 1) % 3;
|
dashboard.graphTooltip = (dashboard.graphTooltip + 1) % 3;
|
||||||
appEvents.emit(CoreEvents.graphHoverClear);
|
appEvents.emit(CoreEvents.graphHoverClear);
|
||||||
@ -203,7 +204,7 @@ export class KeybindingSrv {
|
|||||||
|
|
||||||
// edit panel
|
// edit panel
|
||||||
this.bind('e', () => {
|
this.bind('e', () => {
|
||||||
if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
|
if (dashboard.canEditPanelById(dashboard.meta.focusPanelId)) {
|
||||||
appEvents.emit(PanelEvents.panelChangeView, {
|
appEvents.emit(PanelEvents.panelChangeView, {
|
||||||
fullscreen: true,
|
fullscreen: true,
|
||||||
edit: true,
|
edit: true,
|
||||||
@ -248,7 +249,7 @@ export class KeybindingSrv {
|
|||||||
|
|
||||||
// delete panel
|
// delete panel
|
||||||
this.bind('p r', () => {
|
this.bind('p r', () => {
|
||||||
if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
|
if (dashboard.canEditPanelById(dashboard.meta.focusPanelId)) {
|
||||||
appEvents.emit(CoreEvents.removePanel, dashboard.meta.focusPanelId);
|
appEvents.emit(CoreEvents.removePanel, dashboard.meta.focusPanelId);
|
||||||
dashboard.meta.focusPanelId = 0;
|
dashboard.meta.focusPanelId = 0;
|
||||||
}
|
}
|
||||||
@ -256,7 +257,7 @@ export class KeybindingSrv {
|
|||||||
|
|
||||||
// duplicate panel
|
// duplicate panel
|
||||||
this.bind('p d', () => {
|
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;
|
const panelIndex = dashboard.getPanelInfoById(dashboard.meta.focusPanelId).index;
|
||||||
dashboard.duplicatePanel(dashboard.panels[panelIndex]);
|
dashboard.duplicatePanel(dashboard.panels[panelIndex]);
|
||||||
}
|
}
|
||||||
|
@ -293,6 +293,14 @@ export class DashboardModel {
|
|||||||
return null;
|
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) {
|
addPanel(panelData: any) {
|
||||||
panelData.id = this.getNextPanelId();
|
panelData.id = this.getNextPanelId();
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
|
|||||||
shortcut: 'v',
|
shortcut: 'v',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dashboard.meta.canEdit) {
|
if (dashboard.canEditPanel(panel)) {
|
||||||
menu.push({
|
menu.push({
|
||||||
text: 'Edit',
|
text: 'Edit',
|
||||||
iconClassName: 'gicon gicon-editor',
|
iconClassName: 'gicon gicon-editor',
|
||||||
@ -152,7 +152,7 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
|
|||||||
|
|
||||||
const subMenu: PanelMenuItem[] = [];
|
const subMenu: PanelMenuItem[] = [];
|
||||||
|
|
||||||
if (!panel.fullscreen && dashboard.meta.canEdit) {
|
if (!panel.fullscreen && dashboard.canEditPanel(panel)) {
|
||||||
subMenu.push({
|
subMenu.push({
|
||||||
text: 'Duplicate',
|
text: 'Duplicate',
|
||||||
onClick: onDuplicatePanel,
|
onClick: onDuplicatePanel,
|
||||||
@ -178,7 +178,7 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
|
|||||||
onClick: onMore,
|
onClick: onMore,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dashboard.meta.canEdit) {
|
if (dashboard.canEditPanel(panel)) {
|
||||||
menu.push({ type: 'divider' });
|
menu.push({ type: 'divider' });
|
||||||
|
|
||||||
menu.push({
|
menu.push({
|
||||||
|
@ -127,7 +127,7 @@ export class PanelCtrl {
|
|||||||
shortcut: 'v',
|
shortcut: 'v',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.dashboard.meta.canEdit) {
|
if (this.dashboard.canEditPanel(this.panel)) {
|
||||||
menu.push({
|
menu.push({
|
||||||
text: 'Edit',
|
text: 'Edit',
|
||||||
click: 'ctrl.editPanel();',
|
click: 'ctrl.editPanel();',
|
||||||
@ -164,7 +164,7 @@ export class PanelCtrl {
|
|||||||
submenu: extendedMenu,
|
submenu: extendedMenu,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.dashboard.meta.canEdit) {
|
if (this.dashboard.canEditPanel(this.panel)) {
|
||||||
menu.push({ divider: true, role: 'Editor' });
|
menu.push({ divider: true, role: 'Editor' });
|
||||||
menu.push({
|
menu.push({
|
||||||
text: 'Remove',
|
text: 'Remove',
|
||||||
@ -180,7 +180,7 @@ export class PanelCtrl {
|
|||||||
|
|
||||||
getExtendedMenu() {
|
getExtendedMenu() {
|
||||||
const menu = [];
|
const menu = [];
|
||||||
if (!this.panel.fullscreen && this.dashboard.meta.canEdit) {
|
if (!this.panel.fullscreen && this.dashboard.canEditPanel(this.panel)) {
|
||||||
menu.push({
|
menu.push({
|
||||||
text: 'Duplicate',
|
text: 'Duplicate',
|
||||||
click: 'ctrl.duplicate()',
|
click: 'ctrl.duplicate()',
|
||||||
|
Loading…
Reference in New Issue
Block a user