Skip to content

Commit 4b74e8d

Browse files
committed
fix : Revert wrong branch's commit
1 parent a641e34 commit 4b74e8d

File tree

1 file changed

+16
-98
lines changed

1 file changed

+16
-98
lines changed

docs-client/src/containers/MethodPage/DebugPage.tsx

Lines changed: 16 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ import { TRANSPORTS } from '../../lib/transports';
5959
import { SelectOption } from '../../lib/types';
6060
import DebugInputs from './DebugInputs';
6161

62-
const stringifyHeaders = (headers: [string, string[]][]): string =>
63-
JSON.stringify(
64-
Object.fromEntries(headers.map(([key, value]) => [key, value.join(', ')])),
65-
null,
66-
2,
67-
);
6862
const useStyles = makeStyles((theme: Theme) =>
6963
createStyles({
7064
actionDialog: {
@@ -155,9 +149,6 @@ const DebugPage: React.FunctionComponent<Props> = ({
155149
const [requestBody, setRequestBody] = useState('');
156150
const [debugResponse, setDebugResponse] = useState('');
157151
const [additionalQueries, setAdditionalQueries] = useState('');
158-
const [debugResponseHeaders, setDebugResponseHeaders] = useState<
159-
[string, string[]][]
160-
>([]);
161152
const [additionalPath, setAdditionalPath] = useState('');
162153
const [additionalHeaders, setAdditionalHeaders] = useState('');
163154
const [stickyHeaders, toggleStickyHeaders] = useReducer(toggle, false);
@@ -168,34 +159,13 @@ const DebugPage: React.FunctionComponent<Props> = ({
168159
false,
169160
);
170161

171-
const [currentApiId, setCurrentApiId] = useState<string>(method.id);
172-
const [responseCache, setResponseCache] = useState<
173-
Record<string, { body: string; headers: Map<string, string[]> }>
174-
>({});
175-
176162
const classes = useStyles();
177163

178164
const transport = TRANSPORTS.getDebugTransport(method);
179165
if (!transport) {
180166
throw new Error("This method doesn't have a debug transport.");
181167
}
182168

183-
useEffect(() => {
184-
const apiId = method.id;
185-
if (apiId !== currentApiId) {
186-
setCurrentApiId(apiId);
187-
if (responseCache[apiId]) {
188-
setDebugResponse(responseCache[apiId].body);
189-
setDebugResponseHeaders(
190-
Array.from(responseCache[apiId].headers.entries()),
191-
);
192-
} else {
193-
setDebugResponse('');
194-
setDebugResponseHeaders([]);
195-
}
196-
}
197-
}, [method, currentApiId, responseCache]);
198-
199169
useEffect(() => {
200170
const urlParams = new URLSearchParams(location.search);
201171

@@ -232,7 +202,6 @@ const DebugPage: React.FunctionComponent<Props> = ({
232202

233203
if (!keepDebugResponse) {
234204
setDebugResponse('');
235-
setDebugResponseHeaders([]);
236205
toggleKeepDebugResponse(false);
237206
}
238207
setSnackbarOpen(false);
@@ -395,7 +364,6 @@ const DebugPage: React.FunctionComponent<Props> = ({
395364

396365
const onClear = useCallback(() => {
397366
setDebugResponse('');
398-
setDebugResponseHeaders([]);
399367
}, []);
400368

401369
const executeRequest = useCallback(
@@ -422,29 +390,24 @@ const DebugPage: React.FunctionComponent<Props> = ({
422390
const headersText = params.get('headers');
423391
const headers = headersText ? JSON.parse(headersText) : {};
424392

393+
let executedDebugResponse;
425394
try {
426-
const { body, headers: responseHeaders } = await transport.send(
395+
executedDebugResponse = await transport.send(
427396
method,
428397
headers,
429398
parseServerRootPath(docServiceRoute),
430399
executedRequestBody,
431400
executedEndpointPath,
432401
queries,
433402
);
434-
setDebugResponse(body);
435-
setDebugResponseHeaders(Array.from(responseHeaders.entries()));
436-
setResponseCache((prev) => ({
437-
...prev,
438-
[currentApiId]: {
439-
body,
440-
headers: responseHeaders,
441-
},
442-
}));
443403
} catch (e) {
444-
const message = e instanceof Object ? e.toString() : '<unknown>';
445-
setDebugResponse(message);
446-
setDebugResponseHeaders([]);
404+
if (e instanceof Object) {
405+
executedDebugResponse = e.toString();
406+
} else {
407+
executedDebugResponse = '<unknown>';
408+
}
447409
}
410+
setDebugResponse(executedDebugResponse);
448411
},
449412
[
450413
useRequestBody,
@@ -453,7 +416,6 @@ const DebugPage: React.FunctionComponent<Props> = ({
453416
method,
454417
transport,
455418
docServiceRoute,
456-
currentApiId,
457419
],
458420
);
459421

@@ -610,7 +572,7 @@ const DebugPage: React.FunctionComponent<Props> = ({
610572
<Grid item xs={12} sm={6}>
611573
<Grid container spacing={1}>
612574
<Grid item xs="auto">
613-
<Tooltip title="Copy response body">
575+
<Tooltip title="Copy response">
614576
<div>
615577
<IconButton
616578
onClick={onCopy}
@@ -634,37 +596,13 @@ const DebugPage: React.FunctionComponent<Props> = ({
634596
</Tooltip>
635597
</Grid>
636598
</Grid>
637-
{debugResponse && (
638-
<>
639-
{Object.keys(debugResponseHeaders).length > 0 && (
640-
<>
641-
<Typography
642-
variant="subtitle1"
643-
style={{ marginTop: '1rem' }}
644-
>
645-
Response Headers:
646-
</Typography>
647-
<SyntaxHighlighter
648-
language="json"
649-
style={githubGist}
650-
wrapLines={false}
651-
>
652-
{stringifyHeaders(debugResponseHeaders)}
653-
</SyntaxHighlighter>
654-
</>
655-
)}
656-
<Typography variant="subtitle1" style={{ marginTop: '1rem' }}>
657-
Response Body:
658-
</Typography>
659-
<SyntaxHighlighter
660-
language="json"
661-
style={githubGist}
662-
wrapLines={false}
663-
>
664-
{debugResponse}
665-
</SyntaxHighlighter>
666-
</>
667-
)}
599+
<SyntaxHighlighter
600+
language="json"
601+
style={githubGist}
602+
wrapLines={false}
603+
>
604+
{debugResponse}
605+
</SyntaxHighlighter>
668606
</Grid>
669607
</Grid>
670608
<Snackbar
@@ -746,26 +684,6 @@ const DebugPage: React.FunctionComponent<Props> = ({
746684
</Tooltip>
747685
</Grid>
748686
</Grid>
749-
{Object.keys(debugResponseHeaders).length > 0 && (
750-
<>
751-
<Typography
752-
variant="subtitle1"
753-
style={{ marginTop: '1rem' }}
754-
>
755-
Response Headers:
756-
</Typography>
757-
<SyntaxHighlighter
758-
language="json"
759-
style={githubGist}
760-
wrapLines={false}
761-
>
762-
{stringifyHeaders(debugResponseHeaders)}
763-
</SyntaxHighlighter>
764-
</>
765-
)}
766-
<Typography variant="subtitle1" style={{ marginTop: '1rem' }}>
767-
Response Body:
768-
</Typography>
769687
<SyntaxHighlighter
770688
language="json"
771689
style={githubGist}

0 commit comments

Comments
 (0)