mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PluginExtensions: Added onClick to link as a replacement for the command type (#65837)
* Added onClick to the link and made path optional. * Added type to the import. * revert(plugin-extensions): put back isPromise utility function * Minor update to the isPromise function. * added onClick in the panel menu item. --------- Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
This commit is contained in:
@@ -163,6 +163,31 @@ describe('getPanelMenu()', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should pass onClick from plugin extension link to menu item', () => {
|
||||
const expectedOnClick = jest.fn();
|
||||
|
||||
(getPluginExtensions as jest.Mock).mockReturnValue({
|
||||
extensions: [
|
||||
{
|
||||
pluginId: '...',
|
||||
type: PluginExtensionTypes.link,
|
||||
title: 'Declare incident when pressing this amazing menu item',
|
||||
description: 'Declaring an incident in the app',
|
||||
onClick: expectedOnClick,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const panel = new PanelModel({});
|
||||
const dashboard = createDashboardModelFixture({});
|
||||
const menuItems = getPanelMenu(dashboard, panel);
|
||||
const extensionsSubMenu = menuItems.find((i) => i.text === 'Extensions')?.subMenu;
|
||||
const menuItem = extensionsSubMenu?.find((i) => (i.text = 'Declare incident when...'));
|
||||
|
||||
menuItem?.onClick?.({} as React.MouseEvent);
|
||||
expect(expectedOnClick).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should pass context with correct values when configuring extension', () => {
|
||||
const panel = new PanelModel({
|
||||
type: 'timeseries',
|
||||
|
||||
@@ -291,6 +291,7 @@ export function getPanelMenu(
|
||||
extensionsMenu.push({
|
||||
text: truncateTitle(extension.title, 25),
|
||||
href: extension.path,
|
||||
onClick: extension.onClick,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user