Skip to content

Commit

Permalink
isTooDeep
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Nov 30, 2021
1 parent 6ec0f23 commit e3812d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ example/demo-bundle.*
example/reference-bundle.*

packages/**/dist
.vscode
6 changes: 5 additions & 1 deletion packages/api-explorer/src/components/Response/Result.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const FileSvg = (
</svg>
)

const objectDepth = (o) => Object (o) === o ? 1 + Math.max (-1, ... Object.values(o).map(objectDepth)) : 0

export default function Result({result, isCollapse}) {
const isJson =
result.type && contentTypeIsJson(result.type) && typeof result.responseBody === 'object';

const isTooDeep = isJson && objectDepth(result.responseBody) > 10

return (
<div>
{result.isBinary && (
Expand All @@ -46,7 +50,7 @@ export default function Result({result, isCollapse}) {
{!result.isBinary && isJson && (
<ReactJson
src={result.responseBody}
collapsed={isCollapse ? 1 : false}
collapsed={isCollapse || isTooDeep ? 1 : false}
collapseStringsAfterLength={100}
enableClipboard={false}
theme="tomorrow"
Expand Down

0 comments on commit e3812d6

Please sign in to comment.