Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON for table values only for objects #2168

Merged
merged 1 commit into from
Feb 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('<KeyValuesTable>', () => {
{ key: 'omg', value: 'mos-def', expected: 'mos-def' },
{ key: 'numericString', value: '12345678901234567890', expected: '12345678901234567890' },
{ key: 'numeric', value: 123456789, expected: '123456789' },
{ key: 'boolean', value: true, expected: 'true' },
{ key: 'http.request.header.accept', value: ['application/json'], expected: 'application/json' },
{
key: 'http.response.header.set_cookie',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,27 @@ const stringListMarkup = (value: any[]) => (
</div>
);

const stringMarkup = (value: string) => (
<div className="json-markup">
<span className="json-markup-string">{value}</span>
</div>
);
const scalarMarkup = (value: string | Number | Boolean) => {
let className;
switch (typeof value) {
case 'boolean': {
className = 'json-markup-bool';
break;
}
case 'number': {
className = 'json-markup-number';
break;
}
default: {
className = 'json-markup-string';
}
}
return (
<div className="json-markup">
<span className={className}>{value.toString()}</span>
</div>
);
};

function formatValue(key: string, value: any) {
let content;
Expand All @@ -66,11 +82,9 @@ function formatValue(key: string, value: any) {
parsed = tryParseJson(value);
}

if (typeof parsed === 'string') {
content = stringMarkup(parsed);
} else if (Array.isArray(parsed) && shouldDisplayAsStringList(key)) {
if (Array.isArray(parsed) && shouldDisplayAsStringList(key)) {
content = stringListMarkup(parsed);
} else {
} else if (typeof parsed === 'object') {
const shouldJsonTreeExpand = Object.keys(parsed).length <= 10;

content = (
Expand All @@ -95,6 +109,8 @@ function formatValue(key: string, value: any) {
}}
/>
);
} else {
content = scalarMarkup(parsed);
}
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

return <div className="ub-inline-block">{content}</div>;
Expand Down