Skip to content

Commit dd3c6ea

Browse files
committed
Unpretty JSON columns display properly
They were showing as [Object Object] before.
1 parent 839d5e8 commit dd3c6ea

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

apps/webapp/app/components/code/TSQLResultsTable.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ function CellValue({
134134
}) {
135135
// Plain text mode - render everything as monospace text with truncation
136136
if (!prettyFormatting) {
137+
if (column.type === "JSON") {
138+
return <JSONCellValue value={value} />;
139+
}
140+
137141
const plainValue = value === null ? "NULL" : String(value);
138142
const isTruncated = plainValue.length > MAX_STRING_DISPLAY_LENGTH;
139143

@@ -277,24 +281,7 @@ function CellValue({
277281

278282
// JSON type
279283
if (type === "JSON") {
280-
const jsonString = JSON.stringify(value);
281-
const isTruncated = jsonString.length > MAX_STRING_DISPLAY_LENGTH;
282-
283-
if (isTruncated) {
284-
return (
285-
<SimpleTooltip
286-
content={
287-
<pre className="max-w-sm whitespace-pre-wrap break-all font-mono text-xs">
288-
{jsonString}
289-
</pre>
290-
}
291-
button={
292-
<span className="font-mono text-xs text-text-dimmed">{truncateString(jsonString)}</span>
293-
}
294-
/>
295-
);
296-
}
297-
return <span className="font-mono text-xs text-text-dimmed">{jsonString}</span>;
284+
return <JSONCellValue value={value} />;
298285
}
299286

300287
// Array types
@@ -382,6 +369,28 @@ function EnvironmentCellValue({ value }: { value: string }) {
382369
return <EnvironmentLabel environment={environment} />;
383370
}
384371

372+
function JSONCellValue({ value }: { value: any }) {
373+
const jsonString = JSON.stringify(value);
374+
const isTruncated = jsonString.length > MAX_STRING_DISPLAY_LENGTH;
375+
376+
if (isTruncated) {
377+
return (
378+
<SimpleTooltip
379+
content={
380+
<pre className="max-w-sm whitespace-pre-wrap break-all font-mono text-xs">
381+
{jsonString}
382+
</pre>
383+
}
384+
button={
385+
<span className="font-mono text-xs text-text-dimmed">{truncateString(jsonString)}</span>
386+
}
387+
/>
388+
);
389+
}
390+
391+
return <span className="font-mono text-xs text-text-dimmed">{jsonString}</span>;
392+
}
393+
385394
/**
386395
* Check if a column should be right-aligned (numeric columns, duration, cost)
387396
*/

0 commit comments

Comments
 (0)