mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-22 13:48:41 +01:00
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 { useTheme } from 'providers/Theme';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
|
import { getContentTypeHeader } from 'utils/common';
|
||||||
|
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
|
|
||||||
@ -18,11 +19,16 @@ const QueryResult = ({ item, collection, value, width, disableRunEventListener }
|
|||||||
}
|
}
|
||||||
dispatch(sendRequest(item, collection.uid));
|
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 (
|
return (
|
||||||
<StyledWrapper className="px-3 w-full" style={{ maxWidth: width }}>
|
<StyledWrapper className="px-3 w-full" style={{ maxWidth: width }}>
|
||||||
<div className="h-full">
|
<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>
|
</div>
|
||||||
</StyledWrapper>
|
</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) => {
|
export const formatResponse = (response) => {
|
||||||
var type = response.headers.find((element) => element[0]=='content-type')[1];
|
var type = getContentTypeHeader(response.headers);
|
||||||
if(type.includes("json")){
|
if(type.includes("json")){
|
||||||
return safeStringifyJSON(response.data);
|
return safeStringifyJSON(response.data);
|
||||||
}if(type.includes("xml")){
|
}if(type.includes("xml")){
|
||||||
|
Loading…
Reference in New Issue
Block a user