feat: Allow to skip submitting empty values in form data (#5830)
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
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 }) => {
|
||||
export const ParameterIncludeEmpty = ({ isIncluded, onChange, isDisabled }) => {
|
||||
const onCheckboxChange = e => {
|
||||
onChange(e.target.checked)
|
||||
}
|
||||
if(!param.get("allowEmptyValue")) {
|
||||
return null
|
||||
}
|
||||
return <div className={cx("parameter__empty_value_toggle", {
|
||||
return <label className={cx("parameter__empty_value_toggle", {
|
||||
"disabled": isDisabled
|
||||
})}>
|
||||
<input type="checkbox" disabled={isDisabled} checked={!isDisabled && isIncluded} onChange={onCheckboxChange} />
|
||||
Send empty value
|
||||
</div>
|
||||
</label>
|
||||
}
|
||||
ParameterIncludeEmpty.propTypes = {
|
||||
param: ImPropTypes.map.isRequired,
|
||||
isIncluded: PropTypes.bool.isRequired,
|
||||
isDisabled: PropTypes.bool.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Map, List } from "immutable"
|
||||
import PropTypes from "prop-types"
|
||||
import ImPropTypes from "react-immutable-proptypes"
|
||||
import win from "core/window"
|
||||
import { getSampleSchema, getExtensions, getCommonExtensions, numberToString, stringify } from "core/utils"
|
||||
import { getSampleSchema, getExtensions, getCommonExtensions, numberToString, stringify, isEmptyValue } from "core/utils"
|
||||
import getParameterSchema from "../../helpers/get-parameter-schema.js"
|
||||
|
||||
export default class ParameterRow extends Component {
|
||||
@@ -336,12 +336,11 @@ export default class ParameterRow extends Component {
|
||||
}
|
||||
|
||||
{
|
||||
!bodyParam && isExecute ?
|
||||
!bodyParam && isExecute && param.get("allowEmptyValue") ?
|
||||
<ParameterIncludeEmpty
|
||||
onChange={this.onChangeIncludeEmpty}
|
||||
isIncluded={specSelectors.parameterInclusionSettingFor(pathMethod, param.get("name"), param.get("in"))}
|
||||
isDisabled={value && value.size !== 0}
|
||||
param={param} />
|
||||
isDisabled={!isEmptyValue(value)} />
|
||||
: null
|
||||
}
|
||||
|
||||
|
||||
@@ -196,6 +196,7 @@ export default class Parameters extends Component {
|
||||
specPath={specPath.slice(0, -1).push("requestBody")}
|
||||
requestBody={requestBody}
|
||||
requestBodyValue={oas3Selectors.requestBodyValue(...pathMethod)}
|
||||
requestBodyInclusionSetting={oas3Selectors.requestBodyInclusionSetting(...pathMethod)}
|
||||
isExecute={isExecute}
|
||||
activeExamplesKey={oas3Selectors.activeExamplesMember(
|
||||
...pathMethod,
|
||||
@@ -222,6 +223,13 @@ export default class Parameters extends Component {
|
||||
}
|
||||
oas3Actions.setRequestBodyValue({ value, pathMethod })
|
||||
}}
|
||||
onChangeIncludeEmpty={(name, value) => {
|
||||
oas3Actions.setRequestBodyInclusion({
|
||||
pathMethod,
|
||||
value,
|
||||
name,
|
||||
})
|
||||
}}
|
||||
contentType={oas3Selectors.requestContentType(...pathMethod)}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user