import React, { Component } from "react" import PropTypes from "prop-types" import Im, { Map, List } from "immutable" import ImPropTypes from "react-immutable-proptypes" // More readable, just iterate over maps, only const eachMap = (iterable, fn) => iterable.valueSeq().filter(Im.Map.isMap).map(fn) export default class Parameters extends Component { constructor(props) { super(props) this.state = { callbackVisible: false, parametersVisible: true } } static propTypes = { parameters: ImPropTypes.list.isRequired, operation: PropTypes.object.isRequired, specActions: PropTypes.object.isRequired, getComponent: PropTypes.func.isRequired, specSelectors: PropTypes.object.isRequired, oas3Actions: PropTypes.object.isRequired, oas3Selectors: PropTypes.object.isRequired, fn: PropTypes.object.isRequired, tryItOutEnabled: PropTypes.bool, allowTryItOut: PropTypes.bool, onTryoutClick: PropTypes.func, onCancelClick: PropTypes.func, onChangeKey: PropTypes.array, pathMethod: PropTypes.array.isRequired, getConfigs: PropTypes.func.isRequired, specPath: ImPropTypes.list.isRequired, } static defaultProps = { onTryoutClick: Function.prototype, onCancelClick: Function.prototype, tryItOutEnabled: false, allowTryItOut: true, onChangeKey: [], specPath: [], } onChange = ( param, value, isXml ) => { let { specActions: { changeParamByIdentity }, onChangeKey, } = this.props changeParamByIdentity(onChangeKey, param, value, isXml) } onChangeConsumesWrapper = ( val ) => { let { specActions: { changeConsumesValue }, onChangeKey } = this.props changeConsumesValue(onChangeKey, val) } toggleTab = (tab) => { if(tab === "parameters"){ return this.setState({ parametersVisible: true, callbackVisible: false }) }else if(tab === "callbacks"){ return this.setState({ callbackVisible: true, parametersVisible: false }) } } render(){ let { onTryoutClick, onCancelClick, parameters, allowTryItOut, tryItOutEnabled, specPath, fn, getComponent, getConfigs, specSelectors, specActions, pathMethod, oas3Actions, oas3Selectors, operation } = this.props const ParameterRow = getComponent("parameterRow") const TryItOutButton = getComponent("TryItOutButton") const ContentType = getComponent("contentType") const Callbacks = getComponent("Callbacks", true) const RequestBody = getComponent("RequestBody", true) const isExecute = tryItOutEnabled && allowTryItOut const isOAS3 = specSelectors.isOAS3() const requestBody = operation.get("requestBody") return (
{ isOAS3 ? (
this.toggleTab("parameters")} className={`tab-item ${this.state.parametersVisible && "active"}`}>

Parameters

{ operation.get("callbacks") ? (
this.toggleTab("callbacks")} className={`tab-item ${this.state.callbackVisible && "active"}`}>

Callbacks

) : null }
) : (

Parameters

)} { allowTryItOut ? ( ) : null }
{this.state.parametersVisible ?
{ !parameters.count() ?

No parameters

:
{ eachMap(parameters, (parameter, i) => ( )).toArray() }
Name Description
}
: null } {this.state.callbackVisible ?
: null } { isOAS3 && requestBody && this.state.parametersVisible &&

Request body

{ this.props.oas3Actions.setActiveExamplesMember({ name: key, pathMethod: this.props.pathMethod, contextType: "requestBody", contextName: "requestBody" // RBs are currently not stored per-mediaType }) } } onChange={(value, path) => { if(path) { const lastValue = oas3Selectors.requestBodyValue(...pathMethod) const usableValue = Map.isMap(lastValue) ? lastValue : Map() return oas3Actions.setRequestBodyValue({ pathMethod, value: usableValue.setIn(path, value) }) } oas3Actions.setRequestBodyValue({ value, pathMethod }) }} onChangeIncludeEmpty={(name, value) => { oas3Actions.setRequestBodyInclusion({ pathMethod, value, name, }) }} contentType={oas3Selectors.requestContentType(...pathMethod)}/>
}
) } }