revert: feat: Allow to skip submitting empty values in form data (#5830)
This reverts commit b9b32c9c93.
Refs #6203 #5830
This commit is contained in:
@@ -1,19 +1,24 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import cx from "classnames"
|
import cx from "classnames"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
|
import ImPropTypes from "react-immutable-proptypes"
|
||||||
|
|
||||||
export const ParameterIncludeEmpty = ({ isIncluded, onChange, isDisabled }) => {
|
export const ParameterIncludeEmpty = ({ param, isIncluded, onChange, isDisabled }) => {
|
||||||
const onCheckboxChange = e => {
|
const onCheckboxChange = e => {
|
||||||
onChange(e.target.checked)
|
onChange(e.target.checked)
|
||||||
}
|
}
|
||||||
return <label className={cx("parameter__empty_value_toggle", {
|
if(!param.get("allowEmptyValue")) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return <div className={cx("parameter__empty_value_toggle", {
|
||||||
"disabled": isDisabled
|
"disabled": isDisabled
|
||||||
})}>
|
})}>
|
||||||
<input type="checkbox" disabled={isDisabled} checked={!isDisabled && isIncluded} onChange={onCheckboxChange} />
|
<input type="checkbox" disabled={isDisabled} checked={!isDisabled && isIncluded} onChange={onCheckboxChange} />
|
||||||
Send empty value
|
Send empty value
|
||||||
</label>
|
</div>
|
||||||
}
|
}
|
||||||
ParameterIncludeEmpty.propTypes = {
|
ParameterIncludeEmpty.propTypes = {
|
||||||
|
param: ImPropTypes.map.isRequired,
|
||||||
isIncluded: PropTypes.bool.isRequired,
|
isIncluded: PropTypes.bool.isRequired,
|
||||||
isDisabled: PropTypes.bool.isRequired,
|
isDisabled: PropTypes.bool.isRequired,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Map, List } from "immutable"
|
|||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import ImPropTypes from "react-immutable-proptypes"
|
import ImPropTypes from "react-immutable-proptypes"
|
||||||
import win from "core/window"
|
import win from "core/window"
|
||||||
import { getSampleSchema, getExtensions, getCommonExtensions, numberToString, stringify, isEmptyValue } from "core/utils"
|
import { getSampleSchema, getExtensions, getCommonExtensions, numberToString, stringify } from "core/utils"
|
||||||
import getParameterSchema from "../../helpers/get-parameter-schema.js"
|
import getParameterSchema from "../../helpers/get-parameter-schema.js"
|
||||||
|
|
||||||
export default class ParameterRow extends Component {
|
export default class ParameterRow extends Component {
|
||||||
@@ -343,11 +343,12 @@ export default class ParameterRow extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
!bodyParam && isExecute && param.get("allowEmptyValue") ?
|
!bodyParam && isExecute ?
|
||||||
<ParameterIncludeEmpty
|
<ParameterIncludeEmpty
|
||||||
onChange={this.onChangeIncludeEmpty}
|
onChange={this.onChangeIncludeEmpty}
|
||||||
isIncluded={specSelectors.parameterInclusionSettingFor(pathMethod, param.get("name"), param.get("in"))}
|
isIncluded={specSelectors.parameterInclusionSettingFor(pathMethod, param.get("name"), param.get("in"))}
|
||||||
isDisabled={!isEmptyValue(value)} />
|
isDisabled={value && value.size !== 0}
|
||||||
|
param={param} />
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -196,7 +196,6 @@ export default class Parameters extends Component {
|
|||||||
specPath={specPath.slice(0, -1).push("requestBody")}
|
specPath={specPath.slice(0, -1).push("requestBody")}
|
||||||
requestBody={requestBody}
|
requestBody={requestBody}
|
||||||
requestBodyValue={oas3Selectors.requestBodyValue(...pathMethod)}
|
requestBodyValue={oas3Selectors.requestBodyValue(...pathMethod)}
|
||||||
requestBodyInclusionSetting={oas3Selectors.requestBodyInclusionSetting(...pathMethod)}
|
|
||||||
isExecute={isExecute}
|
isExecute={isExecute}
|
||||||
activeExamplesKey={oas3Selectors.activeExamplesMember(
|
activeExamplesKey={oas3Selectors.activeExamplesMember(
|
||||||
...pathMethod,
|
...pathMethod,
|
||||||
@@ -223,13 +222,6 @@ export default class Parameters extends Component {
|
|||||||
}
|
}
|
||||||
oas3Actions.setRequestBodyValue({ value, pathMethod })
|
oas3Actions.setRequestBodyValue({ value, pathMethod })
|
||||||
}}
|
}}
|
||||||
onChangeIncludeEmpty={(name, value) => {
|
|
||||||
oas3Actions.setRequestBodyInclusion({
|
|
||||||
pathMethod,
|
|
||||||
value,
|
|
||||||
name,
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
contentType={oas3Selectors.requestContentType(...pathMethod)}/>
|
contentType={oas3Selectors.requestContentType(...pathMethod)}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
export const UPDATE_SELECTED_SERVER = "oas3_set_servers"
|
export const UPDATE_SELECTED_SERVER = "oas3_set_servers"
|
||||||
export const UPDATE_REQUEST_BODY_VALUE = "oas3_set_request_body_value"
|
export const UPDATE_REQUEST_BODY_VALUE = "oas3_set_request_body_value"
|
||||||
export const UPDATE_REQUEST_BODY_INCLUSION = "oas3_set_request_body_inclusion"
|
|
||||||
export const UPDATE_ACTIVE_EXAMPLES_MEMBER = "oas3_set_active_examples_member"
|
export const UPDATE_ACTIVE_EXAMPLES_MEMBER = "oas3_set_active_examples_member"
|
||||||
export const UPDATE_REQUEST_CONTENT_TYPE = "oas3_set_request_content_type"
|
export const UPDATE_REQUEST_CONTENT_TYPE = "oas3_set_request_content_type"
|
||||||
export const UPDATE_RESPONSE_CONTENT_TYPE = "oas3_set_response_content_type"
|
export const UPDATE_RESPONSE_CONTENT_TYPE = "oas3_set_response_content_type"
|
||||||
@@ -23,13 +22,6 @@ export function setRequestBodyValue ({ value, pathMethod }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setRequestBodyInclusion ({ value, pathMethod, name }) {
|
|
||||||
return {
|
|
||||||
type: UPDATE_REQUEST_BODY_INCLUSION,
|
|
||||||
payload: { value, pathMethod, name }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setActiveExamplesMember ({ name, pathMethod, contextType, contextName }) {
|
export function setActiveExamplesMember ({ name, pathMethod, contextType, contextName }) {
|
||||||
return {
|
return {
|
||||||
type: UPDATE_ACTIVE_EXAMPLES_MEMBER,
|
type: UPDATE_ACTIVE_EXAMPLES_MEMBER,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from "react"
|
|||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import ImPropTypes from "react-immutable-proptypes"
|
import ImPropTypes from "react-immutable-proptypes"
|
||||||
import { Map, OrderedMap, List } from "immutable"
|
import { Map, OrderedMap, List } from "immutable"
|
||||||
import { getCommonExtensions, getSampleSchema, stringify, isEmptyValue } from "core/utils"
|
import { getCommonExtensions, getSampleSchema, stringify } from "core/utils"
|
||||||
|
|
||||||
function getDefaultRequestBodyValue(requestBody, mediaType, activeExamplesKey) {
|
function getDefaultRequestBodyValue(requestBody, mediaType, activeExamplesKey) {
|
||||||
let mediaTypeValue = requestBody.getIn(["content", mediaType])
|
let mediaTypeValue = requestBody.getIn(["content", mediaType])
|
||||||
@@ -37,7 +37,6 @@ function getDefaultRequestBodyValue(requestBody, mediaType, activeExamplesKey) {
|
|||||||
const RequestBody = ({
|
const RequestBody = ({
|
||||||
requestBody,
|
requestBody,
|
||||||
requestBodyValue,
|
requestBodyValue,
|
||||||
requestBodyInclusionSetting,
|
|
||||||
getComponent,
|
getComponent,
|
||||||
getConfigs,
|
getConfigs,
|
||||||
specSelectors,
|
specSelectors,
|
||||||
@@ -46,7 +45,6 @@ const RequestBody = ({
|
|||||||
isExecute,
|
isExecute,
|
||||||
specPath,
|
specPath,
|
||||||
onChange,
|
onChange,
|
||||||
onChangeIncludeEmpty,
|
|
||||||
activeExamplesKey,
|
activeExamplesKey,
|
||||||
updateActiveExamplesKey,
|
updateActiveExamplesKey,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -60,7 +58,6 @@ const RequestBody = ({
|
|||||||
const HighlightCode = getComponent("highlightCode")
|
const HighlightCode = getComponent("highlightCode")
|
||||||
const ExamplesSelectValueRetainer = getComponent("ExamplesSelectValueRetainer")
|
const ExamplesSelectValueRetainer = getComponent("ExamplesSelectValueRetainer")
|
||||||
const Example = getComponent("Example")
|
const Example = getComponent("Example")
|
||||||
const ParameterIncludeEmpty = getComponent("ParameterIncludeEmpty")
|
|
||||||
|
|
||||||
const { showCommonExtensions } = getConfigs()
|
const { showCommonExtensions } = getConfigs()
|
||||||
|
|
||||||
@@ -158,8 +155,7 @@ const RequestBody = ({
|
|||||||
</td>
|
</td>
|
||||||
<td className="parameters-col_description">
|
<td className="parameters-col_description">
|
||||||
<Markdown source={ description }></Markdown>
|
<Markdown source={ description }></Markdown>
|
||||||
{isExecute ? <div>
|
{isExecute ? <div><JsonSchemaForm
|
||||||
<JsonSchemaForm
|
|
||||||
fn={fn}
|
fn={fn}
|
||||||
dispatchInitialValue={!isFile}
|
dispatchInitialValue={!isFile}
|
||||||
schema={prop}
|
schema={prop}
|
||||||
@@ -169,15 +165,7 @@ const RequestBody = ({
|
|||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
onChange(value, [key])
|
onChange(value, [key])
|
||||||
}}
|
}}
|
||||||
/>
|
/></div> : null }
|
||||||
{required ? null : (
|
|
||||||
<ParameterIncludeEmpty
|
|
||||||
onChange={(value) => onChangeIncludeEmpty(key, value)}
|
|
||||||
isIncluded={requestBodyInclusionSetting.get(key)}
|
|
||||||
isDisabled={!isEmptyValue(currentValue)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div> : null }
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
})
|
})
|
||||||
@@ -255,7 +243,6 @@ const RequestBody = ({
|
|||||||
RequestBody.propTypes = {
|
RequestBody.propTypes = {
|
||||||
requestBody: ImPropTypes.orderedMap.isRequired,
|
requestBody: ImPropTypes.orderedMap.isRequired,
|
||||||
requestBodyValue: ImPropTypes.orderedMap.isRequired,
|
requestBodyValue: ImPropTypes.orderedMap.isRequired,
|
||||||
requestBodyInclusionSetting: ImPropTypes.Map.isRequired,
|
|
||||||
getComponent: PropTypes.func.isRequired,
|
getComponent: PropTypes.func.isRequired,
|
||||||
getConfigs: PropTypes.func.isRequired,
|
getConfigs: PropTypes.func.isRequired,
|
||||||
fn: PropTypes.object.isRequired,
|
fn: PropTypes.object.isRequired,
|
||||||
@@ -263,7 +250,6 @@ RequestBody.propTypes = {
|
|||||||
contentType: PropTypes.string,
|
contentType: PropTypes.string,
|
||||||
isExecute: PropTypes.bool.isRequired,
|
isExecute: PropTypes.bool.isRequired,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
onChangeIncludeEmpty: PropTypes.func.isRequired,
|
|
||||||
specPath: PropTypes.array.isRequired,
|
specPath: PropTypes.array.isRequired,
|
||||||
activeExamplesKey: PropTypes.string,
|
activeExamplesKey: PropTypes.string,
|
||||||
updateActiveExamplesKey: PropTypes.func,
|
updateActiveExamplesKey: PropTypes.func,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
UPDATE_SELECTED_SERVER,
|
UPDATE_SELECTED_SERVER,
|
||||||
UPDATE_REQUEST_BODY_VALUE,
|
UPDATE_REQUEST_BODY_VALUE,
|
||||||
UPDATE_REQUEST_BODY_INCLUSION,
|
|
||||||
UPDATE_ACTIVE_EXAMPLES_MEMBER,
|
UPDATE_ACTIVE_EXAMPLES_MEMBER,
|
||||||
UPDATE_REQUEST_CONTENT_TYPE,
|
UPDATE_REQUEST_CONTENT_TYPE,
|
||||||
UPDATE_SERVER_VARIABLE_VALUE,
|
UPDATE_SERVER_VARIABLE_VALUE,
|
||||||
@@ -17,10 +16,6 @@ export default {
|
|||||||
let [path, method] = pathMethod
|
let [path, method] = pathMethod
|
||||||
return state.setIn( [ "requestData", path, method, "bodyValue" ], value)
|
return state.setIn( [ "requestData", path, method, "bodyValue" ], value)
|
||||||
},
|
},
|
||||||
[UPDATE_REQUEST_BODY_INCLUSION]: (state, { payload: { value, pathMethod, name } } ) =>{
|
|
||||||
let [path, method] = pathMethod
|
|
||||||
return state.setIn( [ "requestData", path, method, "bodyInclusion", name ], value)
|
|
||||||
},
|
|
||||||
[UPDATE_ACTIVE_EXAMPLES_MEMBER]: (state, { payload: { name, pathMethod, contextType, contextName } } ) =>{
|
[UPDATE_ACTIVE_EXAMPLES_MEMBER]: (state, { payload: { name, pathMethod, contextType, contextName } } ) =>{
|
||||||
let [path, method] = pathMethod
|
let [path, method] = pathMethod
|
||||||
return state.setIn( [ "examples", path, method, contextType, contextName, "activeExample" ], name)
|
return state.setIn( [ "examples", path, method, contextType, contextName, "activeExample" ], name)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { OrderedMap, Map } from "immutable"
|
import { OrderedMap } from "immutable"
|
||||||
import { isOAS3 as isOAS3Helper } from "./helpers"
|
import { isOAS3 as isOAS3Helper } from "./helpers"
|
||||||
|
|
||||||
|
|
||||||
@@ -26,11 +26,6 @@ export const requestBodyValue = onlyOAS3((state, path, method) => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const requestBodyInclusionSetting = onlyOAS3((state, path, method) => {
|
|
||||||
return state.getIn(["requestData", path, method, "bodyInclusion"]) || Map()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export const activeExamplesMember = onlyOAS3((state, path, method, type, name) => {
|
export const activeExamplesMember = onlyOAS3((state, path, method, type, name) => {
|
||||||
return state.getIn(["examples", path, method, type, name, "activeExample"]) || null
|
return state.getIn(["examples", path, method, type, name, "activeExample"]) || null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import serializeError from "serialize-error"
|
|||||||
import isString from "lodash/isString"
|
import isString from "lodash/isString"
|
||||||
import debounce from "lodash/debounce"
|
import debounce from "lodash/debounce"
|
||||||
import set from "lodash/set"
|
import set from "lodash/set"
|
||||||
import { isJSONObject, paramToValue, isEmptyValue } from "core/utils"
|
import { isJSONObject, paramToValue } from "core/utils"
|
||||||
|
|
||||||
// Actions conform to FSA (flux-standard-actions)
|
// Actions conform to FSA (flux-standard-actions)
|
||||||
// {type: string,payload: Any|Error, meta: obj, error: bool}
|
// {type: string,payload: Any|Error, meta: obj, error: bool}
|
||||||
@@ -401,12 +401,11 @@ export const executeRequest = (req) =>
|
|||||||
req.requestContentType = oas3Selectors.requestContentType(pathName, method)
|
req.requestContentType = oas3Selectors.requestContentType(pathName, method)
|
||||||
req.responseContentType = oas3Selectors.responseContentType(pathName, method) || "*/*"
|
req.responseContentType = oas3Selectors.responseContentType(pathName, method) || "*/*"
|
||||||
const requestBody = oas3Selectors.requestBodyValue(pathName, method)
|
const requestBody = oas3Selectors.requestBodyValue(pathName, method)
|
||||||
const requestBodyInclusionSetting = oas3Selectors.requestBodyInclusionSetting(pathName, method)
|
|
||||||
|
|
||||||
if(isJSONObject(requestBody)) {
|
if(isJSONObject(requestBody)) {
|
||||||
req.requestBody = JSON.parse(requestBody)
|
req.requestBody = JSON.parse(requestBody)
|
||||||
} else if(requestBody && requestBody.toJS) {
|
} else if(requestBody && requestBody.toJS) {
|
||||||
req.requestBody = requestBody.filter((value, key) => !isEmptyValue(value) || requestBodyInclusionSetting.get(key)).toJS()
|
req.requestBody = requestBody.toJS()
|
||||||
} else{
|
} else{
|
||||||
req.requestBody = requestBody
|
req.requestBody = requestBody
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -956,15 +956,3 @@ function b64toB64UrlEncoded(str) {
|
|||||||
.replace(/\//g, "_")
|
.replace(/\//g, "_")
|
||||||
.replace(/=/g, "")
|
.replace(/=/g, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isEmptyValue = (value) => {
|
|
||||||
if (!value) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isImmutable(value) && value.isEmpty()) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -157,7 +157,6 @@ table
|
|||||||
}
|
}
|
||||||
|
|
||||||
.parameter__empty_value_toggle {
|
.parameter__empty_value_toggle {
|
||||||
display: block;
|
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
padding-top: 5px;
|
padding-top: 5px;
|
||||||
padding-bottom: 12px;
|
padding-bottom: 12px;
|
||||||
|
|||||||
Reference in New Issue
Block a user