mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 06:22:13 +08:00
Plugin extensions: Make description optional (#95555)
make description optional
This commit is contained in:
@ -50,7 +50,7 @@ type PluginExtensionConfigBase = {
|
||||
/**
|
||||
* A short description
|
||||
*/
|
||||
description: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
export type PluginExtensionAddedComponentConfig<Props = {}> = PluginExtensionConfigBase & {
|
||||
|
@ -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),
|
||||
};
|
||||
|
||||
|
@ -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';
|
||||
|
@ -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() &&
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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() &&
|
||||
|
@ -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,
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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()', () => {
|
||||
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user