Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(notebooks): clamp wide SQL result cells to one line (#72834)

Sinan Kucukkoseler2effb7b19ef3
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
index c17b90030095..bca9eeeb872b 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
@@ -163,6 +163,9 @@ const Component = ({
page={page}
pageSize={pageSize}
hasMore={hasMorePages}
+ // Wide text columns (long strings, JSON blobs) shouldn't make every
+ // row tall; clamp to one line here and let the user open a cell.
+ truncateCells
paginationDisabledReason={
pageLoading
? 'Fetching page…'
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
index eac19a252b3b..6b57e36db779 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
@@ -239,6 +239,9 @@ const Component = ({
page={page}
pageSize={pageSize}
hasMore={hasMorePages}
+ // Wide text columns (long strings, JSON blobs) shouldn't make every
+ // row tall; clamp to one line here and let the user open a cell.
+ truncateCells
// Serialize page fetches: no new page while one is in flight, a run
// is replacing this result, or another cell's operation is running.
paginationDisabledReason={
diff --git a/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeTable.tsx b/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeTable.tsx
index 850a005ed197..003d35ef2cd8 100644
--- a/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeTable.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/components/NotebookDataframeTable.tsx
@@ -1,4 +1,5 @@
-import { useMemo } from 'react'
+import clsx from 'clsx'
+import { useMemo, useState } from 'react'
import { LemonButton, LemonSelect, LemonTable, Spinner } from '@posthog/lemon-ui'
@@ -16,6 +17,9 @@ type NotebookDataframeTableProps = {
hasMore?: boolean
/** Disables all pagination controls, e.g. while a page fetch is already in flight. */
paginationDisabledReason?: string
+ /** Clamp long cell values to a single line (ellipsis); hover shows the full value, double-click
+ * expands it inline. Keeps a wide text column from blowing up row height. */
+ truncateCells?: boolean
onNextPage: () => void
onPreviousPage: () => void
onPageSizeChange: (pageSize: number) => void
@@ -40,6 +44,26 @@ const formatCellValue = (value: unknown): string => {
}
}
+// A cell that stays on one line (ellipsis) until the user opens it. Hover surfaces the full value
+// as a native tooltip; double-click toggles the full value wrapped inline, so a long string doesn't
+// force the whole row tall by default.
+const TruncatableCell = ({ value }: { value: unknown }): JSX.Element => {
+ const [expanded, setExpanded] = useState(false)
+ const text = formatCellValue(value)
+ return (
+ <span
+ className={clsx(
+ 'font-mono text-xs',
+ expanded ? 'whitespace-pre-wrap break-words select-text' : 'inline-block max-w-xs truncate align-bottom'
+ )}
+ title={!expanded && text ? text : undefined}
+ onDoubleClick={() => setExpanded((prev) => !prev)}
+ >
+ {text}
+ </span>
+ )
+}
+
export const NotebookDataframeTable = ({
result,
loading,
@@ -47,6 +71,7 @@ export const NotebookDataframeTable = ({
pageSize,
hasMore,
paginationDisabledReason,
+ truncateCells,
onNextPage,
onPreviousPage,
onPageSizeChange,
@@ -57,10 +82,15 @@ export const NotebookDataframeTable = ({
title: column,
key: `${column}-${index}`,
dataIndex: column,
- render: (value) => <span className="font-mono text-xs">{formatCellValue(value)}</span>,
+ render: (value) =>
+ truncateCells ? (
+ <TruncatableCell value={value} />
+ ) : (
+ <span className="font-mono text-xs">{formatCellValue(value)}</span>
+ ),
})) ?? []
)
- }, [result?.columns])
+ }, [result?.columns, truncateCells])
const rowsWithIndex = useMemo(() => {
const baseIndex = (page - 1) * pageSize