mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-07 08:34:15 +01:00
Add pretty option to xml request content (#1914)
Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
parent
6c8c87fe28
commit
9ee6f9a8cc
@ -9,6 +9,7 @@ import StyledWrapper from './StyledWrapper';
|
||||
import { updateRequestBody } from 'providers/ReduxStore/slices/collections/index';
|
||||
import { toastError } from 'utils/common/error';
|
||||
import { parse, stringify } from 'lossless-json';
|
||||
import xmlFormat from 'xml-formatter';
|
||||
|
||||
const RequestBodyMode = ({ item, collection }) => {
|
||||
const dispatch = useDispatch();
|
||||
@ -50,6 +51,19 @@ const RequestBodyMode = ({ item, collection }) => {
|
||||
} catch (e) {
|
||||
toastError(new Error('Unable to prettify. Invalid JSON format.'));
|
||||
}
|
||||
} else if (body?.xml && bodyMode === 'xml') {
|
||||
try {
|
||||
const prettyBodyXML = xmlFormat(body.xml, { collapseContent: true });
|
||||
dispatch(
|
||||
updateRequestBody({
|
||||
content: prettyBodyXML,
|
||||
itemUid: item.uid,
|
||||
collectionUid: collection.uid
|
||||
})
|
||||
);
|
||||
} catch (e) {
|
||||
toastError(new Error('Unable to prettify. Invalid XML format.'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -125,7 +139,7 @@ const RequestBodyMode = ({ item, collection }) => {
|
||||
</div>
|
||||
</Dropdown>
|
||||
</div>
|
||||
{bodyMode === 'json' && (
|
||||
{(bodyMode === 'json' || bodyMode === 'xml') && (
|
||||
<button className="ml-1" onClick={onPrettify}>
|
||||
Prettify
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user