From 8851b138f96ea016787b0dbe8071ee2c60276d3e Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Fri, 14 Jul 2017 00:51:26 -0700 Subject: [PATCH] Add config switch for deep linking --- src/core/index.js | 2 ++ src/core/plugins/deep-linking/layout-wrap-actions.js | 8 +++++++- src/core/plugins/deep-linking/spec-wrap-actions.js | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/index.js b/src/core/index.js index fa5db888..f624ea34 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -30,6 +30,7 @@ const CONFIGS = [ "parameterMacro", "displayOperationId", "displayRequestDuration", + "deepLinking", ] // eslint-disable-next-line no-undef @@ -61,6 +62,7 @@ module.exports = function SwaggerUI(opts) { custom: {}, displayOperationId: false, displayRequestDuration: false, + deepLinking: true, // Initial set of plugins ( TODO rename this, or refactor - we don't need presets _and_ plugins. Its just there for performance. // Instead, we can compile the first plugin ( it can be a collection of plugins ), then batch the rest. diff --git a/src/core/plugins/deep-linking/layout-wrap-actions.js b/src/core/plugins/deep-linking/layout-wrap-actions.js index a1b75d7b..72d98948 100644 --- a/src/core/plugins/deep-linking/layout-wrap-actions.js +++ b/src/core/plugins/deep-linking/layout-wrap-actions.js @@ -1,7 +1,13 @@ import { setHash } from "./helpers" -export const show = (ori, system) => (...args) => { +export const show = (ori, { getConfigs }) => (...args) => { ori(...args) + + const isDeepLinkingEnabled = getConfigs().deepLinking + if(!isDeepLinkingEnabled || isDeepLinkingEnabled === "false") { + return + } + try { let [thing, shown] = args let [type] = thing diff --git a/src/core/plugins/deep-linking/spec-wrap-actions.js b/src/core/plugins/deep-linking/spec-wrap-actions.js index fc2580e5..9d9b2847 100644 --- a/src/core/plugins/deep-linking/spec-wrap-actions.js +++ b/src/core/plugins/deep-linking/spec-wrap-actions.js @@ -4,9 +4,14 @@ const SCROLL_OFFSET = -5 let hasHashBeenParsed = false -export const updateResolved = (ori, { layoutActions }) => (...args) => { +export const updateResolved = (ori, { layoutActions, getConfigs }) => (...args) => { ori(...args) + const isDeepLinkingEnabled = getConfigs().deepLinking + if(!isDeepLinkingEnabled || isDeepLinkingEnabled === "false") { + return + } + if(window.location.hash && !hasHashBeenParsed ) { let hash = window.location.hash.slice(1) // # is first character