Add pretty option to xml request content (#1914)

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
tlaloc911 2024-04-09 15:16:45 -06:00 committed by GitHub
parent 6c8c87fe28
commit 9ee6f9a8cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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>