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

@@ -22,6 +22,7 @@ export default class Operation extends PureComponent {
specActions: PropTypes.object.isRequired,
specSelectors: PropTypes.object.isRequired,
oas3Actions: PropTypes.object.isRequired,
oas3Selectors: PropTypes.object.isRequired,
layoutActions: PropTypes.object.isRequired,
layoutSelectors: PropTypes.object.isRequired,
fn: PropTypes.object.isRequired
@@ -48,7 +49,8 @@ export default class Operation extends PureComponent {
specSelectors,
authActions,
authSelectors,
oas3Actions
oas3Actions,
oas3Selectors
} = this.props
let operationProps = this.props.operation
@@ -186,8 +188,15 @@ export default class Operation extends PureComponent {
{ !tryItOutEnabled ? null :
<OperationServers
getComponent={getComponent}
path={path}
method={method}
operationServers={operation.get("servers")}
pathServers={specSelectors.paths().getIn([path, "servers"])}
getSelectedServer={oas3Selectors.selectedServer}
setSelectedServer={oas3Actions.setSelectedServer}
setServerVariableValue={oas3Actions.setServerVariableValue}
getServerVariable={oas3Selectors.serverVariableValue}
getEffectiveServerValue={oas3Selectors.serverEffectiveValue}
/>
}

View File

@@ -35,6 +35,7 @@ export default class OperationContainer extends PureComponent {
getComponent: PropTypes.func.isRequired,
authActions: PropTypes.object,
oas3Actions: PropTypes.object,
oas3Selectors: PropTypes.object,
authSelectors: PropTypes.object,
specActions: PropTypes.object.isRequired,
specSelectors: PropTypes.object.isRequired,
@@ -149,6 +150,7 @@ export default class OperationContainer extends PureComponent {
authActions,
authSelectors,
oas3Actions,
oas3Selectors,
fn
} = this.props
@@ -189,6 +191,7 @@ export default class OperationContainer extends PureComponent {
specActions={ specActions }
specSelectors={ specSelectors }
oas3Actions={oas3Actions}
oas3Selectors={oas3Selectors}
layoutActions={ layoutActions }
layoutSelectors={ layoutSelectors }
authActions={ authActions }

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"))
}