: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
feat(notebooks): show kernel UI when revamped-py-notebooks is enabled (#71424)
Sinan Kucukkoseler20946c5eeb3e
diff --git a/frontend/src/scenes/notebooks/Nodes/components/DuckSqlRunMenu.tsx b/frontend/src/scenes/notebooks/Nodes/components/DuckSqlRunMenu.tsxindex 90e03294be6e..56c673945da6 100644--- a/frontend/src/scenes/notebooks/Nodes/components/DuckSqlRunMenu.tsx+++ b/frontend/src/scenes/notebooks/Nodes/components/DuckSqlRunMenu.tsx@@ -3,10 +3,10 @@ import { useActions, useValues } from 'kea'import { IconChevronDown, IconPlay } from '@posthog/icons'import { LemonButton, LemonMenuItems, LemonMenuOverlay } from '@posthog/lemon-ui'-import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { notebookSettingsLogic } from '../../Notebook/notebookSettingsLogic'+import { isKernelUiEnabled } from '../../utils'import { NotebookRunMode, buildRunMenuItems } from './runMenuItems'export type DuckSqlRunMode = NotebookRunMode@@ -36,7 +36,7 @@ export const DuckSqlRunMenu = ({const duckSqlRunMenuItems: LemonMenuItems = [...buildRunMenuItems(onRun)]- if (featureFlags[FEATURE_FLAGS.NOTEBOOK_PYTHON]) {+ if (isKernelUiEnabled(featureFlags)) {duckSqlRunMenuItems.push({label: 'Toggle kernel info',onClick: () => setShowKernelInfo(!showKernelInfo),diff --git a/frontend/src/scenes/notebooks/Nodes/components/HogqlSqlRunMenu.tsx b/frontend/src/scenes/notebooks/Nodes/components/HogqlSqlRunMenu.tsxindex dfdee497865f..9ca6d917f778 100644--- a/frontend/src/scenes/notebooks/Nodes/components/HogqlSqlRunMenu.tsx+++ b/frontend/src/scenes/notebooks/Nodes/components/HogqlSqlRunMenu.tsx@@ -3,10 +3,10 @@ import { useActions, useValues } from 'kea'import { IconChevronDown, IconPlay } from '@posthog/icons'import { LemonButton, LemonMenuItems, LemonMenuOverlay } from '@posthog/lemon-ui'-import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { notebookSettingsLogic } from '../../Notebook/notebookSettingsLogic'+import { isKernelUiEnabled } from '../../utils'import { NotebookRunMode, buildRunMenuItems } from './runMenuItems'export type HogqlSqlRunMode = NotebookRunMode@@ -36,7 +36,7 @@ export const HogqlSqlRunMenu = ({const hogqlRunMenuItems: LemonMenuItems = [...buildRunMenuItems(onRun)]- if (featureFlags[FEATURE_FLAGS.NOTEBOOK_PYTHON]) {+ if (isKernelUiEnabled(featureFlags)) {hogqlRunMenuItems.push({label: 'Toggle kernel info',onClick: () => setShowKernelInfo(!showKernelInfo),diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookMeta.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookMeta.tsxindex cfa35f651c18..4465721f9ffc 100644--- a/frontend/src/scenes/notebooks/Notebook/NotebookMeta.tsx+++ b/frontend/src/scenes/notebooks/Notebook/NotebookMeta.tsx@@ -4,7 +4,6 @@ import { useCallback, useEffect, useState } from 'react'import { IconSparkles, IconTerminal } from '@posthog/icons'import { LemonButton, LemonButtonProps, LemonTag } from '@posthog/lemon-ui'-import { FEATURE_FLAGS } from 'lib/constants'import { IconDocumentExpand } from 'lib/lemon-ui/icons'import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture'import { Spinner } from 'lib/lemon-ui/Spinner'@@ -13,6 +12,8 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'import { NotebookSyncStatus } from '../types'+import { isKernelUiEnabled } from '../utils'+import { isMarkdownNotebookContent } from './markdownNotebookV2'import { NotebookLogicProps, notebookLogic } from './notebookLogic'import { NOTEBOOK_AI_PRESENCE_COLOR, type NotebookPresenceParticipant } from './notebookPresence'import { notebookSettingsLogic } from './notebookSettingsLogic'@@ -215,10 +216,12 @@ export const NotebookKernelInfoButton = ({...props}: NotebookKernelInfoButtonProps): JSX.Element | null => {const { featureFlags } = useValues(featureFlagLogic)+ const { content } = useValues(notebookLogic)const { showKernelInfo } = useValues(notebookSettingsLogic)const { setShowKernelInfo } = useActions(notebookSettingsLogic)- if (!featureFlags[FEATURE_FLAGS.NOTEBOOK_PYTHON]) {+ // The kernel info panel only renders for markdown (V2) notebooks, so hide the toggle elsewhere+ if (!isKernelUiEnabled(featureFlags) || !isMarkdownNotebookContent(content)) {return null}diff --git a/frontend/src/scenes/notebooks/NotebookScene.tsx b/frontend/src/scenes/notebooks/NotebookScene.tsxindex d3bc687d398a..f62ce4bb4ce3 100644--- a/frontend/src/scenes/notebooks/NotebookScene.tsx+++ b/frontend/src/scenes/notebooks/NotebookScene.tsx@@ -1,4 +1,4 @@-import { useActions, useValues } from 'kea'+import { BindLogic, useActions, useValues } from 'kea'import { router } from 'kea-router'import { useEffect, useState } from 'react'@@ -141,11 +141,13 @@ export function NotebookScene(): JSX.Element {{!sceneMenuBarEnabled && <NotebookMenu shortId={notebookId} />}{!sceneMenuBarEnabled && (- <NotebookKernelInfoButton- type="secondary"- size="small"- onBeforeShowKernelInfo={() => setIsMarkdownSourceOpen(false)}- />+ <BindLogic logic={notebookLogic} props={{ shortId: notebookId, target: NotebookTarget.Scene }}>+ <NotebookKernelInfoButton+ type="secondary"+ size="small"+ onBeforeShowKernelInfo={() => setIsMarkdownSourceOpen(false)}+ />+ </BindLogic>)}{!sceneMenuBarEnabled && <NotebookExpandButton type="secondary" size="small" inPanel={false} />}{!sceneMenuBarEnabled && (diff --git a/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsx b/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsxindex a2137a1cec91..7ed1ca570d36 100644--- a/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsx+++ b/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsx@@ -17,9 +17,11 @@ import {} from '~/layout/scenes/components/SceneMenuBar'import { notebooksModel } from '~/models/notebooksModel'+import { isMarkdownNotebookContent } from './Notebook/markdownNotebookV2'import { notebookLogic } from './Notebook/notebookLogic'import { notebookSettingsLogic } from './Notebook/notebookSettingsLogic'import { notebookPanelLogic } from './NotebookPanel/notebookPanelLogic'+import { isKernelUiEnabled } from './utils'const RESOURCE_TYPE = 'notebook'@@ -33,14 +35,15 @@ export function NotebookSceneMenuBar({ shortId }: { shortId: string }): JSX.Elemfunction NotebookSceneMenuBarInner({ shortId }: { shortId: string }): JSX.Element {const logic = notebookLogic({ shortId })- const { notebook, showHistory, isLocalOnly } = useValues(logic)+ const { notebook, showHistory, isLocalOnly, content } = useValues(logic)const { openShareModal, duplicateNotebook, downloadMarkdown, copyMarkdown, setShowHistory } = useActions(logic)const { featureFlags } = useValues(featureFlagLogic)const { isMarkdownExpanded, showKernelInfo } = useValues(notebookSettingsLogic)const { setIsMarkdownExpanded, setShowKernelInfo } = useActions(notebookSettingsLogic)const { selectNotebook } = useActions(notebookPanelLogic)const canDelete = !isLocalOnly && !notebook?.is_template- const showKernelToggle = !!featureFlags[FEATURE_FLAGS.NOTEBOOK_PYTHON]+ // The kernel info panel only renders for markdown (V2) notebooks, so hide the toggle elsewhere+ const showKernelToggle = isKernelUiEnabled(featureFlags) && isMarkdownNotebookContent(content)return (<SceneMenuBar>diff --git a/frontend/src/scenes/notebooks/utils.ts b/frontend/src/scenes/notebooks/utils.tsindex 9fbe10de75eb..dd54c4ad98c4 100644--- a/frontend/src/scenes/notebooks/utils.ts+++ b/frontend/src/scenes/notebooks/utils.ts@@ -1,10 +1,16 @@import { JSONContent } from 'lib/components/RichContentEditor/types'+import { FEATURE_FLAGS } from 'lib/constants'+import { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'import { buildMarkdownNotebookContent, convertNotebookContentToMarkdown } from './Notebook/markdownNotebookV2'import { CreatePostHogWidgetNodeOptions } from './types'export const KNOWN_NODES: Record<string, CreatePostHogWidgetNodeOptions<any>> = {}+export function isKernelUiEnabled(featureFlags: FeatureFlagsSet): boolean {+ return !!featureFlags[FEATURE_FLAGS.NOTEBOOK_PYTHON] || !!featureFlags[FEATURE_FLAGS.REVAMPED_PY_NOTEBOOKS]+}+export function defaultNotebookContent(title?: string, content?: JSONContent[]): JSONContent {const initialContent = [{