feat(RequestBody): set default true for 'send empty value' (#6228)
This commit is contained in:
@@ -1,22 +1,53 @@
|
||||
import React from "react"
|
||||
import React, { Component } from "react"
|
||||
import cx from "classnames"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export const ParameterIncludeEmpty = ({ isIncluded, onChange, isDisabled }) => {
|
||||
const onCheckboxChange = e => {
|
||||
onChange(e.target.checked)
|
||||
}
|
||||
return <label className={cx("parameter__empty_value_toggle", {
|
||||
"disabled": isDisabled
|
||||
})}>
|
||||
<input type="checkbox" disabled={isDisabled} checked={!isDisabled && isIncluded} onChange={onCheckboxChange} />
|
||||
Send empty value
|
||||
</label>
|
||||
}
|
||||
ParameterIncludeEmpty.propTypes = {
|
||||
|
||||
const noop = () => { }
|
||||
|
||||
const ParameterIncludeEmptyPropTypes = {
|
||||
isIncluded: PropTypes.bool.isRequired,
|
||||
isDisabled: PropTypes.bool.isRequired,
|
||||
isIncludedOptions: PropTypes.object,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
export default ParameterIncludeEmpty
|
||||
const ParameterIncludeEmptyDefaultProps = {
|
||||
onChange: noop,
|
||||
isIncludedOptions: {},
|
||||
}
|
||||
export default class ParameterIncludeEmpty extends Component {
|
||||
static propTypes = ParameterIncludeEmptyPropTypes
|
||||
static defaultProps = ParameterIncludeEmptyDefaultProps
|
||||
|
||||
componentDidMount() {
|
||||
const { isIncludedOptions, onChange } = this.props
|
||||
const { shouldDispatchInit, defaultValue } = isIncludedOptions
|
||||
if (shouldDispatchInit) {
|
||||
onChange(defaultValue)
|
||||
}
|
||||
}
|
||||
|
||||
onCheckboxChange = e => {
|
||||
const { onChange } = this.props
|
||||
onChange(e.target.checked)
|
||||
}
|
||||
|
||||
render() {
|
||||
let { isIncluded, isDisabled } = this.props
|
||||
|
||||
return (
|
||||
<div>
|
||||
<label className={cx("parameter__empty_value_toggle", {
|
||||
"disabled": isDisabled
|
||||
})}>
|
||||
<input type="checkbox"
|
||||
disabled={isDisabled}
|
||||
checked={!isDisabled && isIncluded}
|
||||
onChange={this.onCheckboxChange} />
|
||||
Send empty value
|
||||
</label>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,19 @@ const RequestBody = ({
|
||||
const handleFile = (e) => {
|
||||
onChange(e.target.files[0])
|
||||
}
|
||||
const setIsIncludedOptions = (key) => {
|
||||
let options = {
|
||||
key,
|
||||
shouldDispatchInit: false,
|
||||
defaultValue: true
|
||||
}
|
||||
let currentInclusion = requestBodyInclusionSetting.get(key, "no value")
|
||||
if (currentInclusion === "no value") {
|
||||
options.shouldDispatchInit = true
|
||||
// future: can get/set defaultValue from a config setting
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
const Markdown = getComponent("Markdown", true)
|
||||
const ModelExample = getComponent("modelExample")
|
||||
@@ -173,7 +186,8 @@ const RequestBody = ({
|
||||
{required ? null : (
|
||||
<ParameterIncludeEmpty
|
||||
onChange={(value) => onChangeIncludeEmpty(key, value)}
|
||||
isIncluded={requestBodyInclusionSetting.get(key)}
|
||||
isIncluded={requestBodyInclusionSetting.get(key) || false}
|
||||
isIncludedOptions={setIsIncludedOptions(key)}
|
||||
isDisabled={!isEmptyValue(currentValue)}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user