From 1755f8c7b764f65449df837effd5197206ab3672 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Tue, 25 Jul 2023 20:18:49 +0200 Subject: [PATCH] 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 * Update public/app/features/plugins/extensions/getPluginExtensions.test.ts Co-authored-by: Ben Sully * Update public/app/features/plugins/extensions/getPluginExtensions.ts Co-authored-by: Jack Westbrook * Update public/app/features/plugins/extensions/getPluginExtensions.test.ts Co-authored-by: Jack Westbrook --------- Co-authored-by: Ben Sully Co-authored-by: Jack Westbrook --- .../extensions/getPluginExtensions.test.ts | 16 ++++++++++++++-- .../plugins/extensions/getPluginExtensions.ts | 6 +++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/public/app/features/plugins/extensions/getPluginExtensions.test.ts b/public/app/features/plugins/extensions/getPluginExtensions.test.ts index 0ad86c5f080..ce106bce5a5 100644 --- a/public/app/features/plugins/extensions/getPluginExtensions.test.ts +++ b/public/app/features/plugins/extensions/getPluginExtensions.test.ts @@ -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!' }; diff --git a/public/app/features/plugins/extensions/getPluginExtensions.ts b/public/app/features/plugins/extensions/getPluginExtensions.ts index e878989ebf1..71acd6a365b 100644 --- a/public/app/features/plugins/extensions/getPluginExtensions.ts +++ b/public/app/features/plugins/extensions/getPluginExtensions.ts @@ -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.` ); }