mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* feat(plugins): introduce dashboard panel menu placement for adding menu items
* test: add test for getPanelMenu()
* added an unique identifier for each extension.
* added context to getPluginExtensions.
* wip
* Wip
* wiwip
* Wip
* feat: WWWIIIIPPPP 🧨
* Wip
* Renamed some of the types to align a bit better.
* added limit to how many extensions a plugin can register per placement.
* decreased number of items to 2
* will trim the lenght of titles to max 25 chars.
* wrapping configure function with error handling.
* added error handling for all scenarios.
* moved extension menu items to the bottom of the more sub menu.
* added tests for configuring the title.
* minor refactorings.
* changed so you need to specify the full path in package.json.
* wip
* removed unused type.
* big refactor to make things simpler and to centralize all configure error/validation handling.
* added missing import.
* fixed failing tests.
* fixed tests.
* revert(extensions): remove static extensions config in favour of registering via AppPlugin APIs
* removed the compose that didn't work for some reason.
* added tests just to verify that validation and error handling is tied together in configuration function.
* adding some more values to the context.
* draft validation.
* added missing tests for getPanelMenu.
* added more tests.
* refactor(extensions): move logic for validating extension link config to function
* Fixed ts errors.
* Update packages/grafana-data/src/types/app.ts
Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
* Update packages/grafana-runtime/src/services/pluginExtensions/extensions.test.ts
Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
* refactor(extensions): rename limiter -> pluginPlacementCount
* refactor(getpanelmenu): remove redundant continue statement
---------
Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { AppConfigureExtension, AppPluginExtensionLink } from '@grafana/data';
|
|
|
|
import { createErrorHandling } from './errorHandling';
|
|
|
|
describe('extension error handling', () => {
|
|
const pluginId = 'grafana-basic-app';
|
|
const errorHandler = createErrorHandling<AppPluginExtensionLink>({
|
|
pluginId: pluginId,
|
|
title: 'Go to page one',
|
|
logger: jest.fn(),
|
|
});
|
|
|
|
const context = {};
|
|
const extension: AppPluginExtensionLink = {
|
|
title: 'Go to page one',
|
|
description: 'Will navigate the user to page one',
|
|
path: `/a/${pluginId}/one`,
|
|
};
|
|
|
|
it('should return configured link if configure is successful', () => {
|
|
const configureWithErrorHandling = errorHandler(() => {
|
|
return {
|
|
title: 'This is a new title',
|
|
};
|
|
});
|
|
|
|
const configured = configureWithErrorHandling(extension, context);
|
|
|
|
expect(configured).toEqual({
|
|
title: 'This is a new title',
|
|
});
|
|
});
|
|
|
|
it('should return undefined if configure throws error', () => {
|
|
const configureWithErrorHandling = errorHandler(() => {
|
|
throw new Error();
|
|
});
|
|
|
|
const configured = configureWithErrorHandling(extension, context);
|
|
|
|
expect(configured).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined if configure is promise/async-based', () => {
|
|
const promisebased = (async () => {}) as AppConfigureExtension<AppPluginExtensionLink>;
|
|
const configureWithErrorHandling = errorHandler(promisebased);
|
|
|
|
const configured = configureWithErrorHandling(extension, context);
|
|
|
|
expect(configured).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined if configure is not a function', () => {
|
|
const objectbased = {} as AppConfigureExtension<AppPluginExtensionLink>;
|
|
const configureWithErrorHandling = errorHandler(objectbased);
|
|
|
|
const configured = configureWithErrorHandling(extension, context);
|
|
|
|
expect(configured).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined if configure returns other than an object', () => {
|
|
const returnString = (() => '') as AppConfigureExtension<AppPluginExtensionLink>;
|
|
const configureWithErrorHandling = errorHandler(returnString);
|
|
|
|
const configured = configureWithErrorHandling(extension, context);
|
|
|
|
expect(configured).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined if configure returns undefined', () => {
|
|
const returnUndefined = () => undefined;
|
|
const configureWithErrorHandling = errorHandler(returnUndefined);
|
|
|
|
const configured = configureWithErrorHandling(extension, context);
|
|
|
|
expect(configured).toBeUndefined();
|
|
});
|
|
});
|