diff --git a/src/core/components/deep-link.jsx b/src/core/components/deep-link.jsx new file mode 100644 index 00000000..44aa08bb --- /dev/null +++ b/src/core/components/deep-link.jsx @@ -0,0 +1,20 @@ +import React from "react" +import PropTypes from "prop-types" + +export const DeepLink = ({ enabled, path, text }) => { + return ( + e.preventDefault() : null} + href={enabled ? `#/${path}` : null}> + {text} + + ) +} +DeepLink.propTypes = { + enabled: PropTypes.bool, + isShown: PropTypes.bool, + path: PropTypes.string, + text: PropTypes.string +} + +export default DeepLink diff --git a/src/core/components/operation.jsx b/src/core/components/operation.jsx index 5bb7fe5f..7063cf22 100644 --- a/src/core/components/operation.jsx +++ b/src/core/components/operation.jsx @@ -102,6 +102,7 @@ export default class Operation extends PureComponent { const Schemes = getComponent( "schemes" ) const OperationServers = getComponent( "OperationServers" ) const OperationExt = getComponent( "OperationExt" ) + const DeepLink = getComponent( "DeepLink" ) const { showExtensions } = getConfigs() @@ -120,12 +121,11 @@ export default class Operation extends PureComponent { and pulled in with getComponent */} {method.toUpperCase()} - e.preventDefault() : null} - href={isDeepLinkingEnabled ? `#/${isShownKey.join("/")}` : null}> - {path} - + {/*TODO: use wrapComponents here, swagger-ui doesn't care about jumpToPath */} diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index 46a04cc9..6500587e 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -37,6 +37,7 @@ export default class Operations extends React.Component { const OperationContainer = getComponent("OperationContainer", true) const Collapse = getComponent("Collapse") const Markdown = getComponent("Markdown") + const DeepLink = getComponent("DeepLink") let { docExpansion, @@ -79,12 +80,11 @@ export default class Operations extends React.Component { onClick={() => layoutActions.show(isShownKey, !showTag)} className={!tagDescription ? "opblock-tag no-desc" : "opblock-tag" } id={isShownKey.join("-")}> - e.preventDefault() : null} - href= {isDeepLinkingEnabled ? `#/${tag}` : null}> - {tag} - + { !tagDescription ? null : diff --git a/src/core/presets/base.js b/src/core/presets/base.js index 133df134..1521fa28 100644 --- a/src/core/presets/base.js +++ b/src/core/presets/base.js @@ -61,6 +61,7 @@ import PrimitiveModel from "core/components/primitive-model" import Property from "core/components/property" import TryItOutButton from "core/components/try-it-out-button" import VersionStamp from "core/components/version-stamp" +import DeepLink from "core/components/deep-link" import Markdown from "core/components/providers/markdown" @@ -121,7 +122,8 @@ export default function() { OperationExt, OperationExtRow, ParameterExt, - OperationContainer + OperationContainer, + DeepLink } } diff --git a/test/components/operations.js b/test/components/operations.js index 8a6a7506..bfcbed4f 100644 --- a/test/components/operations.js +++ b/test/components/operations.js @@ -3,11 +3,13 @@ import React from "react" import expect, { createSpy } from "expect" import { render } from "enzyme" import { fromJS } from "immutable" +import DeepLink from "components/deep-link" import Operations from "components/operations" import {Collapse} from "components/layout-utils" const components = { Collapse, + DeepLink, OperationContainer: ({ path, method }) => }