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): let the SQL and Python cell editors be dragged smaller (#94004)

Sinan Kucukkoseler1fb4554c1934
diff --git a/frontend/src/lib/monaco/CodeEditorResizable.tsx b/frontend/src/lib/monaco/CodeEditorResizable.tsx
index 89dacd7c28f8..2ce496e4a7b8 100644
--- a/frontend/src/lib/monaco/CodeEditorResizable.tsx
+++ b/frontend/src/lib/monaco/CodeEditorResizable.tsx
@@ -20,6 +20,10 @@ export interface CodeEditorResizableProps extends Omit<CodeEditorProps, 'height'
allowManualResize?: boolean
}
+// Floor for a dragged height. Two Monaco lines stay readable, and the editor cannot be
+// dragged away to nothing.
+const MANUAL_RESIZE_MIN_HEIGHT = 44
+
export function CodeEditorResizeable({
height: defaultHeight,
minHeight = '5rem',
@@ -52,9 +56,10 @@ export function CodeEditorResizeable({
className={clsx('relative CodeEditorResizeable', !embedded ? 'w-full rounded border' : '', className)}
// eslint-disable-next-line react/forbid-dom-props
style={{
- minHeight,
- // `maxHeight` caps how tall the editor grows on its own. A drag is a deliberate
- // choice, so it overrides the cap instead of being clamped by it.
+ // `minHeight` and `maxHeight` bound how the editor sizes itself to its content.
+ // A drag is a deliberate choice, so it overrides both. A `minHeight` that still
+ // applied after a drag would let the editor grow but never shrink.
+ minHeight: manualHeight ?? minHeight,
maxHeight: manualHeight ?? maxHeight,
height: manualHeight ?? height,
}}
@@ -104,7 +109,7 @@ export function CodeEditorResizeable({
const startY = e.clientY
const startHeight = ref.current?.clientHeight ?? 0
const onMouseMove = (event: MouseEvent): void => {
- setManualHeight(startHeight + event.clientY - startY)
+ setManualHeight(Math.max(startHeight + event.clientY - startY, MANUAL_RESIZE_MIN_HEIGHT))
}
const onMouseUp = (): void => {
window.removeEventListener('mousemove', onMouseMove)
diff --git a/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx b/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx
index 6610a97638aa..b11662eb7b8f 100644
--- a/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/QueryPane.tsx
@@ -47,7 +47,17 @@ export function QueryPane(props: QueryPaneProps): JSX.Element {
ref={queryPaneResizerProps.containerRef}
>
<div className="relative flex flex-col w-full min-h-0">
- <div className="flex-1 min-h-0" data-attr="hogql-query-editor">
+ {/*
+ * A notebook cell puts this pane in a container that the browser sizes from
+ * its content. The pane is a flex item there, so the editor inside it sets
+ * the floor the pane can reach. Monaco reports the height it already has, so
+ * a drag could only make the pane taller. The editor leaves the flow here so
+ * that `queryPaneHeight` alone sets the height.
+ */}
+ <div
+ className={cn('flex-1 min-h-0', fillsColumn && 'absolute inset-0')}
+ data-attr="hogql-query-editor"
+ >
<AutoSizer
renderProp={({ height, width }) =>
height && width ? (
diff --git a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
index d9aec6723ce1..061d074292fc 100644
--- a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
@@ -77,6 +77,8 @@ interface SQLEditorProps {
hideRunButton?: boolean
onShareTab?: () => void
queryPaneDefaultHeight?: number
+ /** Floor for a dragged query pane. Notebook cells pass a smaller one than the scene. */
+ queryPaneMinHeight?: number
/** Whether the query pane's code editor may grab focus on mount. Defaults to true. */
autoFocusQueryPane?: boolean
}
@@ -98,6 +100,7 @@ export function SQLEditor({
hideRunButton,
onShareTab,
queryPaneDefaultHeight,
+ queryPaneMinHeight,
autoFocusQueryPane,
}: SQLEditorProps): JSX.Element {
const ref = useRef(null)
@@ -128,6 +131,7 @@ export function SQLEditor({
sidebarRef,
databaseTreeRef,
queryPaneDefaultHeight,
+ queryPaneMinHeight,
biEditorResizerProps: {
containerRef: biEditorRef,
logicKey: 'bi-editor-pane',
@@ -158,7 +162,7 @@ export function SQLEditor({
marginTop: mode === SQLEditorMode.FullScene ? 8 : 0,
},
}
- }, [mode, tabId, queryPaneDefaultHeight])
+ }, [mode, tabId, queryPaneDefaultHeight, queryPaneMinHeight])
const [monacoAndEditor, setMonacoAndEditor] = useState(
null as [Monaco, importedEditor.IStandaloneCodeEditor | null] | null
diff --git a/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx b/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx
index eb2e7371af91..2f645ee9d9d2 100644
--- a/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/editorSizingLogic.tsx
@@ -10,6 +10,8 @@ export interface EditorSizingLogicProps {
sidebarRef: React.RefObject<HTMLDivElement>
databaseTreeRef: React.RefObject<HTMLDivElement>
queryPaneDefaultHeight?: number
+ /** Floor for a dragged query pane. Notebook cells pass a smaller one than the scene. */
+ queryPaneMinHeight?: number
biEditorResizerProps: ResizerLogicProps
sourceNavigatorResizerProps: ResizerLogicProps
sidebarResizerProps: ResizerLogicProps
@@ -89,7 +91,11 @@ export interface editorSizingLogicMeta {
biEditorHeight: (biEditorDesiredSize: number | null) => number
biEditorResizerProps: (biEditorResizerProps: ResizerLogicProps) => ResizerLogicProps
sourceNavigatorWidth: (sourceNavigatorDesiredSize: number | null) => number
- queryPaneHeight: (queryPaneDesiredSize: number | null, arg: number | undefined) => number
+ queryPaneHeight: (
+ queryPaneDesiredSize: number | null,
+ arg: number | undefined,
+ arg2: number | undefined
+ ) => number
queryTabsWidth: (queryPaneDesiredSize: number | null) => number
sourceNavigatorResizerProps: (sourceNavigatorResizerProps: ResizerLogicProps) => ResizerLogicProps
queryPaneResizerProps: (queryPaneResizerProps: ResizerLogicProps) => ResizerLogicProps
@@ -189,11 +195,22 @@ export const editorSizingLogic = kea<editorSizingLogicType>([
(desiredSize: number | null) => Math.max(desiredSize || NAVIGATOR_DEFAULT_WIDTH, MINIMUM_NAVIGATOR_WIDTH),
],
queryPaneHeight: [
- (s) => [s.queryPaneDesiredSize, (_, props: EditorSizingLogicProps) => props.queryPaneDefaultHeight],
- (queryPaneDesiredSize: number | null, queryPaneDefaultHeight: number | undefined) =>
+ (s) => [
+ s.queryPaneDesiredSize,
+ (_, props: EditorSizingLogicProps) => props.queryPaneDefaultHeight,
+ (_, props: EditorSizingLogicProps) => props.queryPaneMinHeight,
+ ],
+ (
+ queryPaneDesiredSize: number | null,
+ queryPaneDefaultHeight: number | undefined,
+ queryPaneMinHeight: number | undefined
+ ) =>
Math.max(
- queryPaneDesiredSize || queryPaneDefaultHeight || DEFAULT_QUERY_PANE_HEIGHT,
- MINIMUM_QUERY_PANE_HEIGHT
+ // `??`, not `||`: a drag that lands on exactly 0 is still a size the user
+ // chose, and the clamp below turns it into the floor. `||` would read it as
+ // "no size yet" and snap the pane back to its default height.
+ queryPaneDesiredSize ?? queryPaneDefaultHeight ?? DEFAULT_QUERY_PANE_HEIGHT,
+ queryPaneMinHeight ?? MINIMUM_QUERY_PANE_HEIGHT
),
],
queryTabsWidth: [
diff --git a/frontend/src/scenes/notebooks/Nodes/components/NotebookSQLEditor.tsx b/frontend/src/scenes/notebooks/Nodes/components/NotebookSQLEditor.tsx
index 67abc94a831c..52258936e2ad 100644
--- a/frontend/src/scenes/notebooks/Nodes/components/NotebookSQLEditor.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/components/NotebookSQLEditor.tsx
@@ -22,6 +22,9 @@ export const EMBEDDED_SQL_EDITOR_DEFAULT_HEIGHT = 333
export const EMBEDDED_SQL_EDITOR_EDIT_DEFAULT_HEIGHT = 150
export const EMBEDDED_SQL_EDITOR_MIN_HEIGHT = 200
export const EMBEDDED_SQL_EDITOR_EDIT_MIN_HEIGHT = 150
+// Floor for a dragged editor, so a cell that holds one line of SQL can shrink to about two
+// lines. The SQL editor scene keeps its own, taller floor.
+export const EMBEDDED_SQL_EDITOR_QUERY_PANE_MIN_HEIGHT = 44
export const getNotebookSqlEditorTabId = (nodeId: string | null | undefined, suffix: string | null = null): string =>
`notebook-sql-${suffix ? `${suffix}-` : ''}${nodeId ?? 'new'}`
@@ -502,6 +505,7 @@ export function NotebookSQLEditorSettings<T extends { query: QuerySchema }>({
panel={SQLEditorPanel.Query}
defaultShowDatabaseTree={false}
queryPaneDefaultHeight={EMBEDDED_SQL_EDITOR_EDIT_DEFAULT_HEIGHT}
+ queryPaneMinHeight={EMBEDDED_SQL_EDITOR_QUERY_PANE_MIN_HEIGHT}
autoFocusQueryPane={autoFocusQueryPane}
/>
</div>
@@ -592,6 +596,7 @@ export function NotebookCodeSQLEditorSettings<T extends { code: string } & Noteb
cancelQueryLoading={cancelQueryLoading}
hideRunButton={hideRunButton}
queryPaneDefaultHeight={EMBEDDED_SQL_EDITOR_EDIT_DEFAULT_HEIGHT}
+ queryPaneMinHeight={EMBEDDED_SQL_EDITOR_QUERY_PANE_MIN_HEIGHT}
/>
</div>
)