From 8dac7f4d963cb54eb534a0f9543a181e290a4dc1 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 21:31:44 +0300 Subject: [PATCH] [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 * 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 (cherry picked from commit 1755f8c7b764f65449df837effd5197206ab3672) Co-authored-by: Marcus Andersson --- .../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 54d5b63b838..753d783394b 100644 --- a/public/app/features/plugins/extensions/getPluginExtensions.test.ts +++ b/public/app/features/plugins/extensions/getPluginExtensions.test.ts @@ -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!' }; diff --git a/public/app/features/plugins/extensions/getPluginExtensions.ts b/public/app/features/plugins/extensions/getPluginExtensions.ts index 7440528c4bc..393815f2b5e 100644 --- a/public/app/features/plugins/extensions/getPluginExtensions.ts +++ b/public/app/features/plugins/extensions/getPluginExtensions.ts @@ -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.` ); }