Plugins: Renamed parts of the UI extension APIs (#63070)
* Renamed target -> id and href -> path after feedback. * fixed type issues in test page. * chore(pluginschemajson): update extensions props target -> id * this is the final. * fixed typings...again... --------- Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
This commit is contained in:
co-authored by
Jack Westbrook
parent
b88206d98f
commit
f46f8bdd3a
@@ -13,7 +13,7 @@ describe('getPluginExtensions', () => {
|
||||
type: 'link',
|
||||
title: 'Declare incident',
|
||||
description: 'Declaring an incident in the app',
|
||||
href: `/a/${pluginId}/declare-incident`,
|
||||
path: `/a/${pluginId}/declare-incident`,
|
||||
key: 1,
|
||||
},
|
||||
],
|
||||
@@ -22,26 +22,26 @@ describe('getPluginExtensions', () => {
|
||||
|
||||
it('should return a collection of extensions to the plugin', () => {
|
||||
const { extensions, error } = getPluginExtensions({
|
||||
target: `plugins/${pluginId}/${linkId}`,
|
||||
placement: `plugins/${pluginId}/${linkId}`,
|
||||
});
|
||||
|
||||
expect(extensions[0].href).toBe(`/a/${pluginId}/declare-incident`);
|
||||
expect(extensions[0].path).toBe(`/a/${pluginId}/declare-incident`);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return a description for the requested link', () => {
|
||||
const { extensions, error } = getPluginExtensions({
|
||||
target: `plugins/${pluginId}/${linkId}`,
|
||||
placement: `plugins/${pluginId}/${linkId}`,
|
||||
});
|
||||
|
||||
expect(extensions[0].href).toBe(`/a/${pluginId}/declare-incident`);
|
||||
expect(extensions[0].path).toBe(`/a/${pluginId}/declare-incident`);
|
||||
expect(extensions[0].description).toBe('Declaring an incident in the app');
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return an empty array when no links can be found', () => {
|
||||
const { extensions, error } = getPluginExtensions({
|
||||
target: `an-unknown-app/${linkId}`,
|
||||
placement: `an-unknown-app/${linkId}`,
|
||||
});
|
||||
|
||||
expect(extensions.length).toBe(0);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getPluginsExtensionRegistry, PluginsExtension } from './registry';
|
||||
|
||||
export type GetPluginExtensionsOptions = {
|
||||
target: string;
|
||||
placement: string;
|
||||
};
|
||||
|
||||
export type PluginExtensionsResult = {
|
||||
@@ -10,23 +10,23 @@ export type PluginExtensionsResult = {
|
||||
};
|
||||
|
||||
export class PluginExtensionsMissingError extends Error {
|
||||
readonly target: string;
|
||||
readonly placement: string;
|
||||
|
||||
constructor(target: string) {
|
||||
super(`Could not find extensions for '${target}'`);
|
||||
this.target = target;
|
||||
constructor(placement: string) {
|
||||
super(`Could not find extensions for '${placement}'`);
|
||||
this.placement = placement;
|
||||
this.name = PluginExtensionsMissingError.name;
|
||||
}
|
||||
}
|
||||
|
||||
export function getPluginExtensions({ target }: GetPluginExtensionsOptions): PluginExtensionsResult {
|
||||
export function getPluginExtensions({ placement }: GetPluginExtensionsOptions): PluginExtensionsResult {
|
||||
const registry = getPluginsExtensionRegistry();
|
||||
const extensions = registry[target];
|
||||
const extensions = registry[placement];
|
||||
|
||||
if (!Array.isArray(extensions)) {
|
||||
return {
|
||||
extensions: [],
|
||||
error: new PluginExtensionsMissingError(target),
|
||||
error: new PluginExtensionsMissingError(placement),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ export type PluginsExtensionLink = {
|
||||
type: 'link';
|
||||
title: string;
|
||||
description: string;
|
||||
href: string;
|
||||
path: string;
|
||||
key: number;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user