fix(system): allow wrapping components both from presets and plugins (#9919)

Refs #7232
This commit is contained in:
Vladimír Gorej
2024-05-07 11:54:12 +02:00
committed by GitHub
parent 6ae2c1fb15
commit 877470b522
7 changed files with 6 additions and 36 deletions

View File

@@ -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.

View File

@@ -39,16 +39,9 @@ Read more about the plugin system in the [Customization documentation](/docs/cus
Parameter name | Docker variable | Description
--- | --- | -----
<a name="layout"></a>`layout` | _Unavailable_ | `String="BaseLayout"`. The name of a component available via the plugin system to use as the top-level layout for Swagger UI.
<a name="pluginsOptions"></a>`pluginsOptions` | _Unavailable_ | `Object`. A Javascript object to configure plugin integration and behaviors (see below).
<a name="plugins"></a>`plugins` | _Unavailable_ | `Array=[]`. An array of plugin functions to use in Swagger UI.
<a name="presets"></a>`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
--- | --- | -----
<a name="pluginLoadType"></a>`pluginLoadType` | _Unavailable_ | `String=["legacy", "chain"]`. Control behavior of plugins when targeting the same component with wrapComponent.<br/>- `legacy` (default) : last plugin takes precedence over the others<br/>- `chain` : chain wrapComponents when targeting the same core component, allowing multiple plugins to wrap the same component
##### Display
<table role="table">

View File

@@ -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

View File

@@ -37,7 +37,6 @@ const systemFactorization = (options) => {
configs: options.configs,
},
plugins: options.presets,
pluginsOptions: options.pluginsOptions,
state,
}
}

View File

@@ -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,

View File

@@ -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 {}

View File

@@ -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 {