mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
PluginExtensions: Allow to specify unkown properties in override but they will be ignored (#72273)
* fixed bug. * Update public/app/features/plugins/extensions/getPluginExtensions.ts Co-authored-by: Ben Sully <ben.sully@grafana.com> * Update public/app/features/plugins/extensions/getPluginExtensions.test.ts Co-authored-by: Ben Sully <ben.sully@grafana.com> * Update public/app/features/plugins/extensions/getPluginExtensions.ts Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> * Update public/app/features/plugins/extensions/getPluginExtensions.test.ts Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> --------- Co-authored-by: Ben Sully <ben.sully@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
This commit is contained in:
parent
9ff193f692
commit
1755f8c7b7
@ -134,18 +134,30 @@ describe('getPluginExtensions()', () => {
|
||||
expect(extension.category).toBe('Machine Learning');
|
||||
});
|
||||
|
||||
test('should hide the extension if it tries to override not-allowed properties with the configure() function', () => {
|
||||
test('should ignore restricted properties passed via the configure() function', () => {
|
||||
link2.configure = jest.fn().mockImplementation(() => ({
|
||||
// The following props are not allowed to override
|
||||
type: 'unknown-type',
|
||||
pluginId: 'another-plugin',
|
||||
|
||||
// Unknown properties
|
||||
testing: false,
|
||||
|
||||
// The following props are allowed to override
|
||||
title: 'test',
|
||||
}));
|
||||
|
||||
const registry = createPluginExtensionRegistry([{ pluginId, extensionConfigs: [link2] }]);
|
||||
const { extensions } = getPluginExtensions({ registry, extensionPointId: extensionPoint2 });
|
||||
const [extension] = extensions;
|
||||
|
||||
expect(link2.configure).toHaveBeenCalledTimes(1);
|
||||
expect(extensions).toHaveLength(0);
|
||||
expect(extensions).toHaveLength(1);
|
||||
expect(extension.title).toBe('test');
|
||||
expect(extension.type).toBe('link');
|
||||
expect(extension.pluginId).toBe('grafana-basic-app');
|
||||
//@ts-ignore
|
||||
expect(extension.testing).toBeUndefined();
|
||||
});
|
||||
test('should pass a read only context to the configure() function', () => {
|
||||
const context = { title: 'New title from the context!' };
|
||||
|
@ -139,10 +139,10 @@ function getLinkExtensionOverrides(pluginId: string, config: PluginExtensionLink
|
||||
assertStringProps({ title, description }, ['title', 'description']);
|
||||
|
||||
if (Object.keys(rest).length > 0) {
|
||||
throw new Error(
|
||||
`Invalid extension "${config.title}". Trying to override not-allowed properties: ${Object.keys(rest).join(
|
||||
logWarning(
|
||||
`Extension "${config.title}", is trying to override restricted properties: ${Object.keys(rest).join(
|
||||
', '
|
||||
)}`
|
||||
)} which will be ignored.`
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user