: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(notebooks): make the variables bar as wide as the notebook (#91003)
Sinan Kucukkoseler60ecb9657674
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 903951647e80..fce9e512a921 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -1308,6 +1308,10 @@ snapshots:hash: v1.k794b7964.b933911885203330331bde8bd799fd74fcd4e5964ba7fba4538dd075f07e32dc.QhPFXSfVCoIMya1xKmHLdyh3P9dJf-zNL4_zLUNqgqUcomponents-markdown-editor-rich--with-markdown--light:hash: v1.k794b7964.98bef7667e05e7a86864149a5db5c24b3d4733bcef7d413ab6faf3053c79fba8.evR63xGwLPTzXw6Hi35ROggl2AHmH_y5lT5p05kFGTg+ components-markdown-notebook--canvas-header--dark:+ hash: v1.k794b7964.608a0ac08314f9ca439ce83d605b5b7068699aefcdc3ec64d2ea9850b78383a5.6uhW10xIiflrvLM9jcnT-l6on-ERqLyloX1KosD6EnA+ components-markdown-notebook--canvas-header--light:+ hash: v1.k794b7964.16b2968666f9d437cd7a6563d7e5c729a63c312b6d45e19763676adb10be5d50.XdkGvKh9l6Osw19D13Y_VwwD_dhRQl9TUIS257ov4CYcomponents-markdown-notebook--component-catalog--dark:hash: v1.k794b7964.8d4bc1ec68c46621e7f0fa8d9ab9c83fc4a5c214fbba1dec162e9bb086643758.kBJyYgTMXU0MN-WCD6K4BcTw4Dne_Y5LCut3zY83OuUcomponents-markdown-notebook--component-catalog--light:diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scssindex c48009c4781a..4ab1d893468a 100644--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss@@ -275,6 +275,16 @@margin: 0 auto;}+// Takes the canvas's own column, then steps in by the offset the blocks leave for their hover+// controls, so anything pinned above the canvas lines up with the blocks below it at any width.+.MarkdownNotebook__canvas-header {+ width: 100%;+ max-width: var(--markdown-notebook-canvas-max-width);+ padding-right: var(--markdown-notebook-gutter-reserve);+ padding-left: calc(var(--markdown-notebook-gutter-reserve) + var(--markdown-notebook-content-offset));+ margin: 0 auto;+}+.MarkdownNotebook--edit .MarkdownNotebook__canvas {padding-bottom: 18rem;}@@ -2112,7 +2122,8 @@ button.MarkdownNotebook__component-title:focus-visible {/* With comment threads present and enough room, the canvas reserves a right gutter wideenough for the whole thread column, pushing the text content left. */-.MarkdownNotebook--comments-margin .MarkdownNotebook__canvas {+.MarkdownNotebook--comments-margin .MarkdownNotebook__canvas,+.MarkdownNotebook--comments-margin .MarkdownNotebook__canvas-header {max-width: calc(var(--markdown-notebook-canvas-max-width) + var(--markdown-notebook-comment-gutter) +var(--markdown-notebook-gutter-reserve)diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsx b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsxindex c159981e332b..f7e9faad378f 100644--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsx+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsx@@ -187,6 +187,17 @@ export const TextOnlyNotebook: Story = {},}+export const CanvasHeader: Story = {+ args: {+ value: textNotebook,+ canvasHeader: (+ <div className="mb-2 w-full rounded border border-primary bg-surface-secondary p-2">+ A panel in the canvas header takes the same left and right edges as the blocks below it.+ </div>+ ),+ },+}+export const HeadingsAndInlineFormatting: Story = {args: {value: `# Heading 1diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsxindex 53e9bded137c..b9985532181d 100644--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx@@ -280,6 +280,10 @@ export type MarkdownNotebookProps = {* resolve against the viewer's project rather than the author's. */hideResourceLinks?: booleanplaceholder?: string+ /** Content pinned above the canvas, laid out on the canvas's own column so it lines up with+ * the blocks below it at any width. For a caller whose panel belongs to the notebook rather+ * than to the document, e.g. its variables. */+ canvasHeader?: ReactNodeclassName?: stringautoFocus?: booleanshowDebug?: boolean@@ -602,6 +606,7 @@ function MarkdownNotebookEditor({allowViewModeFilters = false,hideResourceLinks = false,placeholder = 'Start writing...',+ canvasHeader,className,autoFocus = false,showDebug = false,@@ -6016,6 +6021,7 @@ function MarkdownNotebookEditor({))}</div>) : null}+ {canvasHeader ? <div className="MarkdownNotebook__canvas-header">{canvasHeader}</div> : null}<divclassName="MarkdownNotebook__canvas"ref={canvasRef}diff --git a/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2Renderer.tsx b/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2Renderer.tsxindex 91d0b2dd7c10..d402cf1a45fb 100644--- a/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2Renderer.tsx+++ b/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2Renderer.tsx@@ -69,6 +69,7 @@ import {NOTEBOOK_AI_PRESENCE_NAME,} from './notebookPresence'import { notebookSettingsLogic } from './notebookSettingsLogic'+import { NotebookVariablesBar } from './NotebookVariablesBar'const NOTEBOOK_AI_FOLLOW_UP_PROMPT_MARKDOWN = '<Prompt question="" />'const NOTEBOOK_AI_PRESENCE_DEPARTURE_IDLE_MS = 5_000@@ -710,6 +711,7 @@ export function MarkdownNotebookV2({ debugOpen, onDebugOpenChange }: MarkdownNotdeferRemoteValue={markdownEditorInteractionActive}onInteractionStateChange={setMarkdownEditorInteractionActive}allowViewModeFilters={mountedNotebookLogic.props.mode === 'canvas'}+ canvasHeader={<NotebookVariablesBar />}className="Notebook__markdown-v2"data-attr="notebook-markdown-v2"autoFocus={isEditable}diff --git a/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsx b/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsxindex c3fbe174b344..f643814cd9af 100644--- a/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsx+++ b/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsx@@ -130,6 +130,21 @@ describe('MarkdownNotebookV2Renderer UI', () => {expect(notebookElement?.classList.contains('Notebook--expanded')).toBe(false)})+ it('puts the variables bar in the notebook column, above the blocks', () => {+ // The bar takes its width from the column it sits in. Rendered anywhere else it either+ // disappears from the notebook or stops lining up with the blocks below it.+ act(() => {+ settingsLogic.actions.setShowVariables(true)+ })++ const { container } = render(<Notebook shortId={SHORT_ID} mode="notebook" cachedNotebook={cachedNotebook} />)+ const header = container.querySelector('.MarkdownNotebook__canvas-header')+ const canvas = container.querySelector('.MarkdownNotebook__canvas')++ expect(header?.querySelector('.NotebookVariables')).toBeInstanceOf(HTMLElement)+ expect(header?.compareDocumentPosition(canvas as Node)).toBe(Node.DOCUMENT_POSITION_FOLLOWING)+ })+it('collapses markdown content width', () => {const { container } = render(<NotebookExpandButton type="secondary" size="small" inPanel={false} />)const button = container.querySelector('button')diff --git a/frontend/src/scenes/notebooks/Notebook/Notebook.scss b/frontend/src/scenes/notebooks/Notebook/Notebook.scssindex 2445e59c9589..17f8ef73be5c 100644--- a/frontend/src/scenes/notebooks/Notebook/Notebook.scss+++ b/frontend/src/scenes/notebooks/Notebook/Notebook.scss@@ -719,7 +719,8 @@ body[theme='dark'].has-markdown-v2-notebook .main-content-container > main {.Notebook__markdown-v2,.MarkdownNotebook__debug-layout,.MarkdownNotebook__main,- .MarkdownNotebook__canvas {+ .MarkdownNotebook__canvas,+ .MarkdownNotebook__canvas-header {width: 100%;max-width: none;}diff --git a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx b/frontend/src/scenes/notebooks/Notebook/Notebook.tsxindex 0754be4af4f5..1e929d1b111c 100644--- a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx+++ b/frontend/src/scenes/notebooks/Notebook/Notebook.tsx@@ -21,7 +21,6 @@ import { NotebookHistoryWarning } from './NotebookHistory'import { NotebookLoadingState } from './NotebookLoadingState'import { NotebookMergeConflictDetails } from './NotebookMergeConflictDetails'import { notebookSettingsLogic } from './notebookSettingsLogic'-import { NotebookVariablesBar } from './NotebookVariablesBar'// Counts mounted notebooks so the <body> marker class survives overlapping mounts// (e.g. one in the scene and one in the side panel)@@ -146,8 +145,6 @@ export function Notebook({</LemonBanner>) : null}- <NotebookVariablesBar />-<div className="Notebook_content"><NotebookColumnLeft /><ErrorBoundary>diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookVariablesBar.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookVariablesBar.tsxindex 307662357934..7a90cb982399 100644--- a/frontend/src/scenes/notebooks/Notebook/NotebookVariablesBar.tsx+++ b/frontend/src/scenes/notebooks/Notebook/NotebookVariablesBar.tsx@@ -94,7 +94,7 @@ function NotebookVariableValueInput({/*** The notebook's variables, one row each: name, type, value, delete. A property of the notebook- * rather than a block in the document, so it hangs under the header and cannot be reordered,+ * rather than a block in the document, so it sits above the first block and cannot be reordered,* duplicated, or deleted as content.*/export function NotebookVariablesPanel({@@ -116,7 +116,7 @@ export function NotebookVariablesPanel({onChange(variables.map((variable, i) => (i === index ? { ...variable, ...patch } : variable)))return (- <div className="NotebookVariables mx-auto flex w-[70%] min-w-0 flex-col gap-2 rounded border border-primary bg-surface-secondary p-2">+ <div className="NotebookVariables flex w-full min-w-0 flex-col gap-2 rounded border border-primary bg-surface-secondary p-2">{variables.length === 0 ? (<p className="m-0 text-xs text-secondary">No variables yet. Add one, then read it as <code>{'{name}'}</code> in a SQL cell or as a plain