forked from extern/bruno
Code Editor Mode and formatting
This commit is contained in:
parent
0866d33858
commit
aeb29393c5
@ -3,6 +3,7 @@ import CodeEditor from 'components/CodeEditor';
|
||||
import { useTheme } from 'providers/Theme';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { getContentTypeHeader } from 'utils/common';
|
||||
|
||||
import StyledWrapper from './StyledWrapper';
|
||||
|
||||
@ -18,11 +19,16 @@ const QueryResult = ({ item, collection, value, width, disableRunEventListener }
|
||||
}
|
||||
dispatch(sendRequest(item, collection.uid));
|
||||
};
|
||||
|
||||
var responseType = getContentTypeHeader(item.response.headers);
|
||||
let mode = 'application/json';//TODO: What to default??? json probbaly
|
||||
if(responseType.includes("xml")){
|
||||
mode = "application/xml";
|
||||
}
|
||||
console.log(responseType);
|
||||
return (
|
||||
<StyledWrapper className="px-3 w-full" style={{ maxWidth: width }}>
|
||||
<div className="h-full">
|
||||
<CodeEditor collection={collection} theme={storedTheme} onRun={onRun} value={value || ''} readOnly />
|
||||
<CodeEditor mode={mode} collection={collection} theme={storedTheme} onRun={onRun} value={value || ''} readOnly />
|
||||
</div>
|
||||
</StyledWrapper>
|
||||
);
|
||||
|
@ -51,8 +51,16 @@ export const safeStringifyJSON = (obj, indent=false) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const getContentTypeHeader = (headers) => {
|
||||
let header = headers.find((element) => element[0]=='content-type');
|
||||
if(header && header[1]){
|
||||
return header[1];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export const formatResponse = (response) => {
|
||||
var type = response.headers.find((element) => element[0]=='content-type')[1];
|
||||
var type = getContentTypeHeader(response.headers);
|
||||
if(type.includes("json")){
|
||||
return safeStringifyJSON(response.data);
|
||||
}if(type.includes("xml")){
|
||||
|
Loading…
Reference in New Issue
Block a user