Added onLoad()s and tweaker onToggle() to support ScrollTo functionality for Models (#5237)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
|
import Im from "immutable"
|
||||||
|
|
||||||
export default class ModelCollapse extends Component {
|
export default class ModelCollapse extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@@ -11,6 +12,8 @@ export default class ModelCollapse extends Component {
|
|||||||
classes: PropTypes.string,
|
classes: PropTypes.string,
|
||||||
onToggle: PropTypes.func,
|
onToggle: PropTypes.func,
|
||||||
hideSelfOnExpand: PropTypes.bool,
|
hideSelfOnExpand: PropTypes.bool,
|
||||||
|
layoutActions: PropTypes.object,
|
||||||
|
layoutSelectors: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@@ -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 () {
|
render () {
|
||||||
const { title, classes } = this.props
|
const { title, classes } = this.props
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,15 @@ export default class ModelWrapper extends Component {
|
|||||||
layoutSelectors: PropTypes.object.isRequired
|
layoutSelectors: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSchemaBasePath = () => {
|
||||||
|
const isOAS3 = this.props.specSelectors.isOAS3()
|
||||||
|
return isOAS3 ? ["components", "schemas"] : ["definitions"]
|
||||||
|
}
|
||||||
|
|
||||||
onToggle = (name,isShown) => {
|
onToggle = (name,isShown) => {
|
||||||
// If this prop is present, we'll have deepLinking for it
|
// If this prop is present, we'll have deepLinking for it
|
||||||
if(this.props.layoutActions) {
|
if(this.props.layoutActions) {
|
||||||
this.props.layoutActions.show(["models", name],isShown)
|
this.props.layoutActions.show([...this.getSchemaBasePath(), name],isShown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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(){
|
render(){
|
||||||
let { specSelectors, getComponent, layoutSelectors, layoutActions, getConfigs } = this.props
|
let { specSelectors, getComponent, layoutSelectors, layoutActions, getConfigs } = this.props
|
||||||
let definitions = specSelectors.definitions()
|
let definitions = specSelectors.definitions()
|
||||||
@@ -91,7 +98,8 @@ export default class Models extends Component {
|
|||||||
</span>
|
</span>
|
||||||
</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>
|
<span className="models-jump-to-path"><JumpToPath specPath={specPath} /></span>
|
||||||
<ModelCollapse
|
<ModelCollapse
|
||||||
classes="model-box"
|
classes="model-box"
|
||||||
|
|||||||
Reference in New Issue
Block a user