From 2c278cdcf09af204d3a8e586606f7f796bfadb76 Mon Sep 17 00:00:00 2001 From: Rawa Hamid Date: Mon, 5 Aug 2024 10:39:05 +0300 Subject: [PATCH] Check response type if html to show html example of using dd() function --- ui/src/components/ApiAction.tsx | 10 +- .../components/elements/ApiActionResponse.tsx | 99 ++++++++++++------- 2 files changed, 67 insertions(+), 42 deletions(-) diff --git a/ui/src/components/ApiAction.tsx b/ui/src/components/ApiAction.tsx index 75915bd..fa2de7b 100644 --- a/ui/src/components/ApiAction.tsx +++ b/ui/src/components/ApiAction.tsx @@ -1,8 +1,10 @@ -import React, { useEffect, useState } from 'react'; +// noinspection t + +import React, {useEffect, useState} from 'react'; import useLocalStorage from 'react-use-localstorage'; -import {makeCurlCommand } from '../libs/strings' -import type {IAPIInfo, LRDResponse, IConfig} from '../libs/types' +import {makeCurlCommand} from '../libs/strings' +import type {IAPIInfo, IConfig, LRDResponse} from '../libs/types' import ApiActionResponse from './elements/ApiActionResponse' import ApiActionRequest from './elements/ApiActionRequest' import ApiActionTabs from './elements/ApiActionTabs' @@ -10,7 +12,7 @@ import ApiActionInfo from './elements/ApiActionInfo' import ApiActionSQL from './elements/ApiActionSQL' import ApiActionLog from './elements/ApiActionLog' import ApiActionEvents from './elements/ApiActionEvents' -import { objectToFormData } from '../libs/object'; +import {objectToFormData} from '../libs/object'; interface Props { lrdDocsItem: IAPIInfo, diff --git a/ui/src/components/elements/ApiActionResponse.tsx b/ui/src/components/elements/ApiActionResponse.tsx index 3bad8fd..01b6a80 100644 --- a/ui/src/components/elements/ApiActionResponse.tsx +++ b/ui/src/components/elements/ApiActionResponse.tsx @@ -1,15 +1,15 @@ -import React, { useEffect } from 'react'; +// noinspection t + +import React, {useEffect, useState} from 'react'; import "ace-builds"; import jsonWorkerUrl from 'ace-builds/src-min-noconflict/worker-json?url'; - -ace.config.setModuleUrl('ace/mode/json_worker', jsonWorkerUrl); - import AceEditor from 'react-ace'; import "ace-builds/src-noconflict/mode-json"; import "ace-builds/src-noconflict/theme-one_dark"; import "ace-builds/src-noconflict/ext-language_tools"; import useLocalStorage from 'react-use-localstorage'; +ace.config.setModuleUrl('ace/mode/json_worker', jsonWorkerUrl); interface Props { responseData: string, @@ -25,7 +25,12 @@ export default function ApiActionResponse(props: Props) { const { responseHeaders, responseData, timeTaken, responseStatus, serverMemory, requestUri, method } = props const [savePreviousResponse] = useLocalStorage('savePreviousResponse', 'false'); const [previousResponse, setPreviousResponse] = useLocalStorage('previousResponse' + requestUri + method, ''); + const [isHtml, setIsHtml] = useState(false); useEffect(() => { + if (JSON.parse(responseHeaders)['content-type'].split(';')[0] === 'text/html') { + setIsHtml(true) + } + if (responseData && savePreviousResponse === 'true') { setPreviousResponse(responseData) } @@ -36,7 +41,7 @@ export default function ApiActionResponse(props: Props) { {responseHeaders && ( <>
- +
Show Response Headers
@@ -49,14 +54,18 @@ export default function ApiActionResponse(props: Props) { wrapEnabled={true} value={responseHeaders} theme="one_dark" - onLoad={function (editor) { editor.renderer.setPadding(0); editor.renderer.setScrollMargin(5, 5, 5, 5); editor.renderer.setShowPrintMargin(false); }} + onLoad={function (editor) { + editor.renderer.setPadding(0); + editor.renderer.setScrollMargin(5, 5, 5, 5); + editor.renderer.setShowPrintMargin(false); + }} editorProps={{ $blockScrolling: true }} />
-
+
)} {(!responseData && !previousResponse) && ( @@ -67,41 +76,55 @@ export default function ApiActionResponse(props: Props) { {(!responseData && previousResponse) && (
Previous Response - + {! isHtml ? ( + + ) : (
)}
)} {responseData && (
RESPONSE -
- Time taken: {timeTaken}ms, Status Code: {responseStatus}, Server memory: {serverMemory} - -
- )} - +
+ Time taken: {timeTaken}ms, Status Code: {responseStatus}, Server memory: {serverMemory} + {! isHtml ? ( + + ) : (
)} +
) } + +) +}