Skip to content

Commit 0d142c7

Browse files
Fix reset button in Try It Out form
1 parent e683759 commit 0d142c7

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/core/containers/OperationContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PureComponent } from "react"
22
import PropTypes from "prop-types"
33
import ImPropTypes from "react-immutable-proptypes"
44
import { opId } from "swagger-client/es/helpers"
5-
import { Iterable, fromJS, Map } from "immutable"
5+
import { Iterable, fromJS, Map, OrderedMap } from "immutable"
66

77
export default class OperationContainer extends PureComponent {
88
constructor(props, context) {
@@ -124,7 +124,7 @@ export default class OperationContainer extends PureComponent {
124124

125125
onResetClick = (pathMethod) => {
126126
const defaultRequestBodyValue = this.props.oas3Selectors.selectDefaultRequestBodyValue(...pathMethod)
127-
this.props.oas3Actions.setRequestBodyValue({ value: defaultRequestBodyValue, pathMethod })
127+
this.props.oas3Actions.setRequestBodyValue({ value: OrderedMap(JSON.parse(defaultRequestBodyValue)), pathMethod })
128128
}
129129

130130
onExecute = () => {

src/core/plugins/oas3/reducers.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ export default {
2929
// context: user switch from application/json to application/x-www-form-urlencoded
3030
currentVal = Map()
3131
}
32-
let newVal
32+
let newVal = currentVal
3333
const [...valueKeys] = value.keys()
3434
valueKeys.forEach((valueKey) => {
3535
let valueKeyVal = value.getIn([valueKey])
36-
if (!currentVal.has(valueKey)) {
37-
newVal = currentVal.setIn([valueKey, "value"], valueKeyVal)
36+
if (!newVal.has(valueKey)) {
37+
newVal = newVal.setIn([valueKey, "value"], valueKeyVal)
3838
} else if (!Map.isMap(valueKeyVal)) {
3939
// context: user input will be received as String
40-
newVal = currentVal.setIn([valueKey, "value"], valueKeyVal)
40+
newVal = newVal.setIn([valueKey, "value"], valueKeyVal)
41+
} else {
42+
// context: If multiple values are edited only last edited is string, previous are map.
43+
newVal = newVal.set(valueKey, valueKeyVal)
4144
}
4245
})
4346
return state.setIn(["requestData", path, method, "bodyValue"], newVal)

0 commit comments

Comments
 (0)