feature: allowEmptyValue controls (#4788)
* add baseline tests * coerce empty strings to null when updating parameter values * add ParameterIncludeEmpty * add redux management for empty parameter value inclusion state * use name+in keying for state management instead of hash keying * update new redux method usages to name+in keying * coerce empty Immutable iterables in onChangeWrapper * OAS3 tests & support * add included empty parameters to requests before dispatching to Swagger Client * make empty inclusion interface prettier * add tests for #4587 * linter fixes * check for truthy value before reaching into property
This commit is contained in:
27
src/core/components/parameter-include-empty.jsx
Normal file
27
src/core/components/parameter-include-empty.jsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import React from "react"
|
||||
import cx from "classnames"
|
||||
import PropTypes from "prop-types"
|
||||
import ImPropTypes from "react-immutable-proptypes"
|
||||
|
||||
export const ParameterIncludeEmpty = ({ param, isIncluded, onChange, isDisabled }) => {
|
||||
const onCheckboxChange = e => {
|
||||
onChange(e.target.checked)
|
||||
}
|
||||
if(!param.get("allowEmptyValue")) {
|
||||
return null
|
||||
}
|
||||
return <div className={cx("parameter__empty_value_toggle", {
|
||||
"disabled": isDisabled
|
||||
})}>
|
||||
<input type="checkbox" disabled={isDisabled} checked={!isDisabled && isIncluded} onChange={onCheckboxChange} />
|
||||
Send empty value
|
||||
</div>
|
||||
}
|
||||
ParameterIncludeEmpty.propTypes = {
|
||||
param: ImPropTypes.map.isRequired,
|
||||
isIncluded: PropTypes.bool.isRequired,
|
||||
isDisabled: PropTypes.bool.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
export default ParameterIncludeEmpty
|
||||
@@ -15,6 +15,7 @@ export default class ParameterRow extends Component {
|
||||
isExecute: PropTypes.bool,
|
||||
onChangeConsumes: PropTypes.func.isRequired,
|
||||
specSelectors: PropTypes.object.isRequired,
|
||||
specActions: PropTypes.object.isRequired,
|
||||
pathMethod: PropTypes.array.isRequired,
|
||||
getConfigs: PropTypes.func.isRequired,
|
||||
specPath: ImPropTypes.list.isRequired
|
||||
@@ -61,7 +62,23 @@ export default class ParameterRow extends Component {
|
||||
|
||||
onChangeWrapper = (value, isXml = false) => {
|
||||
let { onChange, rawParam } = this.props
|
||||
return onChange(rawParam, value, isXml)
|
||||
let valueForUpstream
|
||||
|
||||
// Coerce empty strings and empty Immutable objects to null
|
||||
if(value === "" || (value && value.size === 0)) {
|
||||
valueForUpstream = null
|
||||
} else {
|
||||
valueForUpstream = value
|
||||
}
|
||||
|
||||
return onChange(rawParam, valueForUpstream, isXml)
|
||||
}
|
||||
|
||||
onChangeIncludeEmpty = (newValue) => {
|
||||
let { specActions, param, pathMethod } = this.props
|
||||
const paramName = param.get("name")
|
||||
const paramIn = param.get("in")
|
||||
return specActions.updateEmptyParamInclusion(pathMethod, paramName, paramIn, newValue)
|
||||
}
|
||||
|
||||
setDefaultValue = () => {
|
||||
@@ -120,6 +137,7 @@ export default class ParameterRow extends Component {
|
||||
const ModelExample = getComponent("modelExample")
|
||||
const Markdown = getComponent("Markdown")
|
||||
const ParameterExt = getComponent("ParameterExt")
|
||||
const ParameterIncludeEmpty = getComponent("ParameterIncludeEmpty")
|
||||
|
||||
let paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam)
|
||||
let format = param.get("format")
|
||||
@@ -225,6 +243,16 @@ export default class ParameterRow extends Component {
|
||||
: null
|
||||
}
|
||||
|
||||
{
|
||||
!bodyParam && isExecute ?
|
||||
<ParameterIncludeEmpty
|
||||
onChange={this.onChangeIncludeEmpty}
|
||||
isIncluded={specSelectors.parameterInclusionSettingFor(pathMethod, param.get("name"), param.get("in"))}
|
||||
isDisabled={value && value.size !== 0}
|
||||
param={param} />
|
||||
: null
|
||||
}
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
@@ -65,7 +65,8 @@ export default class Parameters extends Component {
|
||||
fn,
|
||||
getComponent,
|
||||
getConfigs,
|
||||
specSelectors,
|
||||
specSelectors,
|
||||
specActions,
|
||||
pathMethod
|
||||
} = this.props
|
||||
|
||||
@@ -107,6 +108,7 @@ export default class Parameters extends Component {
|
||||
onChange={ this.onChange }
|
||||
onChangeConsumes={this.onChangeConsumesWrapper}
|
||||
specSelectors={ specSelectors }
|
||||
specActions={specActions}
|
||||
pathMethod={ pathMethod }
|
||||
isExecute={ isExecute }/>
|
||||
)).toArray()
|
||||
|
||||
Reference in New Issue
Block a user