improve: add button to reset example when user modifies request body (#4185)
* Add a button to reset example when user modifys request body * lint fixes * Revert "lint fixes" This reverts commit 5395005ea775832045aee9bab4aaa538cd2f73ab. * reapply lint fixes
This commit is contained in:
@@ -27,6 +27,7 @@ export default class RequestBodyEditor extends PureComponent {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isEditBox: false,
|
isEditBox: false,
|
||||||
|
userDidModify: false,
|
||||||
value: ""
|
value: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,6 +60,11 @@ export default class RequestBodyEditor extends PureComponent {
|
|||||||
this.onChange(this.sample(explicitMediaType))
|
this.onChange(this.sample(explicitMediaType))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetValueToSample = (explicitMediaType) => {
|
||||||
|
this.setState({ userDidModify: false })
|
||||||
|
this.setValueToSample(explicitMediaType)
|
||||||
|
}
|
||||||
|
|
||||||
sample = (explicitMediaType) => {
|
sample = (explicitMediaType) => {
|
||||||
let { requestBody, mediaType } = this.props
|
let { requestBody, mediaType } = this.props
|
||||||
let schema = requestBody.getIn(["content", explicitMediaType || mediaType, "schema"]).toJS()
|
let schema = requestBody.getIn(["content", explicitMediaType || mediaType, "schema"]).toJS()
|
||||||
@@ -78,6 +84,7 @@ export default class RequestBodyEditor extends PureComponent {
|
|||||||
const isJson = /json/i.test(mediaType)
|
const isJson = /json/i.test(mediaType)
|
||||||
const inputValue = isJson ? e.target.value.trim() : e.target.value
|
const inputValue = isJson ? e.target.value.trim() : e.target.value
|
||||||
|
|
||||||
|
this.setState({ userDidModify: true })
|
||||||
this.onChange(inputValue)
|
this.onChange(inputValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,13 +94,14 @@ export default class RequestBodyEditor extends PureComponent {
|
|||||||
let {
|
let {
|
||||||
isExecute,
|
isExecute,
|
||||||
getComponent,
|
getComponent,
|
||||||
|
mediaType,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
const Button = getComponent("Button")
|
const Button = getComponent("Button")
|
||||||
const TextArea = getComponent("TextArea")
|
const TextArea = getComponent("TextArea")
|
||||||
const HighlightCode = getComponent("highlightCode")
|
const HighlightCode = getComponent("highlightCode")
|
||||||
|
|
||||||
let { value, isEditBox } = this.state
|
let { value, isEditBox, userDidModify } = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="body-param">
|
<div className="body-param">
|
||||||
@@ -104,14 +112,18 @@ export default class RequestBodyEditor extends PureComponent {
|
|||||||
value={ value }/>)
|
value={ value }/>)
|
||||||
}
|
}
|
||||||
<div className="body-param-options">
|
<div className="body-param-options">
|
||||||
{
|
<div className="body-param-edit">
|
||||||
!isExecute ? null
|
{
|
||||||
: <div className="body-param-edit">
|
!isExecute ? null
|
||||||
<Button className={isEditBox ? "btn cancel body-param__example-edit" : "btn edit body-param__example-edit"}
|
: <Button className={isEditBox ? "btn cancel body-param__example-edit" : "btn edit body-param__example-edit"}
|
||||||
onClick={this.toggleIsEditBox}>{ isEditBox ? "Cancel" : "Edit"}
|
onClick={this.toggleIsEditBox}>{ isEditBox ? "Cancel" : "Edit"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
|
{ userDidModify &&
|
||||||
|
<Button className="btn" onClick={() => { this.resetValueToSample(mediaType) }}>Reset</Button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user