From 430e2a970f1509566eda4a8a3bd33ab5dd8ca764 Mon Sep 17 00:00:00 2001 From: Owen Conti Date: Wed, 13 Sep 2017 17:20:37 -0600 Subject: [PATCH] Fixes #3596 Wrap `isShownKey` values in a function that replaces spaces with underscores. When parsing the hash on route change, replace the spaces in the values with underscores again. --- src/core/components/operations.jsx | 6 +++--- src/core/plugins/deep-linking/spec-wrap-actions.js | 3 ++- src/core/utils.js | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index 2aec664a..d10f8a5b 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -1,7 +1,7 @@ import React from "react" import PropTypes from "prop-types" import { helpers } from "swagger-client" - +import { replaceSpacesWithUnderscores } from "core/utils" const { opId } = helpers export default class Operations extends React.Component { @@ -69,7 +69,7 @@ export default class Operations extends React.Component { let tagExternalDocsDescription = tagObj.getIn(["tagDetails", "externalDocs", "description"]) let tagExternalDocsUrl = tagObj.getIn(["tagDetails", "externalDocs", "url"]) - let isShownKey = ["operations-tag", tag] + let isShownKey = ["operations-tag", replaceSpacesWithUnderscores(tag)] let showTag = layoutSelectors.isShown(isShownKey, docExpansion === "full" || docExpansion === "list") return ( @@ -124,7 +124,7 @@ export default class Operations extends React.Component { const operationId = op.getIn(["operation", "operationId"]) || op.getIn(["operation", "__originalOperationId"]) || opId(op.get("operation"), path, method) || op.get("id") - const isShownKey = ["operations", tag, operationId] + const isShownKey = ["operations", replaceSpacesWithUnderscores(tag), replaceSpacesWithUnderscores(operationId)] const allowTryItOut = specSelectors.allowTryItOutFor(op.get("path"), op.get("method")) const response = specSelectors.responseFor(op.get("path"), op.get("method")) diff --git a/src/core/plugins/deep-linking/spec-wrap-actions.js b/src/core/plugins/deep-linking/spec-wrap-actions.js index bb13a6ff..79665536 100644 --- a/src/core/plugins/deep-linking/spec-wrap-actions.js +++ b/src/core/plugins/deep-linking/spec-wrap-actions.js @@ -1,4 +1,5 @@ import scrollTo from "scroll-to-element" +import { replaceSpacesWithUnderscores } from "core/utils" const SCROLL_OFFSET = -5 let hasHashBeenParsed = false @@ -27,7 +28,7 @@ export const updateResolved = (ori, { layoutActions, getConfigs }) => (...args) hash = hash.slice(1) } - let [tag, operationId] = hash.split("/") + let [tag, operationId] = hash.split("/").map(v => replaceSpacesWithUnderscores(v)) if(tag && operationId) { // Pre-expand and scroll to the operation diff --git a/src/core/utils.js b/src/core/utils.js index 743c4749..75ee0f08 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -650,3 +650,5 @@ export const shallowEqualKeys = (a,b, keys) => { return eq(a[key], b[key]) }) } + +export const replaceSpacesWithUnderscores = (str) => str.replace(/\s/, "_")