Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 137 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/oc-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.1",
"@faker-js/faker": "^9.7.0",
"@microlink/react-json-view": "^1.31.22",
"@mintlify/httpsnippet": "^1.0.10",
"@monaco-editor/react": "^4.7.0",
"@opencollection/types": "0.11.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import React from 'react';
import CodeEditor from '../../../../../ui/CodeEditor/CodeEditor';
import { ResponseBodyFormat } from '../../../../../utils/response';
import { RunRequestResponse } from '../../../../../runner';
import { QueryResultPreview } from '../../../QueryResult/QueryResult';
import { formatToPreviewMode } from '../../../QueryResult/QueryResultPreview/previewMode';

interface ResponseBodyTabProps {
response: any;
response: RunRequestResponse;
selectedFormat: ResponseBodyFormat;
showPreview: boolean;
}

const ResponseBodyTab: React.FC<ResponseBodyTabProps> = ({ response }) => {
const formatJson = (data: any) => {
try {
return JSON.stringify(data, null, 2);
} catch {
return String(data);
}
};
const ResponseBodyTab: React.FC<ResponseBodyTabProps> = ({ response, selectedFormat, showPreview }) => {
// The runner parses JSON responses into objects; the editor needs a string.
const editorValue =
response?.data == null
? ''
: typeof response.data === 'string'
? response.data
: JSON.stringify(response.data, null, 2);

const responseText = typeof response.data === 'string' ? response.data : formatJson(response.data);
const contentType = response.headers?.['content-type'] || response.headers?.['Content-Type'] || '';
let language = 'text';

if (contentType.includes('application/json') || contentType.includes('text/json')) {
language = 'json';
} else if (contentType.includes('text/html')) {
language = 'html';
} else if (contentType.includes('text/xml') || contentType.includes('application/xml')) {
language = 'xml';
} else if (contentType.includes('text/css')) {
language = 'css';
} else if (contentType.includes('text/javascript') || contentType.includes('application/javascript')) {
language = 'javascript';
}

// The tab-panel is height-constrained; own the scroll here so a tall body
// (e.g. a large JSON tree) scrolls within the response area instead of
// overflowing and being clipped.
return (
<div className="h-full py-4">
<CodeEditor
value={responseText}
onChange={() => {}} // Read-only
language={language}
height="100%"
readOnly={true}
/>
<div className="h-full overflow-auto">
{showPreview ? (
<QueryResultPreview
data={response?.data}
previewMode={formatToPreviewMode(selectedFormat)}
baseUrl={response?.url}
/>
) : (
<CodeEditor
value={editorValue}
onChange={() => {}} // Read-only
language={selectedFormat}
height="100%"
readOnly={true}
/>
)}
</div>
);
};

export default ResponseBodyTab;

Loading
Loading