From ad905d1a0a893a63c7d23dd7da9462ff6a915571 Mon Sep 17 00:00:00 2001 From: Paul Edwards Date: Wed, 26 Apr 2023 22:06:52 -0400 Subject: [PATCH 1/2] XML Indenting with header check --- package.json | 5 ++++- .../bruno-app/src/components/ResponsePane/index.js | 5 +++-- packages/bruno-app/src/utils/common/index.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8e2c2715..bc1b16f9 100644 --- a/package.json +++ b/package.json @@ -34,5 +34,8 @@ }, "overrides": { "rollup": "3.2.5" + }, + "dependencies": { + "xml-formatter": "^3.3.2" } -} \ No newline at end of file +} diff --git a/packages/bruno-app/src/components/ResponsePane/index.js b/packages/bruno-app/src/components/ResponsePane/index.js index 1648c708..8847ef6b 100644 --- a/packages/bruno-app/src/components/ResponsePane/index.js +++ b/packages/bruno-app/src/components/ResponsePane/index.js @@ -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': { diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js index f5b3b2df..f11c972d 100644 --- a/packages/bruno-app/src/utils/common/index.js +++ b/packages/bruno-app/src/utils/common/index.js @@ -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) { From aeb29393c55f4edd14bb9669435a622894816dee Mon Sep 17 00:00:00 2001 From: Paul Edwards Date: Wed, 19 Jul 2023 20:06:37 -0400 Subject: [PATCH 2/2] Code Editor Mode and formatting --- .../src/components/ResponsePane/QueryResult/index.js | 10 ++++++++-- packages/bruno-app/src/utils/common/index.js | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index 1dd05c8c..a9974c7c 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -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 (
- +
); diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js index f11c972d..ef8f151b 100644 --- a/packages/bruno-app/src/utils/common/index.js +++ b/packages/bruno-app/src/utils/common/index.js @@ -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")){