XML Indenting with header check

This commit is contained in:
Paul Edwards 2023-04-26 22:06:52 -04:00
parent 45ca5ded96
commit ad905d1a0a
3 changed files with 18 additions and 3 deletions

View File

@ -34,5 +34,8 @@
},
"overrides": {
"rollup": "3.2.5"
},
"dependencies": {
"xml-formatter": "^3.3.2"
}
}
}

View File

@ -1,7 +1,7 @@
import React from 'react';
import find from 'lodash/find';
import classnames from 'classnames';
import { safeStringifyJSON } from 'utils/common';
import { formatResponse } from 'utils/common';
import { useSelector, useDispatch } from 'react-redux';
import { updateResponsePaneTab } from 'providers/ReduxStore/slices/tabs';
import QueryResult from './QueryResult';
@ -16,6 +16,7 @@ import TestResults from './TestResults';
import TestResultsLabel from './TestResultsLabel';
import StyledWrapper from './StyledWrapper';
const ResponsePane = ({ rightPaneWidth, item, collection }) => {
const dispatch = useDispatch();
const tabs = useSelector((state) => state.tabs.tabs);
@ -40,7 +41,7 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => {
item={item}
collection={collection}
width={rightPaneWidth}
value={response.data ? safeStringifyJSON(response.data, true) : ''}
value={response.data ? formatResponse(response): ''}
/>;
}
case 'headers': {

View File

@ -1,4 +1,5 @@
import { customAlphabet } from 'nanoid';
import xmlFormat from 'xml-formatter';
// a customized version of nanoid without using _ and -
export const uuid = () => {
@ -50,6 +51,16 @@ export const safeStringifyJSON = (obj, indent=false) => {
}
}
export const formatResponse = (response) => {
var type = response.headers.find((element) => element[0]=='content-type')[1];
if(type.includes("json")){
return safeStringifyJSON(response.data);
}if(type.includes("xml")){
return xmlFormat(response.data, {collapseContent: true});
}
return response.data;
}
// Remove any characters that are not alphanumeric, spaces, hyphens, or underscores
export const normalizeFileName = (name) => {
if (!name) {