[v10.0.x] PluginExtensions: Allow to specify unkown properties in override but they will be ignored (#72301)

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>
(cherry picked from commit 1755f8c7b7)

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]andMarcus Andersson authored and GitHub committed 2023-07-25 21:31:44 +03:00
1 parent f0f42a5c52
commit 8dac7f4d96
2 files changed
+17 -5

No files matched your search

@@ -83,18 +83,30 @@ describe('getPluginExtensions()', () => {
expect(extension.path).toBe(`/a/${pluginId}/updated-path`);
});
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 frozen copy of the context to the configure() function', () => {
const context = { title: 'New title from the context!' };
@@ -82,10 +82,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.`
);
}