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.

fix(notebooks): stop the schema browser stretching SQL cells open (#76981)

Sinan Kucukkoseler8fe4198d7df9
diff --git a/frontend/src/layout/panel-layout/DatabaseTree/DatabaseTree.tsx b/frontend/src/layout/panel-layout/DatabaseTree/DatabaseTree.tsx
index 13ac3ef67e1e..88b55fc40df7 100644
--- a/frontend/src/layout/panel-layout/DatabaseTree/DatabaseTree.tsx
+++ b/frontend/src/layout/panel-layout/DatabaseTree/DatabaseTree.tsx
@@ -21,15 +21,23 @@ export const DatabaseTree = memo(function DatabaseTree({
databaseTreeRef,
tabId,
extraTreeSections,
+ embedded = false,
}: {
databaseTreeRef: React.RefObject<HTMLDivElement>
tabId: string
/** Extra top-level tree sections owned by the embedding surface — see QueryDatabase. */
extraTreeSections?: TreeDataItem[]
+ /** Rendered inside a notebook cell rather than the editor scene. */
+ embedded?: boolean
}): JSX.Element | null {
const scrollContainerRef = useRef<HTMLDivElement | null>(null)
- const { databaseTreeWidth, databaseTreeResizerProps, isDatabaseTreeCollapsed, databaseTreeWillCollapse } =
- useValues(editorSizingLogic)
+ const {
+ databaseTreeWidth,
+ databaseTreeResizerProps,
+ isDatabaseTreeCollapsed,
+ databaseTreeWillCollapse,
+ queryPaneDesiredSize,
+ } = useValues(editorSizingLogic)
const { selectedConnectionId, selectedDirectSource } = useValues(sqlEditorLogic({ tabId }))
const { toggleDatabaseTreeCollapsed, setDatabaseTreeCollapsed } = useActions(editorSizingLogic)
@@ -72,7 +80,19 @@ export const DatabaseTree = memo(function DatabaseTree({
<ScrollableShadows
scrollRef={scrollContainerRef}
direction="vertical"
- className="flex flex-col gap-2 z-20 group/colorful-product-icons colorful-product-icons-true h-[calc(100vh-var(--scene-layout-header-height))] overflow-auto"
+ className={cn(
+ 'flex flex-col gap-2 z-20 group/colorful-product-icons colorful-product-icons-true overflow-auto',
+ // A notebook cell sizes to its content and has no viewport-tall box to fill, so a
+ // viewport-height panel drags the whole cell open. `h-0` keeps the schema list out of
+ // that height, leaving the editor pane to size the cell, and `flex-auto` takes whatever
+ // height the row lands on, with the list scrolling inside it.
+ embedded && 'h-0 flex-auto',
+ // Until the pane has been resized the cell would open at editor height, leaving the
+ // browser a sliver — so hold a floor. Once the user drags, drop it: their size wins,
+ // in both directions, and closing the browser returns the cell to where it was.
+ embedded && (queryPaneDesiredSize === null ? 'min-h-[200px]' : 'min-h-0'),
+ !embedded && 'h-[calc(100vh-var(--scene-layout-header-height))]'
+ )}
innerClassName="flex flex-col gap-2"
styledScrollbars
>
diff --git a/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx b/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx
index 9bd0ef3079c3..6610a97638aa 100644
--- a/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx
@@ -6,6 +6,7 @@ import { AutoSizer } from 'lib/components/AutoSizer'
import { Resizer } from 'lib/components/Resizer/Resizer'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { CodeEditor, CodeEditorProps } from 'lib/monaco/CodeEditor'
+import { cn } from 'lib/utils/css-classes'
import { HogQLQuery } from '~/queries/schema/schema-general'
@@ -27,15 +28,21 @@ export function QueryPane(props: QueryPaneProps): JSX.Element {
const { queryPaneHeight, queryPaneDesiredSize, queryPaneResizerProps } = useValues(editorSizingLogic)
const { onAcceptSuggestedQueryInput, onRejectSuggestedQueryInput } = useActions(sqlEditorLogic)
const { acceptText, rejectText, diffShowRunButton } = useValues(sqlEditorLogic)
+ // Without an output pane beneath it the editor owns its column, so it takes whatever height the
+ // database tree gives the row rather than leaving dead space next to the schema list.
+ const fillsColumn = props.constrainHeight === false
return (
<>
<div
- className="relative flex flex-row w-full bg-primary"
+ // No min-h-0 here: Tailwind runs with `important`, so the utility would beat the
+ // inline min-height that keeps the editor readable when the tree is closed.
+ className={cn('relative flex flex-row w-full bg-primary', fillsColumn && 'flex-1')}
// eslint-disable-next-line react/forbid-dom-props
style={{
- height: `${queryPaneHeight}px`,
- maxHeight: props.constrainHeight !== false && queryPaneDesiredSize === null ? '35%' : undefined,
+ height: fillsColumn ? undefined : `${queryPaneHeight}px`,
+ minHeight: fillsColumn ? `${queryPaneHeight}px` : undefined,
+ maxHeight: !fillsColumn && queryPaneDesiredSize === null ? '35%' : undefined,
}}
ref={queryPaneResizerProps.containerRef}
>
diff --git a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
index 7c0a3f103fb5..cd73069039f4 100644
--- a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
@@ -46,7 +46,7 @@ import { outputPaneLogic } from './outputPaneLogic'
import { QueryHistoryModal } from './QueryHistoryModal'
import { QueryWindow } from './QueryWindow'
import { sqlEditorLogic } from './sqlEditorLogic'
-import { SQLEditorMode } from './sqlEditorModes'
+import { SQLEditorMode, isEmbeddedSQLEditorMode } from './sqlEditorModes'
export enum SQLEditorPanel {
Full = 'full',
@@ -110,8 +110,14 @@ export function SQLEditor({
const showDatabaseTreePanel = showQueryPanel && shouldShowDatabaseTree
const showFullSceneModals = mode === SQLEditorMode.FullScene
- const editorSizingLogicProps = useMemo(
- () => ({
+ const editorSizingLogicProps = useMemo(() => {
+ // The scene keeps one shared set of pane sizes across its tabs. Notebook cells each get their
+ // own, so resizing one cell's editor doesn't resize every other SQL cell in the notebook.
+ const sizingKey = isEmbeddedSQLEditorMode(mode) ? `embedded:${tabId ?? 'new'}` : 'scene'
+ const resizerKey = (name: string): string => (sizingKey === 'scene' ? name : `${name}:${sizingKey}`)
+
+ return {
+ logicKey: sizingKey,
editorSceneRef: ref,
navigatorRef,
sidebarRef,
@@ -119,29 +125,28 @@ export function SQLEditor({
queryPaneDefaultHeight,
sourceNavigatorResizerProps: {
containerRef: navigatorRef,
- logicKey: 'source-navigator',
+ logicKey: resizerKey('source-navigator'),
placement: 'right' as const,
},
sidebarResizerProps: {
containerRef: sidebarRef,
- logicKey: 'sidebar-resizer',
+ logicKey: resizerKey('sidebar-resizer'),
placement: 'right' as const,
},
queryPaneResizerProps: {
containerRef: queryPaneRef,
- logicKey: 'query-pane',
+ logicKey: resizerKey('query-pane'),
placement: 'bottom' as const,
},
databaseTreeResizerProps: {
containerRef: databaseTreeRef,
- logicKey: 'database-tree',
+ logicKey: resizerKey('database-tree'),
placement: 'right' as const,
persistent: true,
marginTop: mode === SQLEditorMode.FullScene ? 8 : 0,
},
- }),
- [mode, queryPaneDefaultHeight]
- )
+ }
+ }, [mode, tabId, queryPaneDefaultHeight])
const [monacoAndEditor, setMonacoAndEditor] = useState(
null as [Monaco, importedEditor.IStandaloneCodeEditor] | null
@@ -242,6 +247,7 @@ export function SQLEditor({
databaseTreeRef={databaseTreeRef}
tabId={tabId || ''}
extraTreeSections={extraTreeSections}
+ embedded={isEmbeddedSQLEditorMode(mode)}
/>
)}
<div
diff --git a/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx b/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx
index 32e56376d309..a9b3a65e713a 100644
--- a/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx
@@ -1,8 +1,10 @@
-import { MakeLogicType, actions, connect, kea, listeners, path, props, reducers, selectors } from 'kea'
+import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLogic'
export interface EditorSizingLogicProps {
+ /** Scopes the pane sizes. Notebook cells pass their tab id so each cell resizes on its own. */
+ logicKey: string
editorSceneRef: React.RefObject<HTMLDivElement>
navigatorRef: React.RefObject<HTMLDivElement>
sidebarRef: React.RefObject<HTMLDivElement>
@@ -75,6 +77,7 @@ export interface editorSizingLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface editorSizingLogicMeta {
+ key: string
__keaTypeGenInternalSelectorTypes: {
editorSceneRef: (editorSceneRef: any) => any
sourceNavigatorWidth: (sourceNavigatorDesiredSize: number | null) => number
@@ -99,6 +102,7 @@ export type editorSizingLogicType = MakeLogicType<
export const editorSizingLogic = kea<editorSizingLogicType>([
path(['scenes', 'data-warehouse', 'editor', 'editorSizingLogic']),
props({} as EditorSizingLogicProps),
+ key((props: EditorSizingLogicProps) => props.logicKey),
connect((props: EditorSizingLogicProps) => ({
values: [
resizerLogic(props.sourceNavigatorResizerProps),