@@ -2,7 +2,7 @@ import React from 'react';
2
2
import find from 'lodash/find' ;
3
3
import classnames from 'classnames' ;
4
4
import { safeStringifyJSON } from 'utils/common' ;
5
- import { useSelector , useDispatch } from 'react-redux' ;
5
+ import { useDispatch , useSelector } from 'react-redux' ;
6
6
import { updateResponsePaneTab } from 'providers/ReduxStore/slices/tabs' ;
7
7
import QueryResult from './QueryResult' ;
8
8
import Overlay from './Overlay' ;
@@ -36,18 +36,21 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => {
36
36
const getTabPanel = ( tab ) => {
37
37
switch ( tab ) {
38
38
case 'response' : {
39
- return < QueryResult
40
- item = { item }
41
- collection = { collection }
42
- width = { rightPaneWidth }
43
- value = { response . data ? safeStringifyJSON ( response . data , true ) : '' }
44
- /> ;
39
+ return (
40
+ < QueryResult
41
+ item = { item }
42
+ collection = { collection }
43
+ width = { rightPaneWidth }
44
+ value = { response . data ? ( isJson ( response . headers ) ? safeStringifyJSON ( response . data , true ) : response . data ) : '' }
45
+ mode = { getContentType ( response . headers ) }
46
+ />
47
+ ) ;
45
48
}
46
49
case 'headers' : {
47
50
return < ResponseHeaders headers = { response . headers } /> ;
48
51
}
49
52
case 'timeline' : {
50
- return < Timeline request = { item . requestSent } response = { item . response } /> ;
53
+ return < Timeline request = { item . requestSent } response = { item . response } /> ;
51
54
}
52
55
case 'tests' : {
53
56
return < TestResults results = { item . testResults } assertionResults = { item . assertionResults } /> ;
@@ -81,7 +84,7 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => {
81
84
82
85
const focusedTab = find ( tabs , ( t ) => t . uid === activeTabUid ) ;
83
86
if ( ! focusedTab || ! focusedTab . uid || ! focusedTab . responsePaneTab ) {
84
- return < div className = "pb-4 px-4" > An error occured !</ div > ;
87
+ return < div className = "pb-4 px-4" > An error occurred !</ div > ;
85
88
}
86
89
87
90
const getTabClassname = ( tabName ) => {
@@ -90,6 +93,28 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => {
90
93
} ) ;
91
94
} ;
92
95
96
+ const getContentType = ( headers ) => {
97
+ if ( headers && headers . length ) {
98
+ let contentType = headers
99
+ . filter ( ( header ) => header [ 0 ] . toLowerCase ( ) === 'content-type' )
100
+ . map ( ( header ) => {
101
+ return header [ 1 ] ;
102
+ } ) ;
103
+ if ( contentType && contentType . length ) {
104
+ if ( typeof contentType [ 0 ] == 'string' && / ^ [ \w \- ] + \/ ( [ \w \- ] + \+ ) ? j s o n / . test ( contentType [ 0 ] ) ) {
105
+ return 'application/ld+json' ;
106
+ } else if ( typeof contentType [ 0 ] == 'string' && / ^ [ \w \- ] + \/ ( [ \w \- ] + \+ ) ? x m l / . test ( contentType [ 0 ] ) ) {
107
+ return 'application/xml' ;
108
+ }
109
+ }
110
+ }
111
+ return '' ;
112
+ } ;
113
+
114
+ const isJson = ( headers ) => {
115
+ return getContentType ( headers ) === 'application/ld+json' ;
116
+ } ;
117
+
93
118
return (
94
119
< StyledWrapper className = "flex flex-col h-full relative" >
95
120
< div className = "flex items-center px-3 tabs" role = "tablist" >
0 commit comments