From ad43965d168bc0de9ff708e4a1ba5ce478fa83a7 Mon Sep 17 00:00:00 2001 From: russell Date: Fri, 2 Mar 2018 21:46:47 -0500 Subject: [PATCH] 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 --- .../oas3/components/request-body-editor.jsx | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/plugins/oas3/components/request-body-editor.jsx b/src/core/plugins/oas3/components/request-body-editor.jsx index ff4c4dae..ceecfcc3 100644 --- a/src/core/plugins/oas3/components/request-body-editor.jsx +++ b/src/core/plugins/oas3/components/request-body-editor.jsx @@ -27,6 +27,7 @@ export default class RequestBodyEditor extends PureComponent { this.state = { isEditBox: false, + userDidModify: false, value: "" } } @@ -59,6 +60,11 @@ export default class RequestBodyEditor extends PureComponent { this.onChange(this.sample(explicitMediaType)) } + resetValueToSample = (explicitMediaType) => { + this.setState({ userDidModify: false }) + this.setValueToSample(explicitMediaType) + } + sample = (explicitMediaType) => { let { requestBody, mediaType } = this.props 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 inputValue = isJson ? e.target.value.trim() : e.target.value + this.setState({ userDidModify: true }) this.onChange(inputValue) } @@ -87,13 +94,14 @@ export default class RequestBodyEditor extends PureComponent { let { isExecute, getComponent, + mediaType, } = this.props const Button = getComponent("Button") const TextArea = getComponent("TextArea") const HighlightCode = getComponent("highlightCode") - let { value, isEditBox } = this.state + let { value, isEditBox, userDidModify } = this.state return (
@@ -104,14 +112,18 @@ export default class RequestBodyEditor extends PureComponent { value={ value }/>) }
- { - !isExecute ? null - :
- -
- } +
+ { + !isExecute ? null + : + + } + { userDidModify && + + } +