mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Panel: shows correct panel menu items in view mode (#24912)
This commit is contained in:
parent
bb099cb141
commit
460847f3ed
@ -1,5 +1,6 @@
|
|||||||
import { PanelModel, DashboardModel } from '../state';
|
import { DashboardModel, PanelModel } from '../state';
|
||||||
import { getPanelMenu } from './getPanelMenu';
|
import { getPanelMenu } from './getPanelMenu';
|
||||||
|
import { describe } from '../../../../test/lib/common';
|
||||||
|
|
||||||
describe('getPanelMenu', () => {
|
describe('getPanelMenu', () => {
|
||||||
it('should return the correct panel menu items', () => {
|
it('should return the correct panel menu items', () => {
|
||||||
@ -69,4 +70,75 @@ describe('getPanelMenu', () => {
|
|||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when panel is in view mode', () => {
|
||||||
|
it('should return the correct panel menu items', () => {
|
||||||
|
const getExtendedMenu = () => [{ text: 'Toggle legend', shortcut: 'p l', click: jest.fn() }];
|
||||||
|
const ctrl: any = { getExtendedMenu };
|
||||||
|
const scope: any = { $$childHead: { ctrl } };
|
||||||
|
const angularComponent: any = { getScope: () => scope };
|
||||||
|
const panel = new PanelModel({ isViewing: true });
|
||||||
|
const dashboard = new DashboardModel({});
|
||||||
|
|
||||||
|
const menuItems = getPanelMenu(dashboard, panel, angularComponent);
|
||||||
|
expect(menuItems).toMatchInlineSnapshot(`
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"iconClassName": "eye",
|
||||||
|
"onClick": [Function],
|
||||||
|
"shortcut": "v",
|
||||||
|
"text": "View",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"iconClassName": "edit",
|
||||||
|
"onClick": [Function],
|
||||||
|
"shortcut": "e",
|
||||||
|
"text": "Edit",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"iconClassName": "share-alt",
|
||||||
|
"onClick": [Function],
|
||||||
|
"shortcut": "p s",
|
||||||
|
"text": "Share",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"iconClassName": "info-circle",
|
||||||
|
"onClick": [Function],
|
||||||
|
"shortcut": "i",
|
||||||
|
"subMenu": Array [
|
||||||
|
Object {
|
||||||
|
"onClick": [Function],
|
||||||
|
"text": "Panel JSON",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"text": "Inspect",
|
||||||
|
"type": "submenu",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"iconClassName": "cube",
|
||||||
|
"onClick": [Function],
|
||||||
|
"subMenu": Array [
|
||||||
|
Object {
|
||||||
|
"href": undefined,
|
||||||
|
"onClick": [Function],
|
||||||
|
"shortcut": "p l",
|
||||||
|
"text": "Toggle legend",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"text": "More...",
|
||||||
|
"type": "submenu",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"type": "divider",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"iconClassName": "trash-alt",
|
||||||
|
"onClick": [Function],
|
||||||
|
"shortcut": "p r",
|
||||||
|
"text": "Remove",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { updateLocation } from 'app/core/actions';
|
import { updateLocation } from 'app/core/actions';
|
||||||
import { store } from 'app/store/store';
|
import { store } from 'app/store/store';
|
||||||
import { getDataSourceSrv, getLocationSrv, AngularComponent } from '@grafana/runtime';
|
import { AngularComponent, getDataSourceSrv, getLocationSrv } from '@grafana/runtime';
|
||||||
import { PanelMenuItem } from '@grafana/data';
|
import { PanelMenuItem } from '@grafana/data';
|
||||||
import { copyPanel, duplicatePanel, removePanel, sharePanel } from 'app/features/dashboard/utils/panel';
|
import { copyPanel, duplicatePanel, removePanel, sharePanel } from 'app/features/dashboard/utils/panel';
|
||||||
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
||||||
@ -187,12 +187,12 @@ export function getPanelMenu(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!panel.isEditing) {
|
if (!panel.isEditing && subMenu.length) {
|
||||||
menu.push({
|
menu.push({
|
||||||
type: 'submenu',
|
type: 'submenu',
|
||||||
text: 'More...',
|
text: 'More...',
|
||||||
iconClassName: 'cube',
|
iconClassName: 'cube',
|
||||||
subMenu: subMenu,
|
subMenu,
|
||||||
onClick: onMore,
|
onClick: onMore,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user