Skip to content

Commit 877470b

Browse files
authored
fix(system): allow wrapping components both from presets and plugins (#9919)
Refs #7232
1 parent 6ae2c1f commit 877470b

File tree

7 files changed

+6
-36
lines changed

7 files changed

+6
-36
lines changed

docs/customization/plugin-api.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ const MyWrapComponentPlugin = function(system) {
388388
}
389389
```
390390

391-
**Note:**
392-
393-
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`.
394-
395391
#### `rootInjects`
396392

397393
The `rootInjects` interface allows you to inject values at the top level of the system.

docs/usage/configuration.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,9 @@ Read more about the plugin system in the [Customization documentation](/docs/cus
3939
Parameter name | Docker variable | Description
4040
--- | --- | -----
4141
<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.
42-
<a name="pluginsOptions"></a>`pluginsOptions` | _Unavailable_ | `Object`. A Javascript object to configure plugin integration and behaviors (see below).
4342
<a name="plugins"></a>`plugins` | _Unavailable_ | `Array=[]`. An array of plugin functions to use in Swagger UI.
4443
<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.
4544

46-
##### Plugins options
47-
48-
Parameter name | Docker variable | Description
49-
--- | --- | -----
50-
<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
51-
5245
##### Display
5346

5447
<table role="table">

src/core/config/defaults.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ const defaultOptions = Object.freeze({
7070
// Plugins; ( loaded after presets )
7171
plugins: [],
7272

73-
pluginsOptions: {
74-
// Behavior during plugin registration. Can be :
75-
// - legacy (default) : the current behavior for backward compatibility – last plugin takes precedence over the others
76-
// - chain : chain wrapComponents when targeting the same core component
77-
pluginLoadType: "legacy",
78-
},
79-
8073
initialState: {},
8174

8275
// Inline Plugin

src/core/config/factorization/system.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const systemFactorization = (options) => {
3737
configs: options.configs,
3838
},
3939
plugins: options.presets,
40-
pluginsOptions: options.pluginsOptions,
4140
state,
4241
}
4342
}

src/core/config/type-cast/mappings.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ const mappings = {
5555
typeCaster: arrayTypeCaster,
5656
defaultValue: defaultOptions.plugins,
5757
},
58-
pluginsOptions: {
59-
typeCaster: objectTypeCaster,
60-
pluginsOptions: defaultOptions.pluginsOptions,
61-
},
62-
"pluginsOptions.pluginsLoadType": { typeCaster: stringTypeCaster },
6358
presets: {
6459
typeCaster: arrayTypeCaster,
6560
defaultValue: defaultOptions.presets,

src/core/system.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default class Store {
3535
deepExtend(this, {
3636
state: {},
3737
plugins: [],
38-
pluginsOptions: {},
3938
system: {
4039
configs: {},
4140
fn: {},
@@ -64,7 +63,7 @@ export default class Store {
6463
}
6564

6665
register(plugins, rebuild=true) {
67-
var pluginSystem = combinePlugins(plugins, this.getSystem(), this.pluginsOptions)
66+
var pluginSystem = combinePlugins(plugins, this.getSystem())
6867
systemExtend(this.system, pluginSystem)
6968
if(rebuild) {
7069
this.buildSystem()
@@ -311,21 +310,19 @@ export default class Store {
311310

312311
}
313312

314-
function combinePlugins(plugins, toolbox, pluginOptions) {
313+
function combinePlugins(plugins, toolbox) {
315314
if(isObject(plugins) && !isArray(plugins)) {
316315
return merge({}, plugins)
317316
}
318317

319318
if(isFunc(plugins)) {
320-
return combinePlugins(plugins(toolbox), toolbox, pluginOptions)
319+
return combinePlugins(plugins(toolbox), toolbox)
321320
}
322321

323322
if(isArray(plugins)) {
324-
const dest = pluginOptions.pluginLoadType === "chain" ? toolbox.getComponents() : {}
325-
326323
return plugins
327-
.map(plugin => combinePlugins(plugin, toolbox, pluginOptions))
328-
.reduce(systemExtend, dest)
324+
.map(plugin => combinePlugins(plugin, toolbox))
325+
.reduce(systemExtend, { components: { ...toolbox.getComponents() } })
329326
}
330327

331328
return {}

test/unit/core/system/wrapComponent.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,11 @@ describe("wrapComponents", () => {
187187
expect(children.eq(1).text()).toEqual("WOW much data")
188188
})
189189

190-
it("should wrap correctly when registering multiple plugins targeting the same component", function () {
190+
it("should wrap component correctly when performing subsequent plugin registering targeting the same component", function () {
191191

192192
// Given
193193

194194
const mySystem = new System({
195-
pluginsOptions: {
196-
pluginLoadType: "chain"
197-
},
198195
plugins: [
199196
() => {
200197
return {

0 commit comments

Comments
 (0)