1
- import React , { useEffect } from 'react' ;
1
+ // noinspection t
2
+
3
+ import React , { useEffect , useState } from 'react' ;
2
4
import "ace-builds" ;
3
5
import jsonWorkerUrl from 'ace-builds/src-min-noconflict/worker-json?url' ;
4
-
5
- ace . config . setModuleUrl ( 'ace/mode/json_worker' , jsonWorkerUrl ) ;
6
-
7
6
import AceEditor from 'react-ace' ;
8
7
import "ace-builds/src-noconflict/mode-json" ;
9
8
import "ace-builds/src-noconflict/theme-one_dark" ;
10
9
import "ace-builds/src-noconflict/ext-language_tools" ;
11
10
import useLocalStorage from 'react-use-localstorage' ;
12
11
12
+ ace . config . setModuleUrl ( 'ace/mode/json_worker' , jsonWorkerUrl ) ;
13
13
14
14
interface Props {
15
15
responseData : string ,
@@ -25,7 +25,12 @@ export default function ApiActionResponse(props: Props) {
25
25
const { responseHeaders, responseData, timeTaken, responseStatus, serverMemory, requestUri, method } = props
26
26
const [ savePreviousResponse ] = useLocalStorage ( 'savePreviousResponse' , 'false' ) ;
27
27
const [ previousResponse , setPreviousResponse ] = useLocalStorage ( 'previousResponse' + requestUri + method , '' ) ;
28
+ const [ isHtml , setIsHtml ] = useState ( false ) ;
28
29
useEffect ( ( ) => {
30
+ if ( JSON . parse ( responseHeaders ) [ 'content-type' ] . split ( ';' ) [ 0 ] === 'text/html' ) {
31
+ setIsHtml ( true )
32
+ }
33
+
29
34
if ( responseData && savePreviousResponse === 'true' ) {
30
35
setPreviousResponse ( responseData )
31
36
}
@@ -36,7 +41,7 @@ export default function ApiActionResponse(props: Props) {
36
41
{ responseHeaders && (
37
42
< >
38
43
< div className = "collapse collapse-arrow" >
39
- < input type = "checkbox" />
44
+ < input type = "checkbox" />
40
45
< div className = "collapse-title text-sm text-slate-500 pl-0" >
41
46
Show Response Headers
42
47
</ div >
@@ -49,14 +54,18 @@ export default function ApiActionResponse(props: Props) {
49
54
wrapEnabled = { true }
50
55
value = { responseHeaders }
51
56
theme = "one_dark"
52
- onLoad = { function ( editor ) { editor . renderer . setPadding ( 0 ) ; editor . renderer . setScrollMargin ( 5 , 5 , 5 , 5 ) ; editor . renderer . setShowPrintMargin ( false ) ; } }
57
+ onLoad = { function ( editor ) {
58
+ editor . renderer . setPadding ( 0 ) ;
59
+ editor . renderer . setScrollMargin ( 5 , 5 , 5 , 5 ) ;
60
+ editor . renderer . setShowPrintMargin ( false ) ;
61
+ } }
53
62
editorProps = { {
54
63
$blockScrolling : true
55
64
} }
56
65
/>
57
66
</ div >
58
67
</ div >
59
- < br />
68
+ < br />
60
69
</ >
61
70
) }
62
71
{ ( ! responseData && ! previousResponse ) && (
@@ -67,41 +76,55 @@ export default function ApiActionResponse(props: Props) {
67
76
{ ( ! responseData && previousResponse ) && (
68
77
< div className = "mockup-code mb-5" >
69
78
< span className = 'pl-5 text-sm text-warning' > Previous Response</ span >
70
- < AceEditor
71
- maxLines = { 50 }
72
- width = '100%'
73
- mode = "json"
74
- wrapEnabled = { true }
75
- readOnly = { true }
76
- value = { previousResponse }
77
- theme = "one_dark"
78
- onLoad = { function ( editor ) { editor . renderer . setPadding ( 0 ) ; editor . renderer . setScrollMargin ( 5 , 5 , 5 , 5 ) ; editor . renderer . setShowPrintMargin ( false ) ; } }
79
- editorProps = { {
80
- $blockScrolling : true
81
- } }
82
- />
79
+ { ! isHtml ? (
80
+ < AceEditor
81
+ maxLines = { 50 }
82
+ width = '100%'
83
+ mode = "json"
84
+ wrapEnabled = { true }
85
+ readOnly = { true }
86
+ value = { previousResponse }
87
+ theme = "one_dark"
88
+ onLoad = { function ( editor ) {
89
+ editor . renderer . setPadding ( 0 ) ;
90
+ editor . renderer . setScrollMargin ( 5 , 5 , 5 , 5 ) ;
91
+ editor . renderer . setShowPrintMargin ( false ) ;
92
+ } }
93
+ editorProps = { {
94
+ $blockScrolling : true
95
+ } }
96
+ />
97
+ ) : ( < div dangerouslySetInnerHTML = { { __html : responseData } } /> ) }
83
98
</ div >
84
99
) }
85
100
{ responseData && (
86
101
< div className = "mockup-code" >
87
102
< span className = 'pl-5 text-sm text-slate-500' > RESPONSE</ span >
88
- < br />
89
- < span className = 'pl-5 text-sm' > Time taken: < b > { timeTaken } ms</ b > , Status Code: < b > { responseStatus } </ b > , Server memory: < b > { serverMemory } </ b > </ span >
90
- < AceEditor
91
- maxLines = { 50 }
92
- width = '100%'
93
- mode = "json"
94
- wrapEnabled = { true }
95
- readOnly = { true }
96
- value = { responseData }
97
- theme = "one_dark"
98
- onLoad = { function ( editor ) { editor . renderer . setPadding ( 0 ) ; editor . renderer . setScrollMargin ( 5 , 5 , 5 , 5 ) ; editor . renderer . setShowPrintMargin ( false ) ; } }
99
- editorProps = { {
100
- $blockScrolling : true
101
- } }
102
- />
103
- </ div >
104
- ) }
105
- </ >
103
+ < br />
104
+ < span
105
+ className = 'pl-5 text-sm' > Time taken: < b > { timeTaken } ms</ b > , Status Code: < b > { responseStatus } </ b > , Server memory: < b > { serverMemory } </ b > </ span >
106
+ { ! isHtml ? (
107
+ < AceEditor
108
+ maxLines = { 50 }
109
+ width = '100%'
110
+ mode = "json"
111
+ wrapEnabled = { true }
112
+ readOnly = { true }
113
+ value = { responseData }
114
+ theme = "one_dark"
115
+ onLoad = { function ( editor ) {
116
+ editor . renderer . setPadding ( 0 ) ;
117
+ editor . renderer . setScrollMargin ( 5 , 5 , 5 , 5 ) ;
118
+ editor . renderer . setShowPrintMargin ( false ) ;
119
+ } }
120
+ editorProps = { {
121
+ $blockScrolling : true
122
+ } }
123
+ />
124
+ ) : ( < div dangerouslySetInnerHTML = { { __html : responseData } } /> ) }
125
+ </ div >
106
126
)
107
127
}
128
+ </ >
129
+ )
130
+ }
0 commit comments