DashboardRow: Prevent unintended editing of DashboardRow with keyboard shortcut 'e' (#39792)

This commit is contained in:
Ashley Harrison 2021-09-29 16:33:11 +01:00 committed by GitHub
parent 62dc10829a
commit ff009bee9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 1 deletions

View File

@ -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', () => {

View File

@ -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 {