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): separate cell output with a gray header row (#82666)

Sinan Kucukkoselerc22d82642f38
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
index b77bfdc5febd..f3d1c61dc205 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
@@ -8,6 +8,7 @@ import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper'
import type { NotebookNodeRunTerminalStatus } from 'scenes/notebooks/Notebook/notebookNodeStalenessLogic'
import { NotebookNodeAttributeProperties, NotebookNodeProps, NotebookNodeType } from '../types'
+import { NotebookCellOutputHeader } from './components/NotebookCellOutputHeader'
import { NotebookDataframeTable } from './components/NotebookDataframeTable'
import { NotebookRunDownstreamBanner } from './components/NotebookRunDownstreamBanner'
import { NotebookStaleCellBanner } from './components/NotebookStaleCellBanner'
@@ -95,6 +96,9 @@ const Component = ({
: (result?.has_more ?? (result?.first_page ?? []).length >= SQL_V2_DEFAULT_PAGE_SIZE)
const hasStreamOutput = !!(result?.stdout || result?.stderr || result?.media?.length)
+ // Only results get the strip. A run that failed shows a traceback, which "Results" mislabels,
+ // and a cell that never ran keeps the plain hint.
+ const hasOutput = hasStreamOutput || !!dataframeResult
// Grow a still-too-short node to fit the output each run lands, so it's readable without a
// manual resize. Sized to what came back — a printed value stays compact, a table or figure
@@ -129,16 +133,16 @@ const Component = ({
return (
<div data-attr="notebook-node-python-v2" className="flex h-full min-h-0 flex-col">
<div
- className="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto"
+ className="flex min-h-0 flex-1 flex-col overflow-y-auto"
onMouseDown={(event) => event.stopPropagation()}
onDragStart={(event) => event.stopPropagation()}
>
{isStale ? (
- <div className="shrink-0" onClick={(event) => event.stopPropagation()}>
+ <div className="shrink-0 pb-2" onClick={(event) => event.stopPropagation()}>
<NotebookStaleCellBanner />
</div>
) : staleDownstreamCount > 0 && !isChainRunning ? (
- <div className="shrink-0" onClick={(event) => event.stopPropagation()}>
+ <div className="shrink-0 pb-2" onClick={(event) => event.stopPropagation()}>
<NotebookRunDownstreamBanner
count={staleDownstreamCount}
onRun={() => runStaleChain(notebookLogic.values.content ?? null, nodeId)}
@@ -147,10 +151,11 @@ const Component = ({
</div>
) : null}
{isRunning && pendingKernelStart ? (
- <div className="shrink-0 px-2 pt-1 text-xs text-muted">Starting compute sandbox…</div>
+ <div className="shrink-0 px-2 pt-1 pb-2 text-xs text-muted">Starting compute sandbox…</div>
) : null}
+ {hasOutput ? <NotebookCellOutputHeader>Results</NotebookCellOutputHeader> : null}
{hasStreamOutput ? (
- <div className="shrink-0 space-y-2 px-2 pt-1" onClick={(event) => event.stopPropagation()}>
+ <div className="shrink-0 space-y-2 px-2 py-2" onClick={(event) => event.stopPropagation()}>
{result?.stdout ? (
<pre className="text-xs font-mono whitespace-pre-wrap select-text m-0">{result.stdout}</pre>
) : null}
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
index 1cfaaa561331..1d833649b59d 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeSQLV2.tsx
@@ -13,6 +13,7 @@ import { DataVisualizationNode, HogQLQueryResponse, NodeKind } from '~/queries/s
import { ChartDisplayType } from '~/types'
import { NotebookNodeAttributeProperties, NotebookNodeProps, NotebookNodeType } from '../types'
+import { NotebookCellOutputHeader } from './components/NotebookCellOutputHeader'
import { NotebookDataframeTable } from './components/NotebookDataframeTable'
import { getCellLabel } from './components/NotebookNodeTitle'
import { NotebookRunDownstreamBanner } from './components/NotebookRunDownstreamBanner'
@@ -238,16 +239,16 @@ const Component = ({
return (
<div data-attr="notebook-node-sql-v2" className="flex h-full min-h-0 flex-col">
<div
- className="flex min-h-0 flex-1 flex-col gap-2"
+ className="flex min-h-0 flex-1 flex-col"
onMouseDown={(event) => event.stopPropagation()}
onDragStart={(event) => event.stopPropagation()}
>
{isStale ? (
- <div className="shrink-0" onClick={(event) => event.stopPropagation()}>
+ <div className="shrink-0 pb-2" onClick={(event) => event.stopPropagation()}>
<NotebookStaleCellBanner />
</div>
) : staleDownstreamCount > 0 && !isChainRunning ? (
- <div className="shrink-0" onClick={(event) => event.stopPropagation()}>
+ <div className="shrink-0 pb-2" onClick={(event) => event.stopPropagation()}>
<NotebookRunDownstreamBanner
count={staleDownstreamCount}
onRun={() => runStaleChain(notebookLogic.values.content ?? null, nodeId)}
@@ -256,13 +257,13 @@ const Component = ({
</div>
) : null}
{isRunning && pendingKernelStart ? (
- <div className="shrink-0 px-2 pt-1 text-xs text-muted">Starting compute sandbox…</div>
+ <div className="shrink-0 px-2 pt-1 pb-2 text-xs text-muted">Starting compute sandbox…</div>
) : null}
{runError ? (
<div className="p-2 text-xs font-mono text-danger whitespace-pre-wrap">{runError}</div>
) : dataframeResult && cachedResults ? (
<>
- <div className="shrink-0 px-2 pt-1" onClick={(event) => event.stopPropagation()}>
+ <NotebookCellOutputHeader>
<LemonTabs
size="small"
activeKey={activeTab}
@@ -275,13 +276,15 @@ const Component = ({
: attributes.height
updateAttributes({ outputTab: tab, height })
}}
- barClassName="mb-0"
+ // The strip already carries the bottom border, and the bar draws
+ // its own as a ::before, so two 1px lines stack without this.
+ barClassName="mb-0 before:hidden"
tabs={[
{ key: OutputTab.Results, label: 'Results' },
{ key: OutputTab.Visualization, label: 'Visualization' },
]}
/>
- </div>
+ </NotebookCellOutputHeader>
{activeTab === OutputTab.Results ? (
<div className="min-h-0 flex-1 overflow-y-auto">
<NotebookDataframeTable
@@ -309,7 +312,7 @@ const Component = ({
</div>
) : (
<div
- className="px-2 pb-2 flex min-h-0 flex-1 flex-col overflow-hidden"
+ className="px-2 py-2 flex min-h-0 flex-1 flex-col overflow-hidden"
onClick={(event) => event.stopPropagation()}
>
<Query
diff --git a/frontend/src/scenes/notebooks/Nodes/components/NotebookCellOutputHeader.tsx b/frontend/src/scenes/notebooks/Nodes/components/NotebookCellOutputHeader.tsx
new file mode 100644
index 000000000000..5b74ab2d0881
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Nodes/components/NotebookCellOutputHeader.tsx
@@ -0,0 +1,23 @@
+import { ReactNode } from 'react'
+
+// Marks where a V2 cell's code stops and its output starts. A bare divider does not read as that
+// boundary, because the node's title and its settings block already end on the same 1px line. The
+// tint is what separates the two. `min-h-9` is a small LemonTabs bar plus this strip's padding, so
+// the SQL cell's tabs and the Python cell's shorter label sit on strips of the same height.
+
+type NotebookCellOutputHeaderProps = {
+ /** Names the output below. Python cells pass a label, SQL cells pass their result tabs. */
+ children: ReactNode
+}
+
+export function NotebookCellOutputHeader({ children }: NotebookCellOutputHeaderProps): JSX.Element {
+ return (
+ <div
+ className="flex min-h-9 shrink-0 items-center gap-2 border-b border-primary bg-fill-highlight-50 px-2 py-1 text-xs text-muted"
+ // Switching tabs is a click on node chrome, which otherwise expands or drags the node.
+ onClick={(event) => event.stopPropagation()}
+ >
+ {children}
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/notebooks/Nodes/notebookNodeOutputHeight.ts b/frontend/src/scenes/notebooks/Nodes/notebookNodeOutputHeight.ts
index 90a183b8916a..8c273902d6e2 100644
--- a/frontend/src/scenes/notebooks/Nodes/notebookNodeOutputHeight.ts
+++ b/frontend/src/scenes/notebooks/Nodes/notebookNodeOutputHeight.ts
@@ -2,8 +2,8 @@
// couple of table rows, but a scalar result doesn't need a tall cell either — so size to what
// actually came back and cap it, instead of snapping every result to one large default.
-/** Tab bar, dataframe-name footer, and the padding around the output area. */
-const NODE_CHROME_HEIGHT = 80
+/** Output header row, dataframe-name footer, and the padding around the output area. */
+const NODE_CHROME_HEIGHT = 88
/** Table header plus the pagination bar under it. */
const TABLE_CHROME_HEIGHT = 68
const ROW_HEIGHT = 28