Skip to content

Fixes #3596 - Deep linking issue with spaces #3661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"base64-js": "^1.2.0",
"brace": "0.7.0",
"css.escape": "1.5.1",
"deep-extend": "0.4.1",
"expect": "1.20.2",
"getbase": "^2.8.2",
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/operations.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react"
import PropTypes from "prop-types"
import { helpers } from "swagger-client"

import { createDeepLinkPath } from "core/utils"
const { opId } = helpers

export default class Operations extends React.Component {
Expand Down Expand Up @@ -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", createDeepLinkPath(tag)]
let showTag = layoutSelectors.isShown(isShownKey, docExpansion === "full" || docExpansion === "list")

return (
Expand Down Expand Up @@ -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", createDeepLinkPath(tag), createDeepLinkPath(operationId)]

const allowTryItOut = specSelectors.allowTryItOutFor(op.get("path"), op.get("method"))
const response = specSelectors.responseFor(op.get("path"), op.get("method"))
Expand Down
5 changes: 3 additions & 2 deletions src/core/plugins/deep-linking/layout-wrap-actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setHash } from "./helpers"
import { createDeepLinkPath } from "core/utils"

export const show = (ori, { getConfigs }) => (...args) => {
ori(...args)
Expand All @@ -19,12 +20,12 @@ export const show = (ori, { getConfigs }) => (...args) => {

if(type === "operations") {
let [, tag, operationId] = thing
setHash(`/${tag}/${operationId}`)
setHash(`/${createDeepLinkPath(tag)}/${createDeepLinkPath(operationId)}`)
}

if(type === "operations-tag") {
let [, tag] = thing
setHash(`/${tag}`)
setHash(`/${createDeepLinkPath(tag)}`)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/plugins/deep-linking/spec-wrap-actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scrollTo from "scroll-to-element"
import { escapeDeepLinkPath } from "core/utils"

const SCROLL_OFFSET = -5
let hasHashBeenParsed = false
Expand Down Expand Up @@ -34,14 +35,14 @@ export const updateResolved = (ori, { layoutActions, getConfigs }) => (...args)
layoutActions.show(["operations-tag", tag], true)
layoutActions.show(["operations", tag, operationId], true)

scrollTo(`#operations-${tag}-${operationId}`, {
scrollTo(`#operations-${escapeDeepLinkPath(tag)}-${escapeDeepLinkPath(operationId)}`, {
offset: SCROLL_OFFSET
})
} else if(tag) {
// Pre-expand and scroll to the tag
layoutActions.show(["operations-tag", tag], true)

scrollTo(`#operations-tag-${tag}`, {
scrollTo(`#operations-tag-${escapeDeepLinkPath(tag)}`, {
offset: SCROLL_OFFSET
})
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import some from "lodash/some"
import eq from "lodash/eq"
import { memoizedSampleFromSchema, memoizedCreateXMLExample } from "core/plugins/samples/fn"
import win from "./window"
import cssEscape from "css.escape"

const DEFAULT_REPONSE_KEY = "default"

Expand Down Expand Up @@ -650,3 +651,6 @@ export const shallowEqualKeys = (a,b, keys) => {
return eq(a[key], b[key])
})
}

export const createDeepLinkPath = (str) => str ? str.replace(/\s/g, "_") : ""
export const escapeDeepLinkPath = (str) => cssEscape( createDeepLinkPath(str) )