Skip to content
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

Adding ScrollTo support for Models #5237

Merged
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
13 changes: 13 additions & 0 deletions src/core/components/model-collapse.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from "react"
import PropTypes from "prop-types"
import Im from "immutable"

export default class ModelCollapse extends Component {
static propTypes = {
Expand All @@ -11,6 +12,8 @@ export default class ModelCollapse extends Component {
classes: PropTypes.string,
onToggle: PropTypes.func,
hideSelfOnExpand: PropTypes.bool,
layoutActions: PropTypes.object,
layoutSelectors: PropTypes.object.isRequired
}

static defaultProps = {
Expand Down Expand Up @@ -58,6 +61,16 @@ export default class ModelCollapse extends Component {
})
}

onLoad = (ref) => {
if(ref) {
const name = this.props.modelName
const scrollToKey = this.props.layoutSelectors.getScrollToKey()

if( Im.is(scrollToKey, Im.fromJS(["models", name])) ) this.toggleCollapsed()
this.props.layoutActions.readyToScroll(["models", name], ref.parentElement)
}
}

render () {
const { title, classes } = this.props

Expand Down
7 changes: 6 additions & 1 deletion src/core/components/model-wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ export default class ModelWrapper extends Component {
layoutSelectors: PropTypes.object.isRequired
}

getSchemaBasePath = () => {
const isOAS3 = this.props.specSelectors.isOAS3()
return isOAS3 ? ["components", "schemas"] : ["definitions"]
}

onToggle = (name,isShown) => {
// If this prop is present, we'll have deepLinking for it
if(this.props.layoutActions) {
this.props.layoutActions.show(["models", name],isShown)
this.props.layoutActions.show([...this.getSchemaBasePath(), name],isShown)
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/core/components/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export default class Models extends Component {
}
}

onLoad = (ref) => {
if (ref) {
const name = ref.getAttribute("data-name")
this.props.layoutActions.readyToScroll(["models", name], ref)
}
}

render(){
let { specSelectors, getComponent, layoutSelectors, layoutActions, getConfigs } = this.props
let definitions = specSelectors.definitions()
Expand Down Expand Up @@ -91,7 +98,8 @@ export default class Models extends Component {
</span>
</span>

return <div id={ `model-${name}` } className="model-container" key={ `models-section-${name}` }>
return <div id={ `model-${name}` } className="model-container" key={ `models-section-${name}` }
data-name={name} ref={this.onLoad} >
<span className="models-jump-to-path"><JumpToPath specPath={specPath} /></span>
<ModelCollapse
classes="model-box"
Expand Down