Plugin extensions: Make description optional (#95555)

make description optional
This commit is contained in:
Erik Sundell
2024-11-11 12:22:57 +01:00
committed by GitHub
parent 5bce96e8e7
commit 8148f0c3bb
11 changed files with 13 additions and 154 deletions

View File

@ -50,7 +50,7 @@ type PluginExtensionConfigBase = {
/**
* A short description
*/
description: string;
description?: string;
};
export type PluginExtensionAddedComponentConfig<Props = {}> = PluginExtensionConfigBase & {

View File

@ -83,7 +83,7 @@ export const getPluginExtensions: GetExtensions = ({
extensionPointId,
path: addedLink.path ?? '',
title: addedLink.title,
description: addedLink.description,
description: addedLink.description ?? '',
onClick: typeof addedLink.onClick,
});
// Run the configure() function with the current context, and apply the ovverides
@ -104,7 +104,7 @@ export const getPluginExtensions: GetExtensions = ({
// Configurable properties
icon: overrides?.icon || addedLink.icon,
title: overrides?.title || addedLink.title,
description: overrides?.description || addedLink.description,
description: overrides?.description || addedLink.description || '',
path: isString(path) ? getLinkExtensionPathWithTracking(pluginId, path, extensionPointId) : undefined,
category: overrides?.category || addedLink.category,
};
@ -134,7 +134,7 @@ export const getPluginExtensions: GetExtensions = ({
const componentLog = log.child({
title: addedComponent.title,
description: addedComponent.description,
description: addedComponent.description ?? '',
pluginId: addedComponent.pluginId,
});
@ -143,7 +143,7 @@ export const getPluginExtensions: GetExtensions = ({
type: PluginExtensionTypes.component,
pluginId: addedComponent.pluginId,
title: addedComponent.title,
description: addedComponent.description,
description: addedComponent.description ?? '',
component: wrapWithPluginContext(addedComponent.pluginId, addedComponent.component, componentLog),
};

View File

@ -380,29 +380,6 @@ describe('AddedComponentsRegistry', () => {
expect(Object.keys(currentState)).toHaveLength(1);
});
it('should not register component when description is missing', async () => {
const registry = new AddedComponentsRegistry();
const extensionPointId = 'grafana/alerting/home';
registry.register({
pluginId,
configs: [
{
title: 'Component 1 title',
description: '',
targets: [extensionPointId],
component: () => React.createElement('div', null, 'Hello World1'),
},
],
});
expect(log.error).toHaveBeenCalledWith(
"Could not register added component with title 'Component 1 title'. Reason: Description is missing."
);
const currentState = await registry.getState();
expect(Object.keys(currentState)).toHaveLength(0);
});
it('should not register component when title is missing', async () => {
const registry = new AddedComponentsRegistry();
const extensionPointId = 'grafana/alerting/home';

View File

@ -10,7 +10,7 @@ import { PluginExtensionConfigs, Registry, RegistryType } from './Registry';
export type AddedComponentRegistryItem<Props = {}> = {
pluginId: string;
title: string;
description: string;
description?: string;
component: React.ComponentType<Props>;
};
@ -45,13 +45,6 @@ export class AddedComponentsRegistry extends Registry<
continue;
}
if (!config.description) {
configLog.error(
`Could not register added component with title '${config.title}'. Reason: Description is missing.`
);
continue;
}
if (
pluginId !== 'grafana' &&
isGrafanaDevMode() &&

View File

@ -17,7 +17,7 @@ export type AddedLinkRegistryItem<Context extends object = object> = {
pluginId: string;
extensionPointId: string;
title: string;
description: string;
description?: string;
path?: string;
onClick?: (event: React.MouseEvent | undefined, helpers: PluginExtensionEventHelpers<Context>) => void;
configure?: PluginAddedLinksConfigureFunc<Context>;
@ -45,7 +45,7 @@ export class AddedLinksRegistry extends Registry<AddedLinkRegistryItem[], Plugin
const { path, title, description, configure, onClick, targets } = config;
const configLog = this.logger.child({
path: path ?? '',
description,
description: description ?? '',
title,
pluginId,
onClick: typeof onClick,
@ -56,11 +56,6 @@ export class AddedLinksRegistry extends Registry<AddedLinkRegistryItem[], Plugin
continue;
}
if (!description) {
configLog.error(`Could not register added link. Reason: Description is missing.`);
continue;
}
if (!isConfigureFnValid(configure)) {
configLog.error(`Could not register added link. Reason: configure is not a function.`);
continue;

View File

@ -352,29 +352,6 @@ describe('ExposedComponentsRegistry', () => {
expect(Object.keys(currentState)).toHaveLength(1);
});
it('should not register component when description is missing', async () => {
const registry = new ExposedComponentsRegistry();
registry.register({
pluginId: 'grafana-basic-app',
configs: [
{
id: 'grafana-basic-app/hello-world/v1',
title: 'not important',
description: '',
component: () => React.createElement('div', null, 'Hello World1'),
},
],
});
expect(log.error).toHaveBeenCalledWith(
"Could not register exposed component with id 'grafana-basic-app/hello-world/v1'. Reason: Description is missing."
);
const currentState = await registry.getState();
expect(Object.keys(currentState)).toHaveLength(0);
});
it('should not register component when title is missing', async () => {
const registry = new ExposedComponentsRegistry();

View File

@ -10,7 +10,7 @@ import { Registry, RegistryType, PluginExtensionConfigs } from './Registry';
export type ExposedComponentRegistryItem<Props = {}> = {
pluginId: string;
title: string;
description: string;
description?: string;
component: React.ComponentType<Props>;
};
@ -39,7 +39,7 @@ export class ExposedComponentsRegistry extends Registry<
const { id, description, title } = config;
const pointIdLog = this.logger.child({
extensionPointId: id,
description,
description: description ?? '',
title,
pluginId,
});
@ -69,11 +69,6 @@ export class ExposedComponentsRegistry extends Registry<
continue;
}
if (!description) {
pointIdLog.error(`Could not register exposed component with id '${id}'. Reason: Description is missing.`);
continue;
}
if (
pluginId !== 'grafana' &&
isGrafanaDevMode() &&

View File

@ -29,7 +29,7 @@ export function usePluginComponent<Props extends object = {}>(id: string): UsePl
const registryItem = registryState[id];
const componentLog = log.child({
title: registryItem.title,
description: registryItem.description,
description: registryItem.description ?? '',
pluginId: registryItem.pluginId,
});

View File

@ -85,7 +85,7 @@ export function usePluginLinks({
const linkLog = pointLog.child({
path: addedLink.path ?? '',
title: addedLink.title,
description: addedLink.description,
description: addedLink.description ?? '',
onClick: typeof addedLink.onClick,
});
// Run the configure() function with the current context, and apply the ovverides
@ -106,7 +106,7 @@ export function usePluginLinks({
// Configurable properties
icon: overrides?.icon || addedLink.icon,
title: overrides?.title || addedLink.title,
description: overrides?.description || addedLink.description,
description: overrides?.description || addedLink.description || '',
path: isString(path) ? getLinkExtensionPathWithTracking(pluginId, path, extensionPointId) : undefined,
category: overrides?.category || addedLink.category,
};

View File

@ -554,24 +554,6 @@ describe('Plugin Extensions / Utils', () => {
expect(log.warning).toHaveBeenCalledTimes(1);
expect(jest.mocked(log.warning).mock.calls[0][0]).toMatch('"targets" don\'t match');
});
it('should return TRUE and log a warning if the "description" does not match', () => {
const log = createLogMock();
config.apps[pluginId].extensions.addedLinks.push(extensionConfig);
const returnValue = isAddedLinkMetaInfoMissing(
pluginId,
{
...extensionConfig,
description: 'Link description UPDATED',
},
log
);
expect(returnValue).toBe(true);
expect(log.warning).toHaveBeenCalledTimes(1);
expect(jest.mocked(log.warning).mock.calls[0][0]).toMatch('"description" doesn\'t match');
});
});
describe('isAddedComponentMetaInfoMissing()', () => {
@ -667,24 +649,6 @@ describe('Plugin Extensions / Utils', () => {
expect(log.warning).toHaveBeenCalledTimes(1);
expect(jest.mocked(log.warning).mock.calls[0][0]).toMatch('"targets" don\'t match');
});
it('should return TRUE and log a warning if the "description" does not match', () => {
const log = createLogMock();
config.apps[pluginId].extensions.addedComponents.push(extensionConfig);
const returnValue = isAddedComponentMetaInfoMissing(
pluginId,
{
...extensionConfig,
description: 'UPDATED',
},
log
);
expect(returnValue).toBe(true);
expect(log.warning).toHaveBeenCalledTimes(1);
expect(jest.mocked(log.warning).mock.calls[0][0]).toMatch('"description" doesn\'t match');
});
});
describe('isExposedComponentMetaInfoMissing()', () => {
@ -780,24 +744,6 @@ describe('Plugin Extensions / Utils', () => {
expect(log.warning).toHaveBeenCalledTimes(1);
expect(jest.mocked(log.warning).mock.calls[0][0]).toMatch('"title" doesn\'t match');
});
it('should return TRUE and log a warning if the "description" does not match', () => {
const log = createLogMock();
config.apps[pluginId].extensions.exposedComponents.push(exposedComponentConfig);
const returnValue = isExposedComponentMetaInfoMissing(
pluginId,
{
...exposedComponentConfig,
description: 'UPDATED',
},
log
);
expect(returnValue).toBe(true);
expect(log.warning).toHaveBeenCalledTimes(1);
expect(jest.mocked(log.warning).mock.calls[0][0]).toMatch('"description" doesn\'t match');
});
});
describe('isExposedComponentDependencyMissing()', () => {

View File

@ -490,14 +490,6 @@ export const isAddedLinkMetaInfoMissing = (
return true;
}
if (pluginJsonMetaInfo.description !== metaInfo.description) {
log.warning(
`${logPrefix} the "description" doesn't match with one in the plugin.json under "extensions.addedLinks[]".`
);
return true;
}
return false;
};
@ -530,14 +522,6 @@ export const isAddedComponentMetaInfoMissing = (
return true;
}
if (pluginJsonMetaInfo.description !== metaInfo.description) {
log.warning(
`${logPrefix} the "description" doesn't match with one in the plugin.json under "extensions.addedComponents[]".`
);
return true;
}
return false;
};
@ -569,13 +553,5 @@ export const isExposedComponentMetaInfoMissing = (
return true;
}
if (pluginJsonMetaInfo.description !== metaInfo.description) {
log.warning(
`${logPrefix} the "description" doesn't match with one in the plugin.json under "extensions.exposedComponents[]".`
);
return true;
}
return false;
};