Basic OperationServers wireup

This commit is contained in:
Kyle Shockey
2017-11-30 16:34:36 -08:00
parent b3c549055d
commit 945d7a3a0f
4 changed files with 57 additions and 14 deletions

View File

@@ -5,13 +5,13 @@ import ImPropTypes from "react-immutable-proptypes"
export default class OperationServers extends React.PureComponent {
static propTypes = {
// for self
path: PropTypes.string.isRequired,
method: PropTypes.string.isRequired,
operationServers: ImPropTypes.list,
pathServers: ImPropTypes.list,
// for Servers
currentServer: PropTypes.string.isRequired,
setSelectedServer: PropTypes.func.isRequired,
setServerVariableValue: PropTypes.func.isRequired,
getSelectedServer: PropTypes.func.isRequired,
getServerVariable: PropTypes.func.isRequired,
getEffectiveServerValue: PropTypes.func.isRequired,
@@ -19,25 +19,51 @@ export default class OperationServers extends React.PureComponent {
getComponent: PropTypes.func.isRequired
}
setSelectedServer = (server) => {
const { path, method } = this.props
return this.props.setSelectedServer(server, `${path}:${method}`)
}
setServerVariableValue = (obj) => {
const { path, method } = this.props
return this.props.setServerVariableValue({
...obj,
namespace: `${path}:${method}`
})
}
getSelectedServer = () => {
const { path, method } = this.props
debugger
return this.props.getSelectedServer(`${path}:${method}`)
}
getServerVariable = (obj) => {
const { path, method } = this.props
return this.props.getServerVariable({
...obj,
namespace: `${path}:${method}`
})
}
getEffectiveServerValue = (obj) => {
const { path, method } = this.props
return this.props.getEffectiveServerValue({
...obj,
namespace: `${path}:${method}`
})
}
render() {
const {
// for self
operationServers,
pathServers,
// for Servers
currentServer,
setSelectedServer,
setServerVariableValue,
getServerVariable,
getEffectiveServerValue,
// util
getComponent
} = this.props
const serverPassthroughProps = { currentServer, setSelectedServer, setServerVariableValue, getServerVariable, getEffectiveServerValue }
const Servers = getComponent("Servers")
const serversToDisplay = operationServers || pathServers
@@ -52,8 +78,12 @@ export default class OperationServers extends React.PureComponent {
<div className="opblock-description-wrapper">
<h4>These {displaying}-level options override the global server options.</h4>
<Servers
{...serverPassthroughProps}
servers={serversToDisplay}
currentServer={this.getSelectedServer()}
setSelectedServer={this.setSelectedServer}
setServerVariableValue={this.setServerVariableValue}
getServerVariable={this.getServerVariable}
getEffectiveServerValue={this.getEffectiveServerValue}
/>
</div>
</div>

View File

@@ -18,6 +18,7 @@ export default class Servers extends React.Component {
let { servers } = this.props
//fire 'change' event to set default 'value' of select
debugger
this.setServer(servers.first().get("url"))
}