Update Operation component to be dumb, update responses to accept Immutable prop types
This commit is contained in:
@@ -1,27 +1,16 @@
|
|||||||
import React, { PureComponent } from "react"
|
import React, { PureComponent } from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { getList } from "core/utils"
|
import { getList } from "core/utils"
|
||||||
import * as CustomPropTypes from "core/proptypes"
|
import { Iterable } from "immutable"
|
||||||
|
|
||||||
//import "less/opblock"
|
|
||||||
|
|
||||||
export default class Operation extends PureComponent {
|
export default class Operation extends PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
path: PropTypes.string.isRequired,
|
operation: PropTypes.instanceOf(Iterable).isRequired,
|
||||||
method: PropTypes.string.isRequired,
|
|
||||||
operation: PropTypes.object.isRequired,
|
|
||||||
showSummary: PropTypes.bool,
|
|
||||||
|
|
||||||
isShownKey: CustomPropTypes.arrayOrString.isRequired,
|
toggleShown: PropTypes.func.isRequired,
|
||||||
jumpToKey: CustomPropTypes.arrayOrString.isRequired,
|
onTryoutClick: PropTypes.func.isRequired,
|
||||||
|
onCancelClick: PropTypes.func.isRequired,
|
||||||
allowTryItOut: PropTypes.bool,
|
onExecute: PropTypes.func.isRequired,
|
||||||
|
|
||||||
displayOperationId: PropTypes.bool,
|
|
||||||
displayRequestDuration: PropTypes.bool,
|
|
||||||
|
|
||||||
response: PropTypes.object,
|
|
||||||
request: PropTypes.object,
|
|
||||||
|
|
||||||
getComponent: PropTypes.func.isRequired,
|
getComponent: PropTypes.func.isRequired,
|
||||||
authActions: PropTypes.object,
|
authActions: PropTypes.object,
|
||||||
@@ -30,8 +19,7 @@ export default class Operation extends PureComponent {
|
|||||||
specSelectors: PropTypes.object.isRequired,
|
specSelectors: 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
|
||||||
getConfigs: PropTypes.func.isRequired
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@@ -42,94 +30,57 @@ export default class Operation extends PureComponent {
|
|||||||
displayRequestDuration: false
|
displayRequestDuration: false
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props, context) {
|
shouldComponentUpdate(nextProps) {
|
||||||
super(props, context)
|
return this.props.operation !== nextProps.operation
|
||||||
this.state = {
|
|
||||||
tryItOutEnabled: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
const defaultContentType = "application/json"
|
|
||||||
let { specActions, path, method, operation } = nextProps
|
|
||||||
let producesValue = operation.get("produces_value")
|
|
||||||
let produces = operation.get("produces")
|
|
||||||
let consumes = operation.get("consumes")
|
|
||||||
let consumesValue = operation.get("consumes_value")
|
|
||||||
|
|
||||||
if(nextProps.response !== this.props.response) {
|
|
||||||
this.setState({ executeInProgress: false })
|
|
||||||
}
|
|
||||||
|
|
||||||
if (producesValue === undefined) {
|
|
||||||
producesValue = produces && produces.size ? produces.first() : defaultContentType
|
|
||||||
specActions.changeProducesValue([path, method], producesValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (consumesValue === undefined) {
|
|
||||||
consumesValue = consumes && consumes.size ? consumes.first() : defaultContentType
|
|
||||||
specActions.changeConsumesValue([path, method], consumesValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleShown =() => {
|
|
||||||
let { layoutActions, isShownKey } = this.props
|
|
||||||
layoutActions.show(isShownKey, !this.isShown())
|
|
||||||
}
|
|
||||||
|
|
||||||
isShown =() => {
|
|
||||||
let { layoutSelectors, isShownKey, getConfigs } = this.props
|
|
||||||
let { docExpansion } = getConfigs()
|
|
||||||
|
|
||||||
return layoutSelectors.isShown(isShownKey, docExpansion === "full" ) // Here is where we set the default
|
|
||||||
}
|
|
||||||
|
|
||||||
onTryoutClick =() => {
|
|
||||||
this.setState({tryItOutEnabled: !this.state.tryItOutEnabled})
|
|
||||||
}
|
|
||||||
|
|
||||||
onCancelClick =() => {
|
|
||||||
let { specActions, path, method } = this.props
|
|
||||||
this.setState({tryItOutEnabled: !this.state.tryItOutEnabled})
|
|
||||||
specActions.clearValidateParams([path, method])
|
|
||||||
}
|
|
||||||
|
|
||||||
onExecute = () => {
|
|
||||||
this.setState({ executeInProgress: true })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let {
|
let {
|
||||||
isShownKey,
|
toggleShown,
|
||||||
jumpToKey,
|
onTryoutClick,
|
||||||
path,
|
onCancelClick,
|
||||||
method,
|
onExecute,
|
||||||
operation,
|
|
||||||
showSummary,
|
|
||||||
response,
|
|
||||||
request,
|
|
||||||
allowTryItOut,
|
|
||||||
displayOperationId,
|
|
||||||
displayRequestDuration,
|
|
||||||
fn,
|
fn,
|
||||||
getComponent,
|
getComponent,
|
||||||
specActions,
|
specActions,
|
||||||
specSelectors,
|
specSelectors,
|
||||||
authActions,
|
authActions,
|
||||||
authSelectors,
|
authSelectors
|
||||||
getConfigs
|
|
||||||
} = this.props
|
} = this.props
|
||||||
|
let operationProps = this.props.operation
|
||||||
|
|
||||||
let summary = operation.get("summary")
|
let {
|
||||||
let description = operation.get("description")
|
isShown,
|
||||||
let deprecated = operation.get("deprecated")
|
isShownKey,
|
||||||
let externalDocs = operation.get("externalDocs")
|
jumpToKey,
|
||||||
|
path,
|
||||||
|
method,
|
||||||
|
op,
|
||||||
|
showSummary,
|
||||||
|
operationId,
|
||||||
|
allowTryItOut,
|
||||||
|
displayOperationId,
|
||||||
|
displayRequestDuration,
|
||||||
|
isDeepLinkingEnabled,
|
||||||
|
tryItOutEnabled,
|
||||||
|
executeInProgress
|
||||||
|
} = operationProps.toJS()
|
||||||
|
let response = operationProps.get("response")
|
||||||
|
let request = operationProps.get("request")
|
||||||
|
|
||||||
|
let {
|
||||||
|
summary,
|
||||||
|
description,
|
||||||
|
deprecated,
|
||||||
|
externalDocs,
|
||||||
|
schemes
|
||||||
|
} = op.operation
|
||||||
|
|
||||||
|
let operation = operationProps.getIn(["op", "operation"])
|
||||||
let responses = operation.get("responses")
|
let responses = operation.get("responses")
|
||||||
let security = operation.get("security") || specSelectors.security()
|
|
||||||
let produces = operation.get("produces")
|
let produces = operation.get("produces")
|
||||||
let schemes = operation.get("schemes")
|
let security = operation.get("security") || specSelectors.security()
|
||||||
let parameters = getList(operation, ["parameters"])
|
let parameters = getList(operation, ["parameters"])
|
||||||
let operationId = operation.get("__originalOperationId")
|
|
||||||
let operationScheme = specSelectors.operationScheme(path, method)
|
let operationScheme = specSelectors.operationScheme(path, method)
|
||||||
|
|
||||||
const Responses = getComponent("responses")
|
const Responses = getComponent("responses")
|
||||||
@@ -142,23 +93,17 @@ export default class Operation extends PureComponent {
|
|||||||
const Markdown = getComponent( "Markdown" )
|
const Markdown = getComponent( "Markdown" )
|
||||||
const Schemes = getComponent( "schemes" )
|
const Schemes = getComponent( "schemes" )
|
||||||
|
|
||||||
const { deepLinking } = getConfigs()
|
|
||||||
|
|
||||||
const isDeepLinkingEnabled = deepLinking && deepLinking !== "false"
|
|
||||||
|
|
||||||
// Merge in Live Response
|
// Merge in Live Response
|
||||||
if(response && response.size > 0) {
|
if(responses && response && response.size > 0) {
|
||||||
let notDocumented = !responses.get(String(response.get("status")))
|
let notDocumented = !responses.get(String(response.get("status")))
|
||||||
response = response.set("notDocumented", notDocumented)
|
response = response.set("notDocumented", notDocumented)
|
||||||
}
|
}
|
||||||
|
|
||||||
let { tryItOutEnabled } = this.state
|
|
||||||
let shown = this.isShown()
|
|
||||||
let onChangeKey = [ path, method ] // Used to add values to _this_ operation ( indexed by path and method )
|
let onChangeKey = [ path, method ] // Used to add values to _this_ operation ( indexed by path and method )
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={deprecated ? "opblock opblock-deprecated" : shown ? `opblock opblock-${method} is-open` : `opblock opblock-${method}`} id={isShownKey.join("-")} >
|
<div className={deprecated ? "opblock opblock-deprecated" : isShown ? `opblock opblock-${method} is-open` : `opblock opblock-${method}`} id={isShownKey.join("-")} >
|
||||||
<div className={`opblock-summary opblock-summary-${method}`} onClick={this.toggleShown} >
|
<div className={`opblock-summary opblock-summary-${method}`} onClick={toggleShown} >
|
||||||
<span className="opblock-summary-method">{method.toUpperCase()}</span>
|
<span className="opblock-summary-method">{method.toUpperCase()}</span>
|
||||||
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" } >
|
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" } >
|
||||||
<a
|
<a
|
||||||
@@ -186,7 +131,7 @@ export default class Operation extends PureComponent {
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Collapse isOpened={shown}>
|
<Collapse isOpened={isShown}>
|
||||||
<div className="opblock-body">
|
<div className="opblock-body">
|
||||||
{ deprecated && <h4 className="opblock-title_normal"> Warning: Deprecated</h4>}
|
{ deprecated && <h4 className="opblock-title_normal"> Warning: Deprecated</h4>}
|
||||||
{ description &&
|
{ description &&
|
||||||
@@ -212,8 +157,8 @@ export default class Operation extends PureComponent {
|
|||||||
parameters={parameters}
|
parameters={parameters}
|
||||||
operation={operation}
|
operation={operation}
|
||||||
onChangeKey={onChangeKey}
|
onChangeKey={onChangeKey}
|
||||||
onTryoutClick = { this.onTryoutClick }
|
onTryoutClick = { onTryoutClick }
|
||||||
onCancelClick = { this.onCancelClick }
|
onCancelClick = { onCancelClick }
|
||||||
tryItOutEnabled = { tryItOutEnabled }
|
tryItOutEnabled = { tryItOutEnabled }
|
||||||
allowTryItOut={allowTryItOut}
|
allowTryItOut={allowTryItOut}
|
||||||
|
|
||||||
@@ -237,25 +182,23 @@ export default class Operation extends PureComponent {
|
|||||||
{ !tryItOutEnabled || !allowTryItOut ? null :
|
{ !tryItOutEnabled || !allowTryItOut ? null :
|
||||||
|
|
||||||
<Execute
|
<Execute
|
||||||
getComponent={getComponent}
|
|
||||||
operation={ operation }
|
operation={ operation }
|
||||||
specActions={ specActions }
|
specActions={ specActions }
|
||||||
specSelectors={ specSelectors }
|
specSelectors={ specSelectors }
|
||||||
path={ path }
|
path={ path }
|
||||||
method={ method }
|
method={ method }
|
||||||
onExecute={ this.onExecute } />
|
onExecute={ onExecute } />
|
||||||
}
|
}
|
||||||
|
|
||||||
{ (!tryItOutEnabled || !response || !allowTryItOut) ? null :
|
{ (!tryItOutEnabled || !response || !allowTryItOut) ? null :
|
||||||
<Clear
|
<Clear
|
||||||
onClick={ this.onClearClick }
|
|
||||||
specActions={ specActions }
|
specActions={ specActions }
|
||||||
path={ path }
|
path={ path }
|
||||||
method={ method }/>
|
method={ method }/>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{this.state.executeInProgress ? <div className="loading-container"><div className="loading"></div></div> : null}
|
{executeInProgress ? <div className="loading-container"><div className="loading"></div></div> : null}
|
||||||
|
|
||||||
{ !responses ? null :
|
{ !responses ? null :
|
||||||
<Responses
|
<Responses
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { fromJS } from "immutable"
|
import { fromJS, Iterable } from "immutable"
|
||||||
import { defaultStatusCode } from "core/utils"
|
import { defaultStatusCode } from "core/utils"
|
||||||
|
|
||||||
export default class Responses extends React.Component {
|
export default class Responses extends React.Component {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
request: PropTypes.object,
|
request: PropTypes.instanceOf(Iterable),
|
||||||
tryItOutResponse: PropTypes.object,
|
tryItOutResponse: PropTypes.instanceOf(Iterable),
|
||||||
responses: PropTypes.object.isRequired,
|
responses: PropTypes.instanceOf(Iterable).isRequired,
|
||||||
produces: PropTypes.object,
|
produces: PropTypes.instanceOf(Iterable),
|
||||||
producesValue: PropTypes.any,
|
producesValue: PropTypes.any,
|
||||||
getComponent: PropTypes.func.isRequired,
|
getComponent: PropTypes.func.isRequired,
|
||||||
specSelectors: PropTypes.object.isRequired,
|
specSelectors: PropTypes.object.isRequired,
|
||||||
|
|||||||
Reference in New Issue
Block a user