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): open the code editor on a new SQL or Python cell (#82467)

Sinan Kucukkoseler11e4897f77fc
diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
index 80b65db6efdd..e705c404458d 100644
--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
@@ -6,6 +6,8 @@ import {
mergeMarkdownNotebookRegistries,
omitInsertCommands,
} from 'lib/components/MarkdownNotebook'
+import { getInsertedComponentPanelVisibility } from 'lib/components/MarkdownNotebook/componentPanels'
+import type { NotebookComponentBlockNode } from 'lib/components/MarkdownNotebook/types'
import { FEATURE_FLAGS } from 'lib/constants'
import { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
@@ -79,6 +81,33 @@ describe('markdownNotebookRegistry', () => {
expect(flagOff.components.SQLV2.insertCommand).toBeUndefined()
expect(flagOff.components.PythonV2.insertCommand).toBeUndefined()
})
+
+ // An inserted code cell holds no code and no result, so a closed editor panel leaves the
+ // user an empty box. Resolving through getInsertedComponentPanelVisibility rather than
+ // reading the prop keeps this honest if the panel prop is renamed again.
+ it.each([
+ ['SQL', 'component-SQLV2'],
+ ['Python', 'component-PythonV2'],
+ ])('inserts a %s cell with its code editor open', (_label, commandKey) => {
+ const insertedNodes: NotebookComponentBlockNode[] = []
+ const noop = (): void => {}
+ const commands = buildInsertCommands(
+ mergeMarkdownNotebookRegistries(
+ getMarkdownNotebookDefaultRegistry(),
+ getMarkdownRegistryForFeatureFlags({ [FEATURE_FLAGS.REVAMPED_PY_NOTEBOOKS]: true })
+ ),
+ (_nodeId, node) => insertedNodes.push(node),
+ noop,
+ noop,
+ noop,
+ noop
+ )
+
+ commands.find((command) => command.key === commandKey)?.run('target-node')
+
+ expect(insertedNodes).toHaveLength(1)
+ expect(getInsertedComponentPanelVisibility(insertedNodes[0]).filters).toBe(true)
+ })
})
describe('insert menu SQL commands', () => {
diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx
index 1b94186eaea5..44325a8e05ab 100644
--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.tsx
@@ -227,6 +227,11 @@ function getMarkdownNodeOptions(tagName: string): CreatePostHogWidgetNodeOptions
return nodeType ? KNOWN_NODES[nodeType] : null
}
+// A code cell's `filters` panel is its code editor, and the shell leaves that panel closed
+// unless the node carries `showFilters`. A cell the user just inserted holds no code and no
+// result, so without this it renders as an empty box with nothing to type into.
+const CODE_CELL_EDITOR_OPEN_PROPS: NotebookComponentProps = { showFilters: true }
+
export const MARKDOWN_NODE_DEFINITIONS: {
tagName: string
category: string
@@ -251,7 +256,11 @@ export const MARKDOWN_NODE_DEFINITIONS: {
label: 'Python',
insertCommand: {
aliases: ['python', 'py'],
- defaultProps: () => ({ ...getDefaultPropsForNodeType(NotebookNodeType.PythonV2), nodeId: uuid() }),
+ defaultProps: () => ({
+ ...getDefaultPropsForNodeType(NotebookNodeType.PythonV2),
+ ...CODE_CELL_EDITOR_OPEN_PROPS,
+ nodeId: uuid(),
+ }),
},
},
{ tagName: 'DuckSQL', category: 'SQL', label: 'SQL (DuckDB)' },
@@ -273,7 +282,11 @@ export const MARKDOWN_NODE_DEFINITIONS: {
// New cells get a durable nodeId up front: parsed markdown block ids are content
// fingerprints, so without a persisted id every prop change (running the cell
// writes runId/result) would orphan the cell's run history and cross-cell refs.
- defaultProps: () => ({ ...getDefaultPropsForNodeType(NotebookNodeType.SQLV2), nodeId: uuid() }),
+ defaultProps: () => ({
+ ...getDefaultPropsForNodeType(NotebookNodeType.SQLV2),
+ ...CODE_CELL_EDITOR_OPEN_PROPS,
+ nodeId: uuid(),
+ }),
},
},
{ tagName: 'RecordingPlaylist', category: 'Data', label: 'Session recordings' },