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, specActions: PropTypes.object.isRequired,
specSelectors: PropTypes.object.isRequired, specSelectors: PropTypes.object.isRequired,
oas3Actions: PropTypes.object.isRequired, oas3Actions: PropTypes.object.isRequired,
oas3Selectors: PropTypes.object.isRequired,
layoutActions: PropTypes.object.isRequired, layoutActions: PropTypes.object.isRequired,
layoutSelectors: PropTypes.object.isRequired, layoutSelectors: PropTypes.object.isRequired,
fn: PropTypes.object.isRequired fn: PropTypes.object.isRequired
@@ -48,7 +49,8 @@ export default class Operation extends PureComponent {
specSelectors, specSelectors,
authActions, authActions,
authSelectors, authSelectors,
oas3Actions oas3Actions,
oas3Selectors
} = this.props } = this.props
let operationProps = this.props.operation let operationProps = this.props.operation
@@ -186,8 +188,15 @@ export default class Operation extends PureComponent {
{ !tryItOutEnabled ? null : { !tryItOutEnabled ? null :
<OperationServers <OperationServers
getComponent={getComponent} getComponent={getComponent}
path={path}
method={method}
operationServers={operation.get("servers")} operationServers={operation.get("servers")}
pathServers={specSelectors.paths().getIn([path, "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, getComponent: PropTypes.func.isRequired,
authActions: PropTypes.object, authActions: PropTypes.object,
oas3Actions: PropTypes.object, oas3Actions: PropTypes.object,
oas3Selectors: PropTypes.object,
authSelectors: PropTypes.object, authSelectors: PropTypes.object,
specActions: PropTypes.object.isRequired, specActions: PropTypes.object.isRequired,
specSelectors: PropTypes.object.isRequired, specSelectors: PropTypes.object.isRequired,
@@ -149,6 +150,7 @@ export default class OperationContainer extends PureComponent {
authActions, authActions,
authSelectors, authSelectors,
oas3Actions, oas3Actions,
oas3Selectors,
fn fn
} = this.props } = this.props
@@ -189,6 +191,7 @@ export default class OperationContainer extends PureComponent {
specActions={ specActions } specActions={ specActions }
specSelectors={ specSelectors } specSelectors={ specSelectors }
oas3Actions={oas3Actions} oas3Actions={oas3Actions}
oas3Selectors={oas3Selectors}
layoutActions={ layoutActions } layoutActions={ layoutActions }
layoutSelectors={ layoutSelectors } layoutSelectors={ layoutSelectors }
authActions={ authActions } authActions={ authActions }

View File

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

View File

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