Skip to content

Commit d84d356

Browse files
authored
feat(editor-save-render): configure plugin via options (#4354)
1 parent 44a088f commit d84d356

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/plugins/editor-safe-render/index.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import ErrorBoundaryWrapper from './wrap-components/ErrorBoundaryWrapper.jsx';
77
* In editor context, we want to dismiss the error produced
88
* in error boundary if editor content has changed.
99
*/
10-
const EditorSafeRenderPlugin = () => {
11-
const safeRenderPlugin = () =>
12-
SwaggerUI.plugins.SafeRender({
13-
fullOverride: true,
14-
componentList: [
10+
const EditorSafeRenderPlugin = (opts = {}) => {
11+
const isCalledWithGetSystem = typeof opts.getSystem === 'function';
12+
const defaultOptions = { componentList: [], fullOverride: false };
13+
const options = isCalledWithGetSystem ? defaultOptions : { ...defaultOptions, ...opts };
14+
15+
const plugin = () => {
16+
const safeRenderPlugin = () => {
17+
const defaultComponentList = [
1518
'TopBar',
1619
'SwaggerEditorLayout',
1720
'Editor',
@@ -24,16 +27,27 @@ const EditorSafeRenderPlugin = () => {
2427
'AlertDialog',
2528
'ConfirmDialog',
2629
'Dropzone',
27-
],
30+
];
31+
const mergedComponentList = options.fullOverride
32+
? options.componentList
33+
: [...defaultComponentList, ...options.componentList];
34+
35+
return SwaggerUI.plugins.SafeRender({
36+
fullOverride: true,
37+
componentList: mergedComponentList,
38+
});
39+
};
40+
41+
const safeRenderPluginOverride = () => ({
42+
wrapComponents: {
43+
ErrorBoundary: ErrorBoundaryWrapper,
44+
},
2845
});
2946

30-
const safeRenderPluginOverride = () => ({
31-
wrapComponents: {
32-
ErrorBoundary: ErrorBoundaryWrapper,
33-
},
34-
});
47+
return [safeRenderPlugin, safeRenderPluginOverride];
48+
};
3549

36-
return [safeRenderPlugin, safeRenderPluginOverride];
50+
return isCalledWithGetSystem ? plugin(opts) : plugin;
3751
};
3852

3953
export default EditorSafeRenderPlugin;

0 commit comments

Comments
 (0)