UI Extensions: Rename placement to extensionPointId (#65841)

* UI Extensions: Rename `placement` to `extensionPointId`

* Fix tests.

* Fix conflicts and review notes

* Remove `placement` from some other places
This commit is contained in:
Levente Balogh
2023-04-03 17:59:54 +02:00
committed by GitHub
parent 44ccd73d46
commit 1380fa54d6
16 changed files with 126 additions and 124 deletions

View File

@@ -54,7 +54,7 @@ export * from './accesscontrol';
export * from './icon';
export {
PluginExtensionTypes,
PluginExtensionPlacements,
PluginExtensionPoints,
type PluginExtension,
type PluginExtensionLink,
type PluginExtensionConfig,

View File

@@ -29,11 +29,11 @@ export type PluginExtensionConfig<Context extends object = object, ExtraProps ex
'title' | 'description'
> &
ExtraProps & {
// The unique name of the placement
// Core Grafana placements are available in the `PluginExtensionPlacements` enum
placement: string;
// The unique identifier of the Extension Point
// (Core Grafana extension point ids are available in the `PluginExtensionPoints` enum)
extensionPointId: string;
// (Optional) A function that can be used to configure the extension dynamically based on the placement's context
// (Optional) A function that can be used to configure the extension dynamically based on the extension point's context
configure?: (
context?: Readonly<Context>
) => Partial<{ title: string; description: string } & ExtraProps> | undefined;
@@ -58,11 +58,11 @@ export type PluginExtensionEventHelpers<Context extends object = object> = {
}) => void;
};
// Placements & Contexts
// Extension Points & Contexts
// --------------------------------------------------------
// Placements available in core Grafana
export enum PluginExtensionPlacements {
// Extension Points available in core Grafana
export enum PluginExtensionPoints {
DashboardPanelMenu = 'grafana/dashboard/panel/menu',
}

View File

@@ -9,10 +9,10 @@ describe('Plugin Extensions / Get Plugin Extensions', () => {
const getter: GetPluginExtensions = jest.fn().mockReturnValue({ extensions: [] });
setPluginExtensionGetter(getter);
getPluginExtensions({ placement: 'panel-menu' });
getPluginExtensions({ extensionPointId: 'panel-menu' });
expect(getter).toHaveBeenCalledTimes(1);
expect(getter).toHaveBeenCalledWith({ placement: 'panel-menu' });
expect(getter).toHaveBeenCalledWith({ extensionPointId: 'panel-menu' });
});
test('should throw an error when trying to redefine the app-wide extension-getter function', () => {
@@ -33,7 +33,7 @@ describe('Plugin Extensions / Get Plugin Extensions', () => {
setPluginExtensionGetter(undefined);
expect(() => {
getPluginExtensions({ placement: 'panel-menu' });
getPluginExtensions({ extensionPointId: 'panel-menu' });
}).toThrowError();
});
});

View File

@@ -1,10 +1,10 @@
import { PluginExtension } from '@grafana/data';
export type GetPluginExtensions = ({
placement,
extensionPointId,
context,
}: {
placement: string;
extensionPointId: string;
context?: object | Record<string | symbol, unknown>;
}) => {
extensions: PluginExtension[];