@@ -27,6 +27,7 @@ export default class RequestBodyEditor extends PureComponent {
2727
2828 this . state = {
2929 isEditBox : false ,
30+ userDidModify : false ,
3031 value : ""
3132 }
3233 }
@@ -59,6 +60,11 @@ export default class RequestBodyEditor extends PureComponent {
5960 this . onChange ( this . sample ( explicitMediaType ) )
6061 }
6162
63+ resetValueToSample = ( explicitMediaType ) => {
64+ this . setState ( { userDidModify : false } )
65+ this . setValueToSample ( explicitMediaType )
66+ }
67+
6268 sample = ( explicitMediaType ) => {
6369 let { requestBody, mediaType } = this . props
6470 let schema = requestBody . getIn ( [ "content" , explicitMediaType || mediaType , "schema" ] ) . toJS ( )
@@ -78,6 +84,7 @@ export default class RequestBodyEditor extends PureComponent {
7884 const isJson = / j s o n / i. test ( mediaType )
7985 const inputValue = isJson ? e . target . value . trim ( ) : e . target . value
8086
87+ this . setState ( { userDidModify : true } )
8188 this . onChange ( inputValue )
8289 }
8390
@@ -87,13 +94,14 @@ export default class RequestBodyEditor extends PureComponent {
8794 let {
8895 isExecute,
8996 getComponent,
97+ mediaType,
9098 } = this . props
9199
92100 const Button = getComponent ( "Button" )
93101 const TextArea = getComponent ( "TextArea" )
94102 const HighlightCode = getComponent ( "highlightCode" )
95103
96- let { value, isEditBox } = this . state
104+ let { value, isEditBox, userDidModify } = this . state
97105
98106 return (
99107 < div className = "body-param" >
@@ -104,14 +112,18 @@ export default class RequestBodyEditor extends PureComponent {
104112 value = { value } /> )
105113 }
106114 < div className = "body-param-options" >
107- {
108- ! isExecute ? null
109- : < div className = "body-param-edit" >
110- < Button className = { isEditBox ? "btn cancel body-param__example-edit" : "btn edit body-param__example-edit" }
111- onClick = { this . toggleIsEditBox } > { isEditBox ? "Cancel" : "Edit" }
112- </ Button >
113- </ div >
114- }
115+ < div className = "body-param-edit" >
116+ {
117+ ! isExecute ? null
118+ : < Button className = { isEditBox ? "btn cancel body-param__example-edit" : "btn edit body-param__example-edit" }
119+ onClick = { this . toggleIsEditBox } > { isEditBox ? "Cancel" : "Edit" }
120+ </ Button >
121+
122+ }
123+ { userDidModify &&
124+ < Button className = "btn" onClick = { ( ) => { this . resetValueToSample ( mediaType ) } } > Reset</ Button >
125+ }
126+ </ div >
115127 </ div >
116128
117129 </ div >
0 commit comments