Skip to content

Commit e594392

Browse files
authored
Merge pull request #3980 from thompsongl/ft/deeplinking-link-component
ft/deeplinking-link-component
2 parents bb54eaa + 48fd8f7 commit e594392

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

src/core/components/deep-link.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
4+
export const DeepLink = ({ enabled, path, text }) => {
5+
return (
6+
<a className="nostyle"
7+
onClick={enabled ? (e) => e.preventDefault() : null}
8+
href={enabled ? `#/${path}` : null}>
9+
<span>{text}</span>
10+
</a>
11+
)
12+
}
13+
DeepLink.propTypes = {
14+
enabled: PropTypes.bool,
15+
isShown: PropTypes.bool,
16+
path: PropTypes.string,
17+
text: PropTypes.string
18+
}
19+
20+
export default DeepLink

src/core/components/operation.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export default class Operation extends PureComponent {
102102
const Schemes = getComponent( "schemes" )
103103
const OperationServers = getComponent( "OperationServers" )
104104
const OperationExt = getComponent( "OperationExt" )
105+
const DeepLink = getComponent( "DeepLink" )
105106

106107
const { showExtensions } = getConfigs()
107108

@@ -120,12 +121,11 @@ export default class Operation extends PureComponent {
120121
and pulled in with getComponent */}
121122
<span className="opblock-summary-method">{method.toUpperCase()}</span>
122123
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" } >
123-
<a
124-
className="nostyle"
125-
onClick={isDeepLinkingEnabled ? (e) => e.preventDefault() : null}
126-
href={isDeepLinkingEnabled ? `#/${isShownKey.join("/")}` : null}>
127-
<span>{path}</span>
128-
</a>
124+
<DeepLink
125+
enabled={isDeepLinkingEnabled}
126+
isShown={isShown}
127+
path={`${isShownKey.join("/")}`}
128+
text={path} />
129129
<JumpToPath path={specPath} /> {/*TODO: use wrapComponents here, swagger-ui doesn't care about jumpToPath */}
130130
</span>
131131

src/core/components/operations.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class Operations extends React.Component {
3737
const OperationContainer = getComponent("OperationContainer", true)
3838
const Collapse = getComponent("Collapse")
3939
const Markdown = getComponent("Markdown")
40+
const DeepLink = getComponent("DeepLink")
4041

4142
let {
4243
docExpansion,
@@ -79,12 +80,11 @@ export default class Operations extends React.Component {
7980
onClick={() => layoutActions.show(isShownKey, !showTag)}
8081
className={!tagDescription ? "opblock-tag no-desc" : "opblock-tag" }
8182
id={isShownKey.join("-")}>
82-
<a
83-
className="nostyle"
84-
onClick={isDeepLinkingEnabled ? (e) => e.preventDefault() : null}
85-
href= {isDeepLinkingEnabled ? `#/${tag}` : null}>
86-
<span>{tag}</span>
87-
</a>
83+
<DeepLink
84+
enabled={isDeepLinkingEnabled}
85+
isShown={showTag}
86+
path={tag}
87+
text={tag} />
8888
{ !tagDescription ? null :
8989
<small>
9090
<Markdown source={tagDescription} />

src/core/presets/base.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import PrimitiveModel from "core/components/primitive-model"
6161
import Property from "core/components/property"
6262
import TryItOutButton from "core/components/try-it-out-button"
6363
import VersionStamp from "core/components/version-stamp"
64+
import DeepLink from "core/components/deep-link"
6465

6566
import Markdown from "core/components/providers/markdown"
6667

@@ -121,7 +122,8 @@ export default function() {
121122
OperationExt,
122123
OperationExtRow,
123124
ParameterExt,
124-
OperationContainer
125+
OperationContainer,
126+
DeepLink
125127
}
126128
}
127129

test/components/operations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import React from "react"
33
import expect, { createSpy } from "expect"
44
import { render } from "enzyme"
55
import { fromJS } from "immutable"
6+
import DeepLink from "components/deep-link"
67
import Operations from "components/operations"
78
import {Collapse} from "components/layout-utils"
89

910
const components = {
1011
Collapse,
12+
DeepLink,
1113
OperationContainer: ({ path, method }) => <span className="mocked-op" id={`${path}-${method}`} />
1214
}
1315

0 commit comments

Comments
 (0)