mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardRow: Prevent unintended editing of DashboardRow with keyboard shortcut 'e' (#39792)
This commit is contained in:
parent
62dc10829a
commit
ff009bee9f
@ -766,6 +766,64 @@ describe('DashboardModel', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('canEditPanel', () => {
|
||||
it('returns false if the dashboard cannot be edited', () => {
|
||||
const dashboard = new DashboardModel({
|
||||
panels: [
|
||||
{ id: 1, type: 'row', gridPos: { x: 0, y: 0, w: 24, h: 6 } },
|
||||
{ id: 2, type: 'graph', gridPos: { x: 0, y: 7, w: 12, h: 2 } },
|
||||
],
|
||||
});
|
||||
dashboard.meta.canEdit = false;
|
||||
const panel = dashboard.getPanelById(2);
|
||||
expect(dashboard.canEditPanel(panel)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if no panel is passed in', () => {
|
||||
const dashboard = new DashboardModel({
|
||||
panels: [
|
||||
{ id: 1, type: 'row', gridPos: { x: 0, y: 0, w: 24, h: 6 } },
|
||||
{ id: 2, type: 'graph', gridPos: { x: 0, y: 7, w: 12, h: 2 } },
|
||||
],
|
||||
});
|
||||
expect(dashboard.canEditPanel()).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if the panel is a repeat', () => {
|
||||
const dashboard = new DashboardModel({
|
||||
panels: [
|
||||
{ id: 1, type: 'row', gridPos: { x: 0, y: 0, w: 24, h: 6 } },
|
||||
{ id: 2, type: 'graph', gridPos: { x: 0, y: 7, w: 12, h: 2 } },
|
||||
{ id: 3, type: 'graph', gridPos: { x: 0, y: 7, w: 12, h: 2 }, repeatPanelId: 2 },
|
||||
],
|
||||
});
|
||||
const panel = dashboard.getPanelById(3);
|
||||
expect(dashboard.canEditPanel(panel)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if the panel is a row', () => {
|
||||
const dashboard = new DashboardModel({
|
||||
panels: [
|
||||
{ id: 1, type: 'row', gridPos: { x: 0, y: 0, w: 24, h: 6 } },
|
||||
{ id: 2, type: 'graph', gridPos: { x: 0, y: 7, w: 12, h: 2 } },
|
||||
],
|
||||
});
|
||||
const panel = dashboard.getPanelById(1);
|
||||
expect(dashboard.canEditPanel(panel)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true otherwise', () => {
|
||||
const dashboard = new DashboardModel({
|
||||
panels: [
|
||||
{ id: 1, type: 'row', gridPos: { x: 0, y: 0, w: 24, h: 6 } },
|
||||
{ id: 2, type: 'graph', gridPos: { x: 0, y: 7, w: 12, h: 2 } },
|
||||
],
|
||||
});
|
||||
const panel = dashboard.getPanelById(2);
|
||||
expect(dashboard.canEditPanel(panel)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('exitViewPanel', () => {
|
||||
|
@ -470,7 +470,7 @@ export class DashboardModel {
|
||||
}
|
||||
|
||||
canEditPanel(panel?: PanelModel | null): boolean | undefined | null {
|
||||
return this.meta.canEdit && panel && !panel.repeatPanelId;
|
||||
return Boolean(this.meta.canEdit && panel && !panel.repeatPanelId && panel.type !== 'row');
|
||||
}
|
||||
|
||||
canEditPanelById(id: number): boolean | undefined | null {
|
||||
|
Loading…
Reference in New Issue
Block a user