From 877470b522838a8fab894c9aa2123ce050eac9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Tue, 7 May 2024 11:54:12 +0200 Subject: [PATCH] fix(system): allow wrapping components both from presets and plugins (#9919) Refs #7232 --- docs/customization/plugin-api.md | 4 ---- docs/usage/configuration.md | 7 ------- src/core/config/defaults.js | 7 ------- src/core/config/factorization/system.js | 1 - src/core/config/type-cast/mappings.js | 5 ----- src/core/system.js | 13 +++++-------- test/unit/core/system/wrapComponent.jsx | 5 +---- 7 files changed, 6 insertions(+), 36 deletions(-) diff --git a/docs/customization/plugin-api.md b/docs/customization/plugin-api.md index 61990187b51..d491d7e55d5 100644 --- a/docs/customization/plugin-api.md +++ b/docs/customization/plugin-api.md @@ -388,10 +388,6 @@ const MyWrapComponentPlugin = function(system) { } ``` -**Note:** - -If you have multiple plugins wrapping the same component, you may want to change the [`pluginsOptions.pluginLoadType`](/docs/usage/configuration.md#Plugins-options) parameter to `chain`. - #### `rootInjects` The `rootInjects` interface allows you to inject values at the top level of the system. diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 5d96636d440..8670dfcf74b 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -39,16 +39,9 @@ Read more about the plugin system in the [Customization documentation](/docs/cus Parameter name | Docker variable | Description --- | --- | ----- `layout` | _Unavailable_ | `String="BaseLayout"`. The name of a component available via the plugin system to use as the top-level layout for Swagger UI. -`pluginsOptions` | _Unavailable_ | `Object`. A Javascript object to configure plugin integration and behaviors (see below). `plugins` | _Unavailable_ | `Array=[]`. An array of plugin functions to use in Swagger UI. `presets` | _Unavailable_ | `Array=[SwaggerUI.presets.ApisPreset]`. An array of presets to use in Swagger UI. Usually, you'll want to include `ApisPreset` if you use this option. -##### Plugins options - -Parameter name | Docker variable | Description ---- | --- | ----- -`pluginLoadType` | _Unavailable_ | `String=["legacy", "chain"]`. Control behavior of plugins when targeting the same component with wrapComponent.
- `legacy` (default) : last plugin takes precedence over the others
- `chain` : chain wrapComponents when targeting the same core component, allowing multiple plugins to wrap the same component - ##### Display diff --git a/src/core/config/defaults.js b/src/core/config/defaults.js index 2ff789852ec..bee47f04cdd 100644 --- a/src/core/config/defaults.js +++ b/src/core/config/defaults.js @@ -70,13 +70,6 @@ const defaultOptions = Object.freeze({ // Plugins; ( loaded after presets ) plugins: [], - pluginsOptions: { - // Behavior during plugin registration. Can be : - // - legacy (default) : the current behavior for backward compatibility – last plugin takes precedence over the others - // - chain : chain wrapComponents when targeting the same core component - pluginLoadType: "legacy", - }, - initialState: {}, // Inline Plugin diff --git a/src/core/config/factorization/system.js b/src/core/config/factorization/system.js index 6ffb70adefd..864c1406fda 100644 --- a/src/core/config/factorization/system.js +++ b/src/core/config/factorization/system.js @@ -37,7 +37,6 @@ const systemFactorization = (options) => { configs: options.configs, }, plugins: options.presets, - pluginsOptions: options.pluginsOptions, state, } } diff --git a/src/core/config/type-cast/mappings.js b/src/core/config/type-cast/mappings.js index 7ec9b132fcd..b085f5ec8ce 100644 --- a/src/core/config/type-cast/mappings.js +++ b/src/core/config/type-cast/mappings.js @@ -55,11 +55,6 @@ const mappings = { typeCaster: arrayTypeCaster, defaultValue: defaultOptions.plugins, }, - pluginsOptions: { - typeCaster: objectTypeCaster, - pluginsOptions: defaultOptions.pluginsOptions, - }, - "pluginsOptions.pluginsLoadType": { typeCaster: stringTypeCaster }, presets: { typeCaster: arrayTypeCaster, defaultValue: defaultOptions.presets, diff --git a/src/core/system.js b/src/core/system.js index 54eea0782e1..051196e966d 100644 --- a/src/core/system.js +++ b/src/core/system.js @@ -35,7 +35,6 @@ export default class Store { deepExtend(this, { state: {}, plugins: [], - pluginsOptions: {}, system: { configs: {}, fn: {}, @@ -64,7 +63,7 @@ export default class Store { } register(plugins, rebuild=true) { - var pluginSystem = combinePlugins(plugins, this.getSystem(), this.pluginsOptions) + var pluginSystem = combinePlugins(plugins, this.getSystem()) systemExtend(this.system, pluginSystem) if(rebuild) { this.buildSystem() @@ -311,21 +310,19 @@ export default class Store { } -function combinePlugins(plugins, toolbox, pluginOptions) { +function combinePlugins(plugins, toolbox) { if(isObject(plugins) && !isArray(plugins)) { return merge({}, plugins) } if(isFunc(plugins)) { - return combinePlugins(plugins(toolbox), toolbox, pluginOptions) + return combinePlugins(plugins(toolbox), toolbox) } if(isArray(plugins)) { - const dest = pluginOptions.pluginLoadType === "chain" ? toolbox.getComponents() : {} - return plugins - .map(plugin => combinePlugins(plugin, toolbox, pluginOptions)) - .reduce(systemExtend, dest) + .map(plugin => combinePlugins(plugin, toolbox)) + .reduce(systemExtend, { components: { ...toolbox.getComponents() } }) } return {} diff --git a/test/unit/core/system/wrapComponent.jsx b/test/unit/core/system/wrapComponent.jsx index 3972527e29e..8a5522e7f40 100644 --- a/test/unit/core/system/wrapComponent.jsx +++ b/test/unit/core/system/wrapComponent.jsx @@ -187,14 +187,11 @@ describe("wrapComponents", () => { expect(children.eq(1).text()).toEqual("WOW much data") }) - it("should wrap correctly when registering multiple plugins targeting the same component", function () { + it("should wrap component correctly when performing subsequent plugin registering targeting the same component", function () { // Given const mySystem = new System({ - pluginsOptions: { - pluginLoadType: "chain" - }, plugins: [ () => { return {