summaryrefslogtreecommitdiff
path: root/src/core/plugins/safe-render/index.js
blob: c45f6a02bea3ca5057c46689a75038a3558f1999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import zipObject from "lodash/zipObject"

import ErrorBoundary from "./components/error-boundary"
import Fallback from "./components/fallback"
import { componentDidCatch, withErrorBoundary } from "./fn"

const safeRenderPlugin = ({componentList = [], fullOverride = false} = {}) => ({ getSystem }) => {
  const defaultComponentList = [
    "App",
    "BaseLayout",
    "VersionPragmaFilter",
    "InfoContainer",
    "ServersContainer",
    "SchemesContainer",
    "AuthorizeBtnContainer",
    "FilterContainer",
    "Operations",
    "OperationContainer",
    "parameters",
    "responses",
    "OperationServers",
    "Models",
    "ModelWrapper",
  ]
  const mergedComponentList = fullOverride ? componentList : [...defaultComponentList, ...componentList]
  const wrapFactory = (Original, { fn }) => fn.withErrorBoundary(Original)
  const wrapComponents = zipObject(mergedComponentList, Array(mergedComponentList.length).fill(wrapFactory))

  return {
    fn: {
      componentDidCatch,
      withErrorBoundary: withErrorBoundary(getSystem),
    },
    components: {
      ErrorBoundary,
      Fallback,
    },
    wrapComponents,
  }
}

export default safeRenderPlugin