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>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user